Class: Fidgit::ComboBox
- Inherits:
-
Button
show all
- Extended by:
- Forwardable
- Defined in:
- lib/fidgit/elements/combo_box.rb
Constant Summary
Constants inherited
from Label
Label::VALID_JUSTIFICATION
Constants inherited
from Element
Element::DEFAULT_SCHEMA_FILE, Element::VALID_ALIGN_H, Element::VALID_ALIGN_V
Instance Attribute Summary
Attributes inherited from Label
#background_color, #border_color, #color, #icon, #text
Attributes inherited from Element
#align_h, #align_v, #background_color, #border_thickness, #font_size, #padding_bottom, #padding_left, #padding_right, #padding_top, #parent, #tip, #z
Instance Method Summary
collapse
Methods inherited from Button
#activate, #enabled=, #enter, #leave, #parent=, #text=
Methods inherited from Label
#draw_foreground
Methods inherited from Element
#default, #drag?, #draw_frame, #draw_rect, #enabled=, #enabled?, #font, #height, #height=, #hit?, #max_height, #max_width, #min_height, #min_width, new, original_new, #outer_height, #outer_width, #recalc, schema, #update, #width, #width=, #with, #x, #x=, #y, #y=
Methods included from Event
#events, included, #publish, #subscribe
Constructor Details
#initialize(options = {}, &block) ⇒ ComboBox
Returns a new instance of ComboBox.
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/fidgit/elements/combo_box.rb', line 37
def initialize(options = {}, &block)
options = {
background_color: default(:background_color),
border_color: default(:border_color),
}.merge! options
@value = options[:value]
@hover_index = 0
= .new(show: false) do
subscribe :selected do |widget, value|
self.value = value
end
end
@@arrow ||= Gosu::Image["combo_arrow.png"]
super('', options)
rect.height = [height, font_size + padding_top + padding_bottom].max
rect.width = [width, font_size * 4 + padding_left + padding_right].max
end
|
Instance Method Details
87
88
89
90
91
|
# File 'lib/fidgit/elements/combo_box.rb', line 87
def clear
self.text = ""
self.icon = nil
.clear
end
|
79
80
81
82
83
84
85
|
# File 'lib/fidgit/elements/combo_box.rb', line 79
def clicked_left_mouse_button(sender, x, y)
.x = self.x
.y = self.y + height + border_thickness
$window.game_state_manager.current_game_state.
nil
end
|
73
74
75
76
77
|
# File 'lib/fidgit/elements/combo_box.rb', line 73
def draw
super
size = height / @@arrow.width.to_f
@@arrow.draw x + width - height, y, z, size, size
end
|
11
|
# File 'lib/fidgit/elements/combo_box.rb', line 11
def index; .index(@value) end
|
#index=(index) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/fidgit/elements/combo_box.rb', line 26
def index=(index)
if index.between?(0, .size - 1)
self.value = [index].value
end
index
end
|
#item(text, value, options = {}, &block) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/fidgit/elements/combo_box.rb', line 61
def item(text, value, options = {}, &block)
item = .item(text, value, options, &block)
if item.value == @value
self.text = item.text
self.icon = item.icon
end
item
end
|
12
|
# File 'lib/fidgit/elements/combo_box.rb', line 12
def value; @value; end
|
#value=(value) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/fidgit/elements/combo_box.rb', line 14
def value=(value)
if @value != value
@value = value
item = .find(@value)
self.text = item.text
self.icon = item.icon
publish :changed, @value
end
value
end
|