| 1 |
|
| 2 |
|
| 3 |
require 'gtk3' |
| 4 |
|
| 5 |
クロール機能を追加するMixin |
| 6 |
時に一番上にレコードが追加された場合、一番上までゆっくりスクロールする |
| 7 |
module Gtk::TreeViewPrettyScroll |
| 8 |
|
| 9 |
FRAME_PER_SECOND = 30 |
| 10 |
FRAME_MS = 1000.to_f / FRAME_PER_SECOND |
| 11 |
|
| 12 |
attr_accessor :pointer_on_main_icon |
| 13 |
|
| 14 |
def initialize(*a) |
| 15 |
super |
| 16 |
pointer_on_main_icon = false ン上にポインタがあるなら真 |
| 17 |
scroll_to_top_animation = false ルアニメーション中なら真 |
| 18 |
get_scroll_to_top_animation_id = 0 |
| 19 |
scroll_to_top_animation_id = lambda{ |
| 20 |
scroll_to_top_animation = false if scroll_to_top_animation |
| 21 |
get_scroll_to_top_animation_id += 1 } |
| 22 |
|
| 23 |
ssc(:scroll_event){ |this, e| |
| 24 |
case e.direction |
| 25 |
when Gdk::ScrollDirection::UP |
| 26 |
this.vadjustment.value = [this.vadjustment.value - this.vadjustment.step_increment, this.vadjustment.lower].max |
| 27 |
scroll_to_top_animation_id.call |
| 28 |
when Gdk::ScrollDirection::DOWN |
| 29 |
@scroll_to_zero_lator = false if this.vadjustment.value == 0 |
| 30 |
this.vadjustment.value = [this.vadjustment.value + this.vadjustment.step_increment, this.vadjustment.upper - visible_rect.height].min |
| 31 |
scroll_to_top_animation_id.call end |
| 32 |
false } |
| 33 |
|
| 34 |
vadjustment.ssc(:value_changed){ |this| |
| 35 |
if(scroll_to_zero? and not(scroll_to_top_animation)) |
| 36 |
@scroll_to_zero_lator = false |
| 37 |
my_id = scroll_to_top_animation_id.call |
| 38 |
scroll_to_top_animation = true |
| 39 |
Gtk.timeout_add(FRAME_MS){ |
| 40 |
if get_scroll_to_top_animation_id == my_id and not(destroyed?) |
| 41 |
vadjustment.value -= (vadjustment.value / 2) + 1 |
| 42 |
scroll_to_top_animation = vadjustment.value > 0.0 end |
| 43 |
} end |
| 44 |
false } |
| 45 |
|
| 46 |
end |
| 47 |
|
| 48 |
def scroll_to_zero_lator! |
| 49 |
@scroll_to_zero_lator = true end |
| 50 |
|
| 51 |
def scroll_to_zero? |
| 52 |
!pointer_on_main_icon and defined?(@scroll_to_zero_lator) and @scroll_to_zero_lator end |
| 53 |
|
| 54 |
end |