button/
button.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, SimplePadding2d};
6use suzy::widget::{
7    WidgetChildReceiver, WidgetContent, WidgetGraphicReceiver, WidgetInit,
8};
9use suzy::widgets::Button;
10
11#[derive(Default)]
12struct Root {
13    button: Button,
14}
15
16impl WidgetContent for Root {
17    fn init(mut init: impl WidgetInit<Self>) {
18        init.watch(|this, rect| {
19            this.button.set_fill(&rect, &SimplePadding2d::uniform(20.0));
20        });
21    }
22
23    fn children(&mut self, mut receiver: impl WidgetChildReceiver) {
24        receiver.child(&mut self.button);
25    }
26
27    fn graphics(&mut self, _receiver: impl WidgetGraphicReceiver) {
28        // no graphics
29    }
30}
31
32fn main() {
33    Root::run_as_app();
34}