Class: HotCocoa::LayoutOptions
Overview
Stores the layout configuration for an object (e.g. a button).
Constant Summary
- VALID_EXPANSIONS =
List of valid values for the #expand parameter.
[nil, :height, :width, [:height, :width], [:width, :height]]
Instance Attribute Summary (collapse)
-
- (HotCocoa::LayoutView) defaults_view
The layout view to which this configuration belongs.
-
- (Number) padding
Number of pixels of padding to add to each side of the view, unless otherwies overridden by setting
left_padding,right_padding, etc. - - (NSView) view readonly
Instance Method Summary (collapse)
-
- (Symbol) align
Returns which way that a view should be aligned.
-
- (Object) align=(value)
Set which way the view should be aligned in the packing view.
-
- (Number) bottom_padding
Return how much padding should be added to the buttom of the view.
-
- (Object) bottom_padding=(value)
Set how much padding, in pixels, should be added to the bottom of the view.
-
- (Symbol, ...) expand
Returns how a view should expand in its packing view.
-
- (Object) expand=(value)
Set whether or not the view should expand in either width or height to fill in unused space in the view.
-
- (Boolean) expand_height?
Whether or not to expand the view height-wise.
-
- (Boolean) expand_width?
Whether or not to expand the view width-wise.
-
- (LayoutOptions) initialize(view, options = {})
constructor
A new instance of LayoutOptions.
-
- (String) inspect
"Pretty" string version of the configuration.
-
- (Number) left_padding
Return how much padding should be added to the left of the view.
-
- (Object) left_padding=(value)
Set the amount of padding, in pixels, to add to the left of the view.
-
- (Number) right_padding
Return how much padding should be added to the right of the view.
-
- (Object) right_padding=(value)
Return how much padding, in pixels, should be added to the right of the view.
-
- (Object) start=(value)
Set if this view should be relative to the start or end of the packing view.
-
- (Boolean) start?
Whether or not to layout the view relative to the top of the packing view.
-
- (Number) top_padding
Return how much padding should be added to the top of the view.
-
- (Object) top_padding=(value)
Set how much padding, in pixels, should be added to the top of the view.
-
- (Object) update_layout_views!
Tell the object using the configuration that it needs to relayout.
Constructor Details
- (LayoutOptions) initialize(view, options = {})
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
- (HotCocoa::LayoutView) defaults_view
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 |
- (Number) padding
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 |
- (NSView) view (readonly)
18 19 20 |
# File 'lib/hotcocoa/layout_view.rb', line 18 def view @view end |
Instance Method Details
- (Symbol) align
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 |
- (Object) align=(value)
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 |
- (Number) bottom_padding
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 |
- (Object) bottom_padding=(value)
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 |
- (Symbol, ...) expand
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 |
- (Object) expand=(value)
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 |
- (Boolean) expand_height?
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 |
- (Boolean) expand_width?
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 |
- (String) inspect
"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 |
- (Number) left_padding
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 |
- (Object) left_padding=(value)
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 |
- (Number) right_padding
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 |
- (Object) right_padding=(value)
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 |
- (Object) start=(value)
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 |
- (Boolean) start?
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 |
- (Number) top_padding
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 |
- (Object) top_padding=(value)
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 |
- (Object) update_layout_views!
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 |