-
Notifications
You must be signed in to change notification settings - Fork 234
Expand file tree
/
Copy pathdemo.rs
More file actions
73 lines (61 loc) · 2.11 KB
/
Copy pathdemo.rs
File metadata and controls
73 lines (61 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2026 the Xilem Authors
// SPDX-License-Identifier: Apache-2.0
use masonry::app::{AppCtx, RenderRoot};
use masonry::core::{ErasedAction, Handled, NewWidget, Widget, WidgetId, WidgetTag};
use masonry::layout::Length;
use masonry::properties::types::CrossAxisAlignment;
use masonry::widgets::{Button, Checkbox, Flex, SizedBox};
pub(crate) const CONTENT_GAP: Length = Length::const_px(10.0);
pub(crate) const SIDEBAR_GAP: Length = Length::const_px(2.0);
#[derive(Clone, Copy)]
pub(crate) struct ShellTags {
pub disabled_toggle: WidgetTag<Checkbox>,
pub content_wrapper: WidgetTag<SizedBox>,
}
pub(crate) trait DemoPage {
fn name(&self) -> &'static str;
fn shell_tags(&self) -> ShellTags;
fn build(&self) -> NewWidget<dyn Widget>;
fn on_selected(&mut self, _app_ctx: &mut AppCtx, _render_root: &mut RenderRoot) {}
fn on_action(
&mut self,
app_ctx: &mut AppCtx,
render_root: &mut RenderRoot,
action: &ErasedAction,
widget_id: WidgetId,
) -> Handled {
#![expect(unused_variables, reason = "Default impl")]
Handled::No
}
}
pub(crate) fn wrap_in_shell(
shell: ShellTags,
body: NewWidget<dyn Widget>,
) -> NewWidget<dyn Widget> {
let disabled_toggle =
NewWidget::new(Checkbox::new(false, "Disabled")).with_tag(shell.disabled_toggle);
let header = Flex::row()
.cross_axis_alignment(CrossAxisAlignment::Center)
.with_fixed(disabled_toggle);
let content = NewWidget::new(SizedBox::new(body)).with_tag(shell.content_wrapper);
NewWidget::new(
Flex::column()
.cross_axis_alignment(CrossAxisAlignment::Stretch)
.with_fixed(header.prepare())
.with_fixed_spacer(CONTENT_GAP)
.with(content, 1.0),
)
.erased()
}
pub(crate) fn new_demo_shell_tags() -> ShellTags {
ShellTags {
disabled_toggle: WidgetTag::unique(),
content_wrapper: WidgetTag::unique(),
}
}
pub(crate) fn build_sidebar_button(
tag: WidgetTag<Button>,
name: &'static str,
) -> NewWidget<Button> {
NewWidget::new(Button::with_text(name)).with_tag(tag)
}