Class: Nuklear::UI::Button
- Includes:
- TextAlign
- Defined in:
- lib/nuklear/ui/button.rb
Instance Attribute Summary collapse
-
#align ⇒ Object
nil, or a set of alignment flags.
-
#color ⇒ Object
Returns the value of attribute color.
-
#image ⇒ Object
Returns the value of attribute image.
-
#repeat ⇒ Object
writeonly
Whether the button click event will repeat while the button is pressed.
-
#style ⇒ Object
A hash which may contain the following options: :normal => a style item, see the classes contained in Nuklear::Style :hover => a style item, see the classes contained in Nuklear::Style :active => a style item, see the classes contained in Nuklear::Style :border_color => an instance of Nuklear::Style::Color :text_background => an instance of Nuklear::Style::Color :text_normal => an instance of Nuklear::Style::Color :text_hover => an instance of Nuklear::Style::Color :text_active => an instance of Nuklear::Style::Color :text_alignment => a set of alignment flags :border => a float :rounding => a float :padding => a vec2 of floats :image_padding => a vec2 of floats :touch_padding => a vec2 of floats.
-
#symbol ⇒ Object
One of: nil, :x, :underscore, :circle_solid, :circle_outline, :rect_solid, :rect_outline, :triangle_up, :triangle_down, :triangle_left, :triangle_right, :plus, :minus or :max.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(text = nil, style: nil, repeat: false, color: nil, symbol: nil, image: nil, align: nil, **options, &block) ⇒ Button
constructor
A new instance of Button.
- #repeat? ⇒ Boolean
- #result(result, context) ⇒ Object
- #to_command ⇒ Object
Methods included from TextAlign
Methods inherited from Base
Methods included from Enableable
#disable, #disabled=, #disabled?, #enable, #enabled=, #enabled?
Methods included from Events
#event_listeners_for, #on, #trigger
Constructor Details
#initialize(text = nil, style: nil, repeat: false, color: nil, symbol: nil, image: nil, align: nil, **options, &block) ⇒ Button
Returns a new instance of Button.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/nuklear/ui/button.rb', line 40 def initialize(text = nil, style: nil, repeat: false, color: nil, symbol: nil, image: nil, align: nil, **, &block) super(**) @text = text @style = style @repeat = repeat @color = color @symbol = symbol @image = image @align = align on(:clicked, &block) if block_given? end |
Instance Attribute Details
#align ⇒ Object
nil, or a set of alignment flags
38 39 40 |
# File 'lib/nuklear/ui/button.rb', line 38 def align @align end |
#color ⇒ Object
Returns the value of attribute color.
28 29 30 |
# File 'lib/nuklear/ui/button.rb', line 28 def color @color end |
#image ⇒ Object
Returns the value of attribute image.
35 36 37 |
# File 'lib/nuklear/ui/button.rb', line 35 def image @image end |
#repeat=(value) ⇒ Object (writeonly)
Whether the button click event will repeat while the button is pressed
26 27 28 |
# File 'lib/nuklear/ui/button.rb', line 26 def repeat=(value) @repeat = value end |
#style ⇒ Object
A hash which may contain the following options:
:normal => a style item, see the classes contained in Nuklear::Style
:hover => a style item, see the classes contained in Nuklear::Style
:active => a style item, see the classes contained in Nuklear::Style
:border_color => an instance of Nuklear::Style::Color
:text_background => an instance of Nuklear::Style::Color
:text_normal => an instance of Nuklear::Style::Color
:text_hover => an instance of Nuklear::Style::Color
:text_active => an instance of Nuklear::Style::Color
:text_alignment => a set of alignment flags
:border => a float
:rounding => a float
:padding => a vec2 of floats
:image_padding => a vec2 of floats
:touch_padding => a vec2 of floats
23 24 25 |
# File 'lib/nuklear/ui/button.rb', line 23 def style @style end |
#symbol ⇒ Object
One of: nil, :x, :underscore, :circle_solid, :circle_outline, :rect_solid, :rect_outline, :triangle_up, :triangle_down, :triangle_left, :triangle_right, :plus, :minus or :max
33 34 35 |
# File 'lib/nuklear/ui/button.rb', line 33 def symbol @symbol end |
#text ⇒ Object
Returns the value of attribute text.
6 7 8 |
# File 'lib/nuklear/ui/button.rb', line 6 def text @text end |
Instance Method Details
#repeat? ⇒ Boolean
52 53 54 |
# File 'lib/nuklear/ui/button.rb', line 52 def repeat? @repeat end |
#result(result, context) ⇒ Object
70 71 72 73 74 |
# File 'lib/nuklear/ui/button.rb', line 70 def result(result, context) if result == 1 then trigger(:clicked) else trigger(:released) end end |
#to_command ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/nuklear/ui/button.rb', line 56 def to_command [ :ui_button, { repeat: repeat?, title: text, color: color, symbol: symbol, image: image, style: style, alignment: align_as_flags(align) } ] end |