This is a constraint based layout framework. Or more simply put, this generates the measurements for a visual layout which could then be used for:
- Positioning things on a PDF
- Drawing objects in a UI toolkit
- Add the dependency to your
shard.yml
:
dependencies:
layout:
github: da1nerd/layout.cr
- Run
shards install
require "layout"
screen = Layout::Block.new
screen.width.eq 300
screen.height.eq 300
top_block = Layout::Block.new
top_block.height.eq 100
top_block.width.eq screen.width
bottom_block = Layout::Block.new
bottom_block.top.eq top_block.bottom
bottom_block.width.eq screen.width
bottom_block.bottom.eq screen.bottom
screen.children = [top_block, bottom_block]
Layout.solve(screen)
# go use the calculated dimensions!
bottom_block.height.value # => 200
With the above code you'd have all the necessary dimensions to draw this stack of blocks.
Note: there's nothing special about
screen.children = [top_block, bottom_block]
This simply combines the blocks into a single one so we can easily pass it to the solver.
TODO: Write development instructions here
- Fork it (https://github.com/da1nerd/layout.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Joel - creator and maintainer