Class: EideticRML::LayoutManagers::VBoxLayout
- Inherits:
-
LayoutManager
- Object
- LayoutManager
- EideticRML::LayoutManagers::VBoxLayout
- Defined in:
- lib/erml_layout_managers.rb
Instance Method Summary collapse
- #layout(container, writer) ⇒ Object
- #preferred_height(grid, writer) ⇒ Object
- #preferred_width(grid, writer) ⇒ Object
Methods inherited from LayoutManager
#after_layout, #col_grid, for_name, #initialize, #layout_absolute, #layout_relative, register, #row_grid
Constructor Details
This class inherits a constructor from EideticRML::LayoutManagers::LayoutManager
Instance Method Details
#layout(container, writer) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/erml_layout_managers.rb', line 267 def layout(container, writer) # $stderr.puts "layout container: #{container.tag}" container_full = false , remaining = (container, :static) remaining.each { || .visible = false if .printed } static, relative = .partition { || .position == :static } headers, unaligned = static.partition { || .align == :top } , unaligned = unaligned.partition { || .align == :bottom } static.each do || .before_layout # puts "<1> vbox widget width: #{widget.width} #{widget.path}" .width([.preferred_width(writer) || container.content_width, container.content_width].min, :pt) if .width.nil? # puts "<2> vbox widget width: #{widget.width} #{widget.path}" .left(container.content_left, :pt) end top, dy = container.content_top, 0 bottom = container.content_top + container.max_content_height headers.each_with_index do |, index| .top(top, :pt) .(writer) # swapped .height(.preferred_height(writer), :pt) if .height.nil? # swapped top += (.height + @style.vpadding) dy += .height + ((index > 0) ? @style.vpadding : 0) end headers.each { || .visible = (.bottom <= bottom) } # or first static widget? unless .empty? container.height('100%') if container.height.nil? .reverse.each do || .bottom(bottom, :pt) .(writer) # swapped .height(.preferred_height(writer), :pt) if .height.nil? # swapped bottom -= (.height + @style.vpadding) end end .each { || .visible = (.top >= top) } # or first static widget? = 0 unaligned.each_with_index do |, index| .visible = !container_full next if container_full .top(top, :pt) # puts "<1> vbox widget height: #{widget.height} #{widget.path}" .(writer) # swapped # puts "<2> vbox widget height: #{widget.height} #{widget.path}" .height(.preferred_height(writer), :pt) if .height.nil? # swapped # puts "<3> vbox widget height: #{widget.height} #{widget.path}" top += .height dy += .height + (index > 0 ? @style.vpadding : 0) #if widget.visible if top > bottom container_full = true .visible = ( == 0) # widget.visible = widget.leaves > 0 and container.root_page.positioned_widgets[:static] == 0 # $stderr.puts "+++vbox+++ #{container.root_page.positioned_widgets[:static]}, tag: #{widget.tag}, visible: #{widget.visible}" end += 1 if .visible top += @style.vpadding end # set_height = container.height.nil? # container.height(container.max_height_avail, :pt) if set_height # unaligned.each_with_index do |widget, index| # # widget.visible = (widget.bottom <= bottom) || (index == 0) #|| (container.overflow && widget.top < bottom) # widget.visible = (widget.bottom <= bottom) || (container.root_page.positioned_widgets[:static] == 0) #|| (container.overflow && widget.top < bottom) # # if widget.visible and widget.bottom > bottom and container.overflow # # widget.layout_widget(writer) # # end # end container_full = unaligned.last && !unaligned.last.visible container.more(true) if container_full and container.overflow # container.height(top - container.content_top + @style.vpadding, :pt) if container.height.nil? # container.height(dy + container.non_content_height, :pt) if container.height.nil? super(container, writer) end |
#preferred_height(grid, writer) ⇒ Object
343 344 345 346 347 348 349 |
# File 'lib/erml_layout_managers.rb', line 343 def preferred_height(grid, writer) cells = grid.col(0) return 0 if cells.empty? cell_heights = cells.map { |w| w.preferred_height(writer) } return nil unless cell_heights.all? cell_heights.inject((cells.size - 1) * @style.vpadding) { |sum, height| sum + height } end |
#preferred_width(grid, writer) ⇒ Object
351 352 353 354 355 356 357 |
# File 'lib/erml_layout_managers.rb', line 351 def preferred_width(grid, writer) cells = grid.col(0) return 0 if cells.empty? cell_widths = cells.map { |w| w.preferred_width(writer) } return nil unless cell_widths.all? cell_widths.max end |