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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
use crate::*;
pub struct SidePanel {
id: Id,
max_width: f32,
}
impl SidePanel {
pub fn left(id_source: impl std::hash::Hash, max_width: f32) -> Self {
Self {
id: Id::new(id_source),
max_width,
}
}
}
impl SidePanel {
pub fn show<R>(
self,
ctx: &CtxRef,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<R> {
let Self { id, max_width } = self;
let mut panel_rect = ctx.available_rect();
panel_rect.max.x = panel_rect.max.x.at_most(panel_rect.min.x + max_width);
let layer_id = LayerId::background();
let clip_rect = ctx.input().screen_rect();
let mut panel_ui = Ui::new(ctx.clone(), layer_id, id, panel_rect, clip_rect);
let frame = Frame::side_top_panel(&ctx.style());
let (r, used_space) = frame.show(&mut panel_ui, |ui| {
let r = add_contents(ui);
let used_space = ui.min_rect();
ui.set_min_height(ui.max_rect_finite().height());
(r, used_space)
});
let panel_rect = panel_ui.min_rect();
let response = panel_ui.interact(panel_rect, id, Sense::hover());
ctx.frame_state()
.allocate_left_panel(used_space.expand2(frame.margin));
InnerResponse::new(r, response)
}
}
pub struct TopPanel {
id: Id,
max_height: Option<f32>,
}
impl TopPanel {
pub fn top(id_source: impl std::hash::Hash) -> Self {
Self {
id: Id::new(id_source),
max_height: None,
}
}
}
impl TopPanel {
pub fn show<R>(
self,
ctx: &CtxRef,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<R> {
let Self { id, max_height } = self;
let max_height = max_height.unwrap_or_else(|| ctx.style().spacing.interact_size.y);
let mut panel_rect = ctx.available_rect();
panel_rect.max.y = panel_rect.max.y.at_most(panel_rect.min.y + max_height);
let layer_id = LayerId::background();
let clip_rect = ctx.input().screen_rect();
let mut panel_ui = Ui::new(ctx.clone(), layer_id, id, panel_rect, clip_rect);
let frame = Frame::side_top_panel(&ctx.style());
let (r, used_space) = frame.show(&mut panel_ui, |ui| {
let r = add_contents(ui);
let used_space = ui.min_rect();
ui.set_min_width(ui.max_rect_finite().width());
(r, used_space)
});
let panel_rect = panel_ui.min_rect();
let response = panel_ui.interact(panel_rect, id, Sense::hover());
ctx.frame_state()
.allocate_top_panel(used_space.expand2(frame.margin));
InnerResponse::new(r, response)
}
}
#[derive(Default)]
pub struct CentralPanel {
frame: Option<Frame>,
}
impl CentralPanel {
pub fn frame(mut self, frame: Frame) -> Self {
self.frame = Some(frame);
self
}
}
impl CentralPanel {
pub fn show<R>(
self,
ctx: &CtxRef,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> InnerResponse<R> {
let Self { frame } = self;
let panel_rect = ctx.available_rect();
let layer_id = LayerId::background();
let id = Id::new("central_panel");
let clip_rect = ctx.input().screen_rect();
let mut panel_ui = Ui::new(ctx.clone(), layer_id, id, panel_rect, clip_rect);
let frame = frame.unwrap_or_else(|| Frame::central_panel(&ctx.style()));
let (r, used_space) = frame.show(&mut panel_ui, |ui| {
let r = add_contents(ui);
let used_space = ui.min_rect();
ui.expand_to_include_rect(ui.max_rect());
(r, used_space)
});
let panel_rect = panel_ui.min_rect();
let id = Id::new("central_panel");
let response = panel_ui.interact(panel_rect, id, Sense::hover());
ctx.frame_state()
.allocate_central_panel(used_space.expand2(frame.margin));
InnerResponse::new(r, response)
}
}