Class: Zif::UI::NinePanelEdge Deprecated
- Inherits:
-
Object
- Object
- Zif::UI::NinePanelEdge
- Defined in:
- lib/zif/ui/nine_panel_edge.rb
Overview
Meant for complex edges in the NinePanel.
This is sort of an example as to how you could extend the simple framework of the NinePanel for some UI component which is a little more complex. In this case, we want to have an extension of each corner, plus some transition graphic between each extension.
So it looks kinda like this: <—-X—-> Where X
is the transition graphic, the -
‘s are left and right edge, and the <>’s are the corners
Two corners are provided by NinePanel already, so this just defines the extra components of the edge: left right and center, as #left_edge #right_edge and #transition.
At least one of #left_edge #right_edge must be present, but the rest is optional. If you only define one edge it should act the same as a regular edge in NinePanel.
Since this is basically just an example, some documentation is missing here and this is marked as deprecated. See the code and ExampleApp::MetalPanel
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#left_edge ⇒ Zif::Sprite
A sprite for the left edge.
-
#ready ⇒ Object
Returns the value of attribute ready.
-
#right_edge ⇒ Zif::Sprite
A sprite for the left edge.
-
#transition ⇒ Object
Returns the value of attribute transition.
-
#transition_height ⇒ Object
Returns the value of attribute transition_height.
-
#transition_path ⇒ Object
Returns the value of attribute transition_path.
-
#transition_width ⇒ Object
Returns the value of attribute transition_width.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #check_ready ⇒ Object
-
#init_sprites ⇒ Object
This must be manually called once after setting up component edges Creates the sprites for the different segments based on what’s been set Either left or right edge must be present, and @ready is set based on this.
-
#initialize ⇒ NinePanelEdge
constructor
Need to set at least one of left/right_edge, and optionally a transition, after initialize.
- #max_height ⇒ Object
- #min_width ⇒ Object
- #reposition(x, y) ⇒ Object
- #resize_width(new_width = min_width) ⇒ Object
- #sprites ⇒ Object
-
#stretch(x, y, new_width = min_width) ⇒ Object
Given a goal width, stretch the given segments across it If only one of left/right edge is given, that will just be stretched to fit If a transition is given, it will be placed after “left” but before “right” and not stretched If both left and right are given, the goal width is divided between them and the left side is prefered if it’s odd.
- #update_paths ⇒ Object
Constructor Details
#initialize ⇒ NinePanelEdge
Need to set at least one of left/right_edge, and optionally a transition, after initialize
39 40 41 42 43 44 45 |
# File 'lib/zif/ui/nine_panel_edge.rb', line 39 def initialize @left_edge_height = 0 @right_edge_height = 0 @transition_width = 0 @transition_height = 0 @ready = false end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
23 24 25 |
# File 'lib/zif/ui/nine_panel_edge.rb', line 23 def height @height end |
#left_edge ⇒ Zif::Sprite
Returns A sprite for the left edge.
|
# File 'lib/zif/ui/nine_panel_edge.rb', line 25
|
#ready ⇒ Object
Returns the value of attribute ready.
23 24 25 |
# File 'lib/zif/ui/nine_panel_edge.rb', line 23 def ready @ready end |
#right_edge ⇒ Zif::Sprite
Returns A sprite for the left edge.
|
# File 'lib/zif/ui/nine_panel_edge.rb', line 28
|
#transition ⇒ Object
Returns the value of attribute transition.
36 37 38 |
# File 'lib/zif/ui/nine_panel_edge.rb', line 36 def transition @transition end |
#transition_height ⇒ Object
Returns the value of attribute transition_height.
36 37 38 |
# File 'lib/zif/ui/nine_panel_edge.rb', line 36 def transition_height @transition_height end |
#transition_path ⇒ Object
Returns the value of attribute transition_path.
36 37 38 |
# File 'lib/zif/ui/nine_panel_edge.rb', line 36 def transition_path @transition_path end |
#transition_width ⇒ Object
Returns the value of attribute transition_width.
36 37 38 |
# File 'lib/zif/ui/nine_panel_edge.rb', line 36 def transition_width @transition_width end |
#width ⇒ Object
Returns the value of attribute width.
23 24 25 |
# File 'lib/zif/ui/nine_panel_edge.rb', line 23 def width @width end |
Instance Method Details
#check_ready ⇒ Object
146 147 148 |
# File 'lib/zif/ui/nine_panel_edge.rb', line 146 def check_ready raise 'Must call #init_sprites after setting left/right edges and transition' unless @ready end |
#init_sprites ⇒ Object
This must be manually called once after setting up component edges Creates the sprites for the different segments based on what’s been set Either left or right edge must be present, and @ready is set based on this. Transition is optional.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/zif/ui/nine_panel_edge.rb', line 50 def init_sprites if @left_edge_path @left_edge = Zif::Sprite.new.tap do |edge| edge.h = @left_edge_height edge.w = @cur_left_edge_width end end if @right_edge_path @right_edge = Zif::Sprite.new.tap do |edge| edge.h = @right_edge_height edge.w = @cur_right_edge_width end end if @transition_path @transition = Zif::Sprite.new.tap do |edge| edge.h = @transition_height edge.w = @transition_width end end @ready = [@left_edge, @right_edge].any? update_paths end |
#max_height ⇒ Object
77 78 79 |
# File 'lib/zif/ui/nine_panel_edge.rb', line 77 def max_height [@left_edge_height, @right_edge_height, @transition_height].max end |
#min_width ⇒ Object
81 82 83 |
# File 'lib/zif/ui/nine_panel_edge.rb', line 81 def min_width (@left_edge_path ? 1 : 0) + @transition_width + (@right_edge_path ? 1 : 0) end |
#reposition(x, y) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/zif/ui/nine_panel_edge.rb', line 95 def reposition(x, y) check_ready cur_x = x if @left_edge @left_edge.x = cur_x @left_edge.y = (max_height - @left_edge_height) + y cur_x += @cur_left_edge_width end if @transition @transition.x = cur_x @transition.y = (max_height - @transition_height) + y cur_x += @transition_width end return unless @right_edge @right_edge.x = cur_x @right_edge.y = (max_height - @right_edge_height) + y end |
#resize_width(new_width = min_width) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/zif/ui/nine_panel_edge.rb', line 117 def resize_width(new_width=min_width) check_ready @width = [new_width, min_width].max.floor @height = max_height # Set side width if @left_edge && @right_edge # TODO: Allow setting a max width. Right now this places the transition exactly in the center. each_side_width, extra_for_left_side = (@width - @transition_width).divmod(2) @cur_left_edge_width = each_side_width + extra_for_left_side @cur_right_edge_width = each_side_width else @cur_left_edge_width = @cur_right_edge_width = (@width - @transition_width) end @left_edge.w = @cur_left_edge_width if @left_edge @right_edge.w = @cur_right_edge_width if @right_edge end |
#sprites ⇒ Object
150 151 152 |
# File 'lib/zif/ui/nine_panel_edge.rb', line 150 def sprites [@left_edge, @transition, @right_edge] end |
#stretch(x, y, new_width = min_width) ⇒ Object
Given a goal width, stretch the given segments across it If only one of left/right edge is given, that will just be stretched to fit If a transition is given, it will be placed after “left” but before “right” and not stretched If both left and right are given, the goal width is divided between them and the left side is prefered if it’s odd
89 90 91 92 93 |
# File 'lib/zif/ui/nine_panel_edge.rb', line 89 def stretch(x, y, new_width=min_width) resize_width(new_width) reposition(x, y) sprites end |
#update_paths ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/zif/ui/nine_panel_edge.rb', line 138 def update_paths return unless @ready @left_edge.path = @left_edge_path if @left_edge_path @right_edge.path = @right_edge_path if @right_edge_path @transition.path = @transition_path if @transition_path end |