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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// SPDX-FileCopyrightText: Copyright (c) 2026 Mike Li/Mikewolfli/Wei Li(mikewolfli@163.com)
// SPDX-License-Identifier: MIT
macro_rules! impl_base_widgets {
() => {
fn backend_name(&self) -> &'static str {
"custom-paint-control-backend"
}
fn kind(&self) -> ControlBackendKind {
ControlBackendKind::Custom
}
fn create_window(&self, title: &str, x: i32, y: i32, width: u32, height: u32) -> ObjectId {
let id = self.mount_widget_of_kind(WidgetKind::Window, 0, title, x, y, width, height);
if id != 0 {
// A widget id is *reusable*: `widget::runtime` counts ids per thread from a
// fixed start, so a window created after another was dropped (or created by a
// different, earlier test on the same thread) can be handed the same id. The
// recorded client size is keyed by id, so without this the new window would
// answer `window_client_size` with the *previous* window's size — a stale
// value that beats the correct geometry fallback and lays the new window's
// children out at the wrong size.
//
// Clearing on creation makes "was this window resized?" a property of the
// window rather than of the integer that names it.
lock(&self.state)
.window_client_sizes
.remove(&id);
}
id
}
fn create_button(
&self,
parent: ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> ObjectId {
self.mount_widget_of_kind(WidgetKind::Button, parent, text, x, y, width, height)
}
fn create_checkbox(
&self,
parent: ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> ObjectId {
self.mount_widget_of_kind(WidgetKind::CheckBox, parent, text, x, y, width, height)
}
fn create_label(
&self,
parent: ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> ObjectId {
self.mount_widget_of_kind(WidgetKind::Label, parent, text, x, y, width, height)
}
fn create_radio_button(
&self,
parent: ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> ObjectId {
self.mount_widget_of_kind(WidgetKind::RadioButton, parent, text, x, y, width, height)
}
fn create_panel(
&self,
parent: ObjectId,
x: i32,
y: i32,
width: u32,
height: u32,
) -> ObjectId {
// By name: `WidgetKind::Panel` is shared with `breadcrumb`, and the kind
// lookup answers with whichever of the two is registered first — which was
// the breadcrumb, so `create_panel` built a navigation trail.
//
// `mount_named_widget` is compiled only where the factory is
// (`full_widgets`). Every other profile has no constructors at all and
// reports `0` from either path, so it keeps the kind-based call rather than
// referring to a helper it does not compile.
#[cfg(full_widgets)]
{
self.mount_named_widget("panel", parent, "", x, y, width, height)
}
#[cfg(not(full_widgets))]
{
self.mount_widget_of_kind(WidgetKind::Panel, parent, "", x, y, width, height)
}
}
fn create_group_box(
&self,
parent: ObjectId,
title: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> ObjectId {
self.mount_widget_of_kind(WidgetKind::GroupBox, parent, title, x, y, width, height)
}
fn create_toggle_button(
&self,
parent: ObjectId,
text: &str,
x: i32,
y: i32,
width: u32,
height: u32,
) -> ObjectId {
self.mount_widget_of_kind(
crate::control_backend::custom::TOGGLE_BUTTON_KIND,
parent,
text,
x,
y,
width,
height,
)
}
};
}