Class: Luck::Pane
- Inherits:
-
Object
- Object
- Luck::Pane
- Defined in:
- lib/luck/pane.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#controls ⇒ Object
Returns the value of attribute controls.
-
#dirty ⇒ Object
(also: #dirty?)
Returns the value of attribute dirty.
-
#display ⇒ Object
Returns the value of attribute display.
-
#handler ⇒ Object
Returns the value of attribute handler.
-
#title ⇒ Object
Returns the value of attribute title.
-
#visible ⇒ Object
(also: #visible?)
Returns the value of attribute visible.
-
#x1 ⇒ Object
Returns the value of attribute x1.
-
#x2 ⇒ Object
Returns the value of attribute x2.
-
#y1 ⇒ Object
Returns the value of attribute y1.
-
#y2 ⇒ Object
Returns the value of attribute y2.
Instance Method Summary collapse
- #[](control) ⇒ Object
- #control(name, type, *args, &blck) ⇒ Object
- #control_at(x, y) ⇒ Object
- #dirty! ⇒ Object
- #draw_contents ⇒ Object
- #draw_frame ⇒ Object
- #draw_title ⇒ Object
- #handle_click(button, modifiers, x, y) ⇒ Object
- #height ⇒ Object
- #hide! ⇒ Object
-
#initialize(display, x1, y1, x2, y2, title, controls = {}, &blck) ⇒ Pane
constructor
A new instance of Pane.
- #on_submit(&blck) ⇒ Object
- #redraw ⇒ Object
- #show! ⇒ Object
- #width ⇒ Object
- #yank_values ⇒ Object
Constructor Details
#initialize(display, x1, y1, x2, y2, title, controls = {}, &blck) ⇒ Pane
Returns a new instance of Pane.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/luck/pane.rb', line 5 def initialize display, x1, y1, x2, y2, title, controls={}, &blck @display = display @x1, @y1 = x1, y1 @x2, @y2 = x2, y2 @title, @controls = title, controls @dirty = false @visible = true instance_eval &blck if blck end |
Instance Attribute Details
#controls ⇒ Object
Returns the value of attribute controls.
3 4 5 |
# File 'lib/luck/pane.rb', line 3 def controls @controls end |
#dirty ⇒ Object Also known as: dirty?
Returns the value of attribute dirty.
3 4 5 |
# File 'lib/luck/pane.rb', line 3 def dirty @dirty end |
#display ⇒ Object
Returns the value of attribute display.
3 4 5 |
# File 'lib/luck/pane.rb', line 3 def display @display end |
#handler ⇒ Object
Returns the value of attribute handler.
3 4 5 |
# File 'lib/luck/pane.rb', line 3 def handler @handler end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/luck/pane.rb', line 3 def title @title end |
#visible ⇒ Object Also known as: visible?
Returns the value of attribute visible.
3 4 5 |
# File 'lib/luck/pane.rb', line 3 def visible @visible end |
#x1 ⇒ Object
Returns the value of attribute x1.
3 4 5 |
# File 'lib/luck/pane.rb', line 3 def x1 @x1 end |
#x2 ⇒ Object
Returns the value of attribute x2.
3 4 5 |
# File 'lib/luck/pane.rb', line 3 def x2 @x2 end |
#y1 ⇒ Object
Returns the value of attribute y1.
3 4 5 |
# File 'lib/luck/pane.rb', line 3 def y1 @y1 end |
#y2 ⇒ Object
Returns the value of attribute y2.
3 4 5 |
# File 'lib/luck/pane.rb', line 3 def y2 @y2 end |
Instance Method Details
#[](control) ⇒ Object
16 17 18 |
# File 'lib/luck/pane.rb', line 16 def [] control @controls[control] end |
#control(name, type, *args, &blck) ⇒ Object
43 44 45 |
# File 'lib/luck/pane.rb', line 43 def control name, type, *args, &blck @controls[name] = type.new(self, *args, &blck) end |
#control_at(x, y) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/luck/pane.rb', line 80 def control_at x, y @controls.values.each do |control| return control if (control.x1..control.x2).include?(x) && (control.y1..control.y2).include?(y) end nil end |
#dirty! ⇒ Object
21 22 23 |
# File 'lib/luck/pane.rb', line 21 def dirty! @dirty = true end |
#draw_contents ⇒ Object
74 75 76 77 78 |
# File 'lib/luck/pane.rb', line 74 def draw_contents controls.each_value do |control| control.redraw end end |
#draw_frame ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/luck/pane.rb', line 98 def draw_frame = 'q' * (width - 1) = ' ' * (width - 1) @display.driver.linedrawing = true print @display.color('0;2') @display.place y1, x1, "n#{}n" @display.place y2, x1, "n#{}n" #~ @display.place y1, x1, "l#{topbar}k" #~ @display.place y2, x1, "m#{bottombar}j" (y1 + 1).upto y2 - 1 do |row| @display.place row, x1, "x#{}x" end @display.driver.linedrawing = false print @display.color('0') end |
#draw_title ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/luck/pane.rb', line 118 def draw_title title = " * #{@title} * " left = (((width - 1).to_f / 2) - (title.size.to_f / 2)).to_i if title.size >= width title = @title[0, width - 3] left = 0 end print @display.color('1;34') @display.place y1, x1 + 1 + left, title print @display.color('0') end |
#handle_click(button, modifiers, x, y) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/luck/pane.rb', line 87 def handle_click , modifiers, x, y control = control_at x, y if control if == :left control.focus! if control.respond_to? :handle_char control.redraw end control.handle_click , modifiers, x, y if control.respond_to?(:handle_click) end end |
#height ⇒ Object
64 65 66 |
# File 'lib/luck/pane.rb', line 64 def height y2 - y1 end |
#hide! ⇒ Object
27 |
# File 'lib/luck/pane.rb', line 27 def hide!; @visible = false; end |
#on_submit(&blck) ⇒ Object
39 40 41 |
# File 'lib/luck/pane.rb', line 39 def on_submit &blck @handler = blck end |
#redraw ⇒ Object
68 69 70 71 72 |
# File 'lib/luck/pane.rb', line 68 def redraw draw_frame draw_contents draw_title end |
#show! ⇒ Object
26 |
# File 'lib/luck/pane.rb', line 26 def show!; @visible = true; end |
#width ⇒ Object
61 62 63 |
# File 'lib/luck/pane.rb', line 61 def width x2 - x1 end |
#yank_values ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/luck/pane.rb', line 29 def yank_values vals = {} @controls.each_pair do |key, control| next unless control.respond_to? :value vals[key] = control.value control.value = '' end vals end |