Class: HotCocoa::LayoutOptions
Overview
Stores the layout configuration for an object (e.g. a button).
Constant Summary collapse
- VALID_EXPANSIONS =
List of valid values for the #expand parameter.
[nil, :height, :width, [:height, :width], [:width, :height]]
Instance Attribute Summary collapse
-
#defaults_view ⇒ HotCocoa::LayoutView
The layout view to which this configuration belongs.
-
#padding ⇒ Number
Number of pixels of padding to add to each side of the view, unless otherwies overridden by setting
left_padding
,right_padding
, etc. - #view ⇒ NSView readonly
Instance Method Summary collapse
-
#align ⇒ Symbol
Returns which way that a view should be aligned.
-
#align=(value) ⇒ Object
Set which way the view should be aligned in the packing view.
-
#bottom_padding ⇒ Number
Return how much padding should be added to the buttom of the view.
-
#bottom_padding=(value) ⇒ Object
Set how much padding, in pixels, should be added to the bottom of the view.
-
#expand ⇒ Symbol, ...
Returns how a view should expand in its packing view.
-
#expand=(value) ⇒ Object
Set whether or not the view should expand in either width or height to fill in unused space in the view.
-
#expand_height? ⇒ Boolean
Whether or not to expand the view height-wise.
-
#expand_width? ⇒ Boolean
Whether or not to expand the view width-wise.
-
#initialize(view, options = {}) ⇒ LayoutOptions
constructor
A new instance of LayoutOptions.
-
#inspect ⇒ String
"Pretty" string version of the configuration.
-
#left_padding ⇒ Number
Return how much padding should be added to the left of the view.
-
#left_padding=(value) ⇒ Object
Set the amount of padding, in pixels, to add to the left of the view.
-
#right_padding ⇒ Number
Return how much padding should be added to the right of the view.
-
#right_padding=(value) ⇒ Object
Return how much padding, in pixels, should be added to the right of the view.
-
#start=(value) ⇒ Object
Set if this view should be relative to the start or end of the packing view.
-
#start? ⇒ Boolean
Whether or not to layout the view relative to the top of the packing view.
-
#top_padding ⇒ Number
Return how much padding should be added to the top of the view.
-
#top_padding=(value) ⇒ Object
Set how much padding, in pixels, should be added to the top of the view.
-
#update_layout_views! ⇒ Object
Tell the object using the configuration that it needs to relayout.
Constructor Details
#initialize(view, options = {}) ⇒ LayoutOptions
Returns a new instance of LayoutOptions.
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/hotcocoa/layout_view.rb', line 61 def initialize view, = {} @view = view @start = [:start] @expand = [:expand] @padding = [:padding] || 0 @left_padding = @padding || [:left_padding] @right_padding = @padding || [:right_padding] @top_padding = @padding || [:top_padding] @bottom_padding = @padding || [:bottom_padding] @align = [:align] @defaults_view = [:defaults_view] end |
Instance Attribute Details
#defaults_view ⇒ HotCocoa::LayoutView
The layout view to which this configuration belongs.
15 16 17 |
# File 'lib/hotcocoa/layout_view.rb', line 15 def defaults_view @defaults_view end |
#padding ⇒ Number
Number of pixels of padding to add to each side of the view, unless
otherwies overridden by setting left_padding
, right_padding
, etc.
285 286 287 |
# File 'lib/hotcocoa/layout_view.rb', line 285 def padding @padding end |
#view ⇒ NSView (readonly)
18 19 20 |
# File 'lib/hotcocoa/layout_view.rb', line 18 def view @view end |
Instance Method Details
#align ⇒ Symbol
Returns which way that a view should be aligned.
Possible values are documented in #initialize.
260 261 262 263 264 265 266 267 |
# File 'lib/hotcocoa/layout_view.rb', line 260 def align return @align unless @align.nil? if in_layout_view? @view.superview.default_layout.align else :left end end |
#align=(value) ⇒ Object
Set which way the view should be aligned in the packing view.
Possible values are documented in #initialize.
248 249 250 251 252 |
# File 'lib/hotcocoa/layout_view.rb', line 248 def align= value return if value == @align @align = value update_layout_views! end |
#bottom_padding ⇒ Number
Return how much padding should be added to the buttom of the view.
233 234 235 236 237 238 239 240 |
# File 'lib/hotcocoa/layout_view.rb', line 233 def bottom_padding return @bottom_padding unless @bottom_padding.nil? if in_layout_view? @view.superview.default_layout.bottom_padding else padding end end |
#bottom_padding=(value) ⇒ Object
Set how much padding, in pixels, should be added to the bottom of the view.
222 223 224 225 226 227 |
# File 'lib/hotcocoa/layout_view.rb', line 222 def bottom_padding= value return if value == @bottom_padding @bottom_padding = value @padding = nil update_layout_views! end |
#expand ⇒ Symbol, ...
Returns how a view should expand in its packing view.
If there is nothing set for the expansion, then this
method will return false
.
120 121 122 123 124 125 126 127 |
# File 'lib/hotcocoa/layout_view.rb', line 120 def return @expand unless @expand.nil? if in_layout_view? @view.superview.default_layout. else false end end |
#expand=(value) ⇒ Object
Set whether or not the view should expand in either width or height to fill in unused space in the view.
The available values are those from VALID_EXPANSIONS.
104 105 106 107 108 109 110 111 |
# File 'lib/hotcocoa/layout_view.rb', line 104 def value return if value == @expand unless VALID_EXPANSIONS.include?(value) raise ArgumentError, "Expand must be nil, :height, :width or [:width, :height] not #{value.inspect}" end @expand = value update_layout_views! end |
#expand_height? ⇒ Boolean
Whether or not to expand the view height-wise.
138 139 140 141 |
# File 'lib/hotcocoa/layout_view.rb', line 138 def e = self. e == :height || (e.respond_to?(:include?) && e.include?(:height)) end |
#expand_width? ⇒ Boolean
Whether or not to expand the view width-wise.
131 132 133 134 |
# File 'lib/hotcocoa/layout_view.rb', line 131 def e = self. e == :width || (e.respond_to?(:include?) && e.include?(:width)) end |
#inspect ⇒ String
"Pretty" string version of the configuration.
291 292 293 294 295 296 297 298 |
# File 'lib/hotcocoa/layout_view.rb', line 291 def inspect "#<#{self.class} " + "start=#{start?}, " + "expand=#{.inspect}, " + "padding=[l:#{left_padding}, r:#{right_padding}, t:#{top_padding}, b:#{bottom_padding}], " + "align=#{align.inspect}, " + "view=#{view.inspect}>" end |
#left_padding ⇒ Number
Return how much padding should be added to the left of the view.
159 160 161 162 163 164 165 166 |
# File 'lib/hotcocoa/layout_view.rb', line 159 def left_padding return @left_padding unless @left_padding.nil? if in_layout_view? @view.superview.default_layout.left_padding else padding end end |
#left_padding=(value) ⇒ Object
Set the amount of padding, in pixels, to add to the left of the view
148 149 150 151 152 153 |
# File 'lib/hotcocoa/layout_view.rb', line 148 def left_padding= value return if value == @left_padding @left_padding = value @padding = nil update_layout_views! end |
#right_padding ⇒ Number
Return how much padding should be added to the right of the view.
183 184 185 186 187 188 189 190 |
# File 'lib/hotcocoa/layout_view.rb', line 183 def right_padding return @right_padding unless @right_padding.nil? if in_layout_view? @view.superview.default_layout.right_padding else padding end end |
#right_padding=(value) ⇒ Object
Return how much padding, in pixels, should be added to the right of the view.
172 173 174 175 176 177 |
# File 'lib/hotcocoa/layout_view.rb', line 172 def right_padding= value return if value == @right_padding @right_padding = value @padding = nil update_layout_views! end |
#start=(value) ⇒ Object
Set if this view should be relative to the start or end of the packing view.
79 80 81 82 83 |
# File 'lib/hotcocoa/layout_view.rb', line 79 def start= value return if value == @start @start = value update_layout_views! end |
#start? ⇒ Boolean
Whether or not to layout the view relative to the top of the packing view.
88 89 90 91 92 93 94 95 |
# File 'lib/hotcocoa/layout_view.rb', line 88 def start? return @start unless @start.nil? if in_layout_view? @view.superview.default_layout.start? else true end end |
#top_padding ⇒ Number
Return how much padding should be added to the top of the view.
208 209 210 211 212 213 214 215 |
# File 'lib/hotcocoa/layout_view.rb', line 208 def top_padding return @top_padding unless @top_padding.nil? if in_layout_view? @view.superview.default_layout.top_padding else padding end end |
#top_padding=(value) ⇒ Object
Set how much padding, in pixels, should be added to the top of the view.
197 198 199 200 201 202 |
# File 'lib/hotcocoa/layout_view.rb', line 197 def top_padding= value return if value == @top_padding @top_padding = value @padding = nil update_layout_views! end |
#update_layout_views! ⇒ Object
Tell the object using the configuration that it needs to relayout.
302 303 304 305 |
# File 'lib/hotcocoa/layout_view.rb', line 302 def update_layout_views! @view.superview.relayout! if in_layout_view? @defaults_view.relayout! if @defaults_view end |