Macro pixels_graphics_lib::layout
source · macro_rules! layout { ($context:expr, $view:expr, left_to_left_of $pivot:expr $(, $offset:expr)?) => { ... }; ($context:expr, $view:expr, left_to_right_of $pivot:expr $(, $offset:expr)?) => { ... }; ($context:expr, $view:expr, right_to_left_of $pivot:expr $(, $offset:expr)?) => { ... }; ($context:expr, $view:expr, top_to_bottom_of $pivot:expr $(, $offset:expr)?) => { ... }; ($context:expr, $view:expr, bottom_to_top_of $pivot:expr $(, $offset:expr)?) => { ... }; ($context:expr, $view:expr, top_to_top_of $pivot:expr $(, $offset:expr)?) => { ... }; ($context:expr, $view:expr, bottom_to_bottom_of $pivot:expr $(, $offset:expr)?) => { ... }; ($context:expr, $view:expr, right_to_right_of $pivot:expr $(, $offset:expr)?) => { ... }; ($context:expr, grow $view:expr, right_to_right_of $pivot:expr $(, $offset:expr)?) => { ... }; ($context:expr, grow $view:expr, right_to_left_of $pivot:expr $(, $offset:expr)?) => { ... }; ($context:expr, grow $view:expr, bottom_to_bottom_of $pivot:expr $(, $offset:expr)?) => { ... }; ($context:expr, grow $view:expr, bottom_to_top_of $pivot:expr $(, $offset:expr)?) => { ... }; ($context:expr, grow $view:expr, left_to_left_of $pivot:expr $(, $offset:expr)?) => { ... }; ($context:expr, grow $view:expr, left_to_right_of $pivot:expr $(, $offset:expr)?) => { ... }; ($context:expr, grow $view:expr, top_to_top_of $pivot:expr $(, $offset:expr)?) => { ... }; ($context:expr, grow $view:expr, top_to_bottom_of $pivot:expr $(, $offset:expr)?) => { ... }; ($context:expr, grow $view:expr, fill_width $(, $offset:expr)?) => { ... }; ($context:expr, grow $view:expr, fill_height $(, $offset:expr)?) => { ... }; ($context:expr, grow $view:expr, align_left $(, $offset:expr)?) => { ... }; ($context:expr, grow $view:expr, align_top $(, $offset:expr)?) => { ... }; ($context:expr, grow $view:expr, align_right $(, $offset:expr)?) => { ... }; ($context:expr, grow $view:expr, align_bottom $(, $offset:expr)?) => { ... }; ($context:expr, $view:expr, align_left $(, $offset:expr)?) => { ... }; ($context:expr, $view:expr, align_top $(, $offset:expr)?) => { ... }; ($context:expr, $view:expr, align_right $(, $offset:expr)?) => { ... }; ($context:expr, $view:expr, align_bottom $(, $offset:expr)?) => { ... }; }
Expand description
Position and size a view relative to the parent or another view
§Format
layout!(context, [command] view, alignment [pivot_view][, offset]);
Views must impl UiElement and to use grow
they must also impl LayoutView
offset
replaces the default offset from context
§Usage
ⓘ
let mut view1 = Button::new(...);
let mut view2 = Button::new(...);
let context = LayoutContext::new(Rect::new((0,0), (200,200)));
layout!(context, view1, left_to_left_of view2);
§Examples
Move a button below another with some spacing
ⓘ
let button1 = Button::new(...);
let button2 = Button::new(...);
let context = LayoutContext::new(...);
layout!(context, button2, top_to_bottom_of button1, px(8));
Move a button to the edge of the screen and grow it’s right side to match another view
ⓘ
let button1 = Button::new(...);
let button2 = Button::new(...);
let context = LayoutContext::new(...);
layout!(context, button2, align_left);
layout!(context, grow button1, right_to_right_of button1);
§Command
grow
- Moves the edge of the view, but not the position
§Alignment
View
left_to_left_of
- Makes view.x = pivot_view.xtop_to_top_of
- Makes view.y = pivot_view.yright_to_right_of
- Makes view.x = pivot_view.x + pivot_view.width - view.widthbottom_to_bottom_of
- Makes view.y = pivot_view.y + pivot_view.height - view.heightleft_to_right_of
- Makes view.x = pivot_view.x + pivot_view.widthright_to_left_of
- Makes view.x = pivot_view.x - view.widthtop_to_bottom_of
- Makes view.y = pivot_view.y + pivot_view.heightbottom_to_top_of
- Makes view.y = pivot_view.y - view.height
Parent
fill_width
- Set x to context.bounds.left, width to context.bounds.width (grow
only)fill_height
- Set y to context.bounds.top, height to context.bounds.height (grow
only)align_left
- Set x to context.bounds.leftalign_right
- Set x to (context.bounds.right - view.width)align_top
- Set y to context.bounds.topalign_bottom
- Set y to (context.bounds.bottom - view.height)