Class: ScrollBox
- Inherits:
-
Object
- Object
- ScrollBox
- Defined in:
- lib/gswax/scrollbox.rb
Instance Attribute Summary collapse
-
#main ⇒ Object
Returns the value of attribute main.
Instance Method Summary collapse
- #hover_toggle ⇒ Object
-
#initialize(txt) ⇒ ScrollBox
constructor
A new instance of ScrollBox.
- #resize ⇒ Object
- #set_text(txt) ⇒ Object
- #show_text(txt) ⇒ Object
- #start_scroll ⇒ Object
- #stop_scroll ⇒ Object
Constructor Details
#initialize(txt) ⇒ ScrollBox
Returns a new instance of ScrollBox.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/gswax/scrollbox.rb', line 13 def initialize(txt) @txt = txt @scroll_text = txt + " " bgc = Settings.bg_color @bg_color = Gdk::Color.new(bgc[0], bgc[1], bgc[2]) @main = Gtk::EventBox.new() @main.set_size_request(727 * Settings.scale, 75 * Settings.scale) @main.signal_connect("enter_notify_event"){hover_toggle}### @main.signal_connect("leave_notify_event"){@left = true}### @main.modify_bg(Gtk::STATE_NORMAL, @bg_color) frame = Gtk::HBox.new(false, 0) @text_label = Gtk::Label.new @text_label.justify=(Gtk::JUSTIFY_CENTER) @text_label.ellipsize = Pango::Layout::ELLIPSIZE_END frame.pack_start(@text_label, true, true, 10) @main.add(frame) show_text(@txt) end |
Instance Attribute Details
#main ⇒ Object
Returns the value of attribute main.
11 12 13 |
# File 'lib/gswax/scrollbox.rb', line 11 def main @main end |
Instance Method Details
#hover_toggle ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/gswax/scrollbox.rb', line 51 def hover_toggle @left = false timer = GLib::Timer.new GLib::Timeout.add(100){ if timer.elapsed[0].round(1) > 0.3 unless @left if @scrolling stop_scroll else start_scroll end timer.stop end false else true end } end |
#resize ⇒ Object
96 97 98 |
# File 'lib/gswax/scrollbox.rb', line 96 def resize @main.set_size_request(727.0 * Settings.scale, 75.0 * Settings.scale) end |
#set_text(txt) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/gswax/scrollbox.rb', line 43 def set_text(txt) stop_scroll if @scrolling @scroll_text = txt + " " @text_label.text = @scroll_text @text_label.justify=(Gtk::JUSTIFY_CENTER) show_text(@scroll_text) end |
#show_text(txt) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/gswax/scrollbox.rb', line 33 def show_text(txt) if @text_label txc = Settings.text_color txt_color = Gdk::Color.new(txc[0], txc[1], txc[2]) @text_label.set_markup( %Q[<span font_desc="#{Settings.font_desc}"foreground="#{txt_color}">#{CGI.escape_html(txt)}</span>] ) end end |
#start_scroll ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/gswax/scrollbox.rb', line 72 def start_scroll @scrolling = true @text_label.justify=(Gtk::JUSTIFY_LEFT) @timer = GLib::Timeout.add(100){ if @scrolling first = @scroll_text.slice!(0) @scroll_text << first show_text(@scroll_text) else false end } end |
#stop_scroll ⇒ Object
86 87 88 |
# File 'lib/gswax/scrollbox.rb', line 86 def stop_scroll @scrolling = false; @timer = nil end |