Class: ExampleApp::TallButton
- Inherits:
-
Zif::UI::TwoStageButton
- Object
- Zif::Sprite
- Zif::CompoundSprite
- Zif::UI::TwoStageButton
- ExampleApp::TallButton
- Includes:
- Zif::Serializable
- Defined in:
- app/ui/components/tall_button.rb
Overview
A two-stage button, sized for all of the tall buttons in the Kenny UI pack.
Constant Summary collapse
- SPRITES_PATH =
'sprites/kenney-uipack-fixed/danhealy-modified'.freeze
- VALID_COLORS =
%i[blue green red yellow white].freeze
- EDGE_WIDTH =
6
- PRESSED_HEIGHT =
45
- NORMAL_HEIGHT =
49
Constants inherited from Zif::Sprite
Instance Attribute Summary
Attributes inherited from Zif::UI::TwoStageButton
#is_pressed, #label_y_offset, #normal, #pressed, #pressed_height
Attributes inherited from Zif::CompoundSprite
Attributes inherited from Zif::Sprite
#a, #angle, #b, #g, #h, #logical_x, #logical_y, #name, #path, #r, #render_target, #source_h, #source_w, #source_x, #source_y, #w, #x, #y, #z_index
Attributes included from Zif::Clickable
#on_mouse_changed, #on_mouse_down, #on_mouse_up
Attributes included from Zif::Actions::Animatable
#animation_sequences, #cur_animation
Attributes included from Zif::Actions::Actionable
Instance Method Summary collapse
- #change_color(color) ⇒ Object
-
#initialize(name = Zif.unique_name('tall_button'), width = 100, color = :blue, label_text = nil, label_size = -1,, &block) ⇒ TallButton
constructor
A new instance of TallButton.
- #resize_width(width) ⇒ Object
- #width ⇒ Object
-
#width=(new_width) ⇒ Object
Width methods to support actions.
Methods included from Zif::Serializable
#exclude_from_serialize, #inspect, #serialize, #to_s
Methods inherited from Zif::UI::TwoStageButton
#label, #label_text=, #press, #recenter_label, #retruncate_label, #toggle_on_change, #toggle_pressed, #unpress
Methods inherited from Zif::CompoundSprite
Methods inherited from Zif::Sprite
#blend, #blend=, #center, #center_x, #center_y, #clicked?, #color, #color=, #dup_and_assign, #exclude_from_serialize, #hide, #rect, rect_array_to_hash, rect_array_to_source_hash, #rect_hash, rect_hash_to_source_hash, #show, #source_as_rect_hash, #source_center, #source_is_set?, #source_rect, #source_rect_hash, #source_wh, #source_xy, #to_h, #view_actual_size!, #wh, #xy, #zoom_factor
Methods included from Zif::Clickable
Methods included from Zif::Actions::Animatable
#new_basic_animation, #new_tiled_animation, #register_animation_sequence, #run_animation_sequence, #stop_animating
Methods included from Zif::Actions::Actionable
#bounce_forever_around, #delayed_action, #fade_in, #fade_out, #fade_out_and_in_forever, #new_action, #perform_actions, #run_action, #running_actions?, #stop_action
Methods included from Zif::Assignable
Constructor Details
#initialize(name = Zif.unique_name('tall_button'), width = 100, color = :blue, label_text = nil, label_size = -1,, &block) ⇒ TallButton
Returns a new instance of TallButton.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/ui/components/tall_button.rb', line 13 def initialize(name=Zif.unique_name('tall_button'), width=100, color=:blue, label_text=nil, label_size=-1, &block) super(name, &block) @h = NORMAL_HEIGHT @pressed_height = PRESSED_HEIGHT - 1 @label_y_offset = 0 @normal_left = Zif::Sprite.new.tap do |s| s.x = 0 s.y = 0 s.w = EDGE_WIDTH s.h = NORMAL_HEIGHT end @normal_center = Zif::Sprite.new.tap do |s| s.x = EDGE_WIDTH s.y = 0 s.h = NORMAL_HEIGHT end @normal_right = Zif::Sprite.new.tap do |s| s.y = 0 s.w = EDGE_WIDTH s.h = NORMAL_HEIGHT s.flip_horizontally = true end @pressed_left = Zif::Sprite.new.tap do |s| s.x = 0 s.y = 0 s.w = EDGE_WIDTH s.h = PRESSED_HEIGHT end @pressed_center = Zif::Sprite.new.tap do |s| s.x = EDGE_WIDTH s.y = 0 s.h = PRESSED_HEIGHT end @pressed_right = Zif::Sprite.new.tap do |s| s.y = 0 s.w = EDGE_WIDTH s.h = PRESSED_HEIGHT s.flip_horizontally = true end resize_width(width) change_color(color) @normal = [@normal_left, @normal_center, @normal_right] @pressed = [@pressed_left, @pressed_center, @pressed_right] if label_text @labels << FutureLabel.new(label_text, size: label_size, alignment: :center) recenter_label retruncate_label end unpress end |
Instance Method Details
#change_color(color) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/ui/components/tall_button.rb', line 102 def change_color(color) @color = VALID_COLORS.include?(color) ? color : :blue [@normal_left, @normal_right].each do |edge| edge.path = "#{SPRITES_PATH}/button_normal_#{@color}_edge.png" end @normal_center.path = "#{SPRITES_PATH}/button_normal_#{@color}_center.png" [@pressed_left, @pressed_right].each do |edge| edge.path = "#{SPRITES_PATH}/button_pressed_#{@color}_edge.png" end @pressed_center.path = "#{SPRITES_PATH}/button_pressed_#{@color}_center.png" end |
#resize_width(width) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/ui/components/tall_button.rb', line 84 def resize_width(width) return if @w == width @w = width view_actual_size! [@normal_center, @pressed_center].each do |center| center.w = @w - (2 * EDGE_WIDTH) end [@normal_right, @pressed_right].each do |r_edge| r_edge.x = @w - EDGE_WIDTH end recenter_label retruncate_label(2 * EDGE_WIDTH) end |
#width ⇒ Object
80 81 82 |
# File 'app/ui/components/tall_button.rb', line 80 def width @w end |
#width=(new_width) ⇒ Object
Width methods to support actions
76 77 78 |
# File 'app/ui/components/tall_button.rb', line 76 def width=(new_width) resize_width(new_width) end |