layout/
layout.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use suzy::dims::Rect;
6use suzy::widget::{
7    WidgetChildReceiver, WidgetContent, WidgetGraphicReceiver, WidgetInit,
8};
9use suzy::widgets::{Button, TextContent};
10
11#[derive(Default)]
12struct Root {
13    one: Button,
14    two: Button,
15    three: Button,
16}
17
18impl WidgetContent for Root {
19    fn init(mut init: impl WidgetInit<Self>) {
20        init.watch(|this, _rect| {
21            this.one.content_mut().set_text("One");
22            this.two.content_mut().set_text("Two");
23            this.three.content_mut().set_text("Three");
24        });
25        init.create_layout_group()
26            .stack_right()
27            .start_at(|this| this.left())
28            .spacing(|_| 10.0)
29            .push(|this| &mut this.one)
30            .push(|this| &mut this.two)
31            .push(|this| &mut this.three);
32    }
33
34    fn children(&mut self, mut receiver: impl WidgetChildReceiver) {
35        receiver.child(&mut self.one);
36        receiver.child(&mut self.two);
37        receiver.child(&mut self.three);
38    }
39
40    fn graphics(&mut self, _receiver: impl WidgetGraphicReceiver) {
41        // no graphics
42    }
43}
44
45fn main() {
46    Root::run_as_app();
47}