Class: HotCocoa::LayoutOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/hotcocoa/layout_view.rb

Constant Summary collapse

VALID_EXPANSIONS =
[nil, :height, :width, [:height, :width], [:width, :height]]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view, options = {}) ⇒ LayoutOptions

Returns a new instance of LayoutOptions.

Parameters:

  • view (NSView)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :start (Boolean) — default: true

    Whether the view is packed at the start or the end of the packing view

  • :expand (Symbol) — default: nil

    Whether the view's first dimension (width for horizontal and height for vertical) should be expanded to the maximum possible size, and should be variable according to the packing view frame. Values can be :height, :width, or [:height, :width]

  • :padding (Float) — default: 0.0

    Controls the padding area around the view. :padding controls all the areas, while options like :left_padding only control the left side--if :padding is set, other padding flags are ignored

  • :left_padding (Fload) — default: 0.0
  • :right_padding (Float) — default: 0.0
  • :top_padding (Float) — default: 0.0
  • :bottom_padding (Float) — default: 0.0
  • :align (Symbol)

    Controls the view's alignment if its not expanded in the other dimension; modes can be:

    • :left For horizontal layouts, align left

    • :center Align center for horizontal or vertical layouts

    • :right For horizontal layouts, align right

    • :top For vertical layouts, align top

    • :bottom For vertical layouts, align bottom

  • :defaults_view (NSView)

    not sure yet...



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/hotcocoa/layout_view.rb', line 50

def initialize view, options = {}
  @view           = view
  @start          = options[:start]
  @expand         = options[:expand]
  @padding        = options[:padding]
  @left_padding   = @padding || options[:left_padding]
  @right_padding  = @padding || options[:right_padding]
  @top_padding    = @padding || options[:top_padding]
  @bottom_padding = @padding || options[:bottom_padding]
  @align          = options[:align]
  @defaults_view  = options[:defaults_view]
end

Instance Attribute Details

#defaults_viewObject

Returns the value of attribute defaults_view.



5
6
7
# File 'lib/hotcocoa/layout_view.rb', line 5

def defaults_view
  @defaults_view
end

#viewNSView (readonly)

Returns:

  • (NSView)


8
9
10
# File 'lib/hotcocoa/layout_view.rb', line 8

def view
  @view
end

Instance Method Details

#alignObject



170
171
172
173
174
175
176
177
# File 'lib/hotcocoa/layout_view.rb', line 170

def align
  return @align unless @align.nil?
  if in_layout_view?
    @view.superview.default_layout.align
  else
    :left
  end
end

#align=(value) ⇒ Object



179
180
181
182
183
# File 'lib/hotcocoa/layout_view.rb', line 179

def align= value
  return if value == @align
  @align = value
  update_layout_views!
end

#bottom_paddingObject



161
162
163
164
165
166
167
168
# File 'lib/hotcocoa/layout_view.rb', line 161

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



154
155
156
157
158
159
# File 'lib/hotcocoa/layout_view.rb', line 154

def bottom_padding= value
  return if value == @bottom_padding
  @bottom_padding = value
  @padding = nil
  update_layout_views!
end

#expandObject



87
88
89
90
91
92
93
94
# File 'lib/hotcocoa/layout_view.rb', line 87

def expand
  return @expand unless @expand.nil?
  if in_layout_view?
    @view.superview.default_layout.expand
  else
    false
  end
end

#expand=(value) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/hotcocoa/layout_view.rb', line 78

def expand= 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

Returns:

  • (Boolean)


101
102
103
104
# File 'lib/hotcocoa/layout_view.rb', line 101

def expand_height?
  e = self.expand
  e == :height || (e.respond_to?(:include?) && e.include?(:height))
end

#expand_width?Boolean

Returns:

  • (Boolean)


96
97
98
99
# File 'lib/hotcocoa/layout_view.rb', line 96

def expand_width?
  e = self.expand
  e == :width || (e.respond_to?(:include?) && e.include?(:width))
end

#inspectObject



196
197
198
199
200
201
202
203
# File 'lib/hotcocoa/layout_view.rb', line 196

def inspect
  "#<#{self.class} " +
    "start=#{start?}, " +
    "expand=#{expand.inspect}, " +
    "padding=[l:#{left_padding}, r:#{right_padding}, t:#{top_padding}, b:#{bottom_padding}], " +
    "align=#{align.inspect}, " +
    "view=#{view.inspect}>"
end

#left_paddingObject



113
114
115
116
117
118
119
120
# File 'lib/hotcocoa/layout_view.rb', line 113

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



106
107
108
109
110
111
# File 'lib/hotcocoa/layout_view.rb', line 106

def left_padding= value
  return if value == @left_padding
  @left_padding = value
  @padding = nil
  update_layout_views!
end

#paddingObject



192
193
194
# File 'lib/hotcocoa/layout_view.rb', line 192

def padding
  @padding || 0.0
end

#padding=(value) ⇒ Object



185
186
187
188
189
190
# File 'lib/hotcocoa/layout_view.rb', line 185

def padding= value
  return if value == @padding
  @right_padding = @left_padding = @top_padding = @bottom_padding = value
  @padding = value
  update_layout_views!
end

#right_paddingObject



129
130
131
132
133
134
135
136
# File 'lib/hotcocoa/layout_view.rb', line 129

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



122
123
124
125
126
127
# File 'lib/hotcocoa/layout_view.rb', line 122

def right_padding= value
  return if value == @right_padding
  @right_padding = value
  @padding = nil
  update_layout_views!
end

#start=(value) ⇒ Object



63
64
65
66
67
# File 'lib/hotcocoa/layout_view.rb', line 63

def start= value
  return if value == @start
  @start = value
  update_layout_views!
end

#start?Boolean

Returns:

  • (Boolean)


69
70
71
72
73
74
75
76
# File 'lib/hotcocoa/layout_view.rb', line 69

def start?
  return @start unless @start.nil?
  if in_layout_view?
    @view.superview.default_layout.start?
  else
    true
  end
end

#top_paddingObject



145
146
147
148
149
150
151
152
# File 'lib/hotcocoa/layout_view.rb', line 145

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



138
139
140
141
142
143
# File 'lib/hotcocoa/layout_view.rb', line 138

def top_padding= value
  return if value == @top_padding
  @top_padding = value
  @padding = nil
  update_layout_views!
end

#update_layout_views!Object



205
206
207
208
# File 'lib/hotcocoa/layout_view.rb', line 205

def update_layout_views!
  @view.superview.relayout! if in_layout_view?
  @defaults_view.relayout!  if @defaults_view
end