layout.cr v0.2.0
layout
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
Installation
- Add the dependency to your
shard.yml
:
dependencies:
layout:
github: da1nerd/layout.cr
- Run
shards install
Usage
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.
Development
TODO: Write development instructions here
Contributing
- 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
Contributors
- Joel - creator and maintainer
Repository
layout.cr
Owner
Statistic
- 4
- 0
- 0
- 1
- 1
- almost 4 years ago
- October 6, 2020
License
MIT License
Links
Synced at
Thu, 07 Nov 2024 07:00:44 GMT
Languages