166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
# File 'lib/erml_layout_managers.rb', line 166
def layout(container, writer)
container_full = false
widgets, remaining = printable_widgets(container, :static)
remaining.each { |widget| widget.visible = false if widget.printed }
static, relative = widgets.partition { |widget| widget.position == :static }
lpanels, unaligned = static.partition { |widget| widget.align == :left }
rpanels, unaligned = unaligned.partition { |widget| widget.align == :right }
percents, others = static.partition { |widget| widget.width_pct }
specified, others = others.partition { |widget| widget.width }
width_avail = container.content_width
specified.each do |widget|
width_avail -= widget.width
container_full = width_avail < 0
widget.disabled = container_full
width_avail -= @style.hpadding
end
if width_avail - (percents.size - 1) * @style.hpadding >= percents.size
width_avail -= (percents.size - 1) * @style.hpadding
total_percents = percents.inject(0) { |total, widget| total + widget.width }
ratio = width_avail.quo(total_percents)
percents.each do |widget|
widget.width(widget.width * ratio, :pt) if ratio < 1.0
width_avail -= widget.width
end
else
container_full = true
percents.each { |widget| widget.disabled = true }
end
width_avail -= @style.hpadding
if width_avail - (others.size - 1) * @style.hpadding >= others.size
width_avail -= (others.size - 1) * @style.hpadding
others_width = width_avail.quo(others.size)
others.each { |widget| widget.width(others_width, :pt) }
else
container_full = true
others.each { |widget| widget.disabled = true }
end
static.each do |widget|
if container.align == :bottom
widget.bottom(container.content_bottom, :pt)
else
container_full = true
widget.top(container.content_top, :pt)
end
widget.height(widget.preferred_height(writer), :pt) if widget.height.nil?
end
left = container.content_left
right = container.content_right
lpanels.each do |widget|
next if widget.disabled
widget.left(left, :pt)
left += (widget.width + @style.hpadding)
end
rpanels.reverse.each do |widget|
next if widget.disabled
widget.right(right, :pt)
right -= (widget.width + @style.hpadding)
end
unaligned.each do |widget|
next if widget.disabled
widget.left(left, :pt)
left += (widget.width + @style.hpadding)
end
if container.height.nil?
content_height = static.map { |widget| widget.height }.max || 0
container.height(content_height + container.non_content_height, :pt)
end
static.each { |widget| widget.layout_widget(writer) if widget.visible and !widget.disabled }
super(container, writer)
end
|