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
use crate::{EventCtx, GfxCtx, ScreenDims, ScreenPt, Widget, WidgetImpl, WidgetOutput};
pub struct Filler {
top_left: ScreenPt,
dims: ScreenDims,
square_width_pct: f64,
}
impl Filler {
pub fn square_width(ctx: &EventCtx, pct_width: f64) -> Widget {
Widget::new(Box::new(Filler {
dims: ScreenDims::new(
pct_width * ctx.canvas.window_width,
pct_width * ctx.canvas.window_width,
),
top_left: ScreenPt::new(0.0, 0.0),
square_width_pct: pct_width,
}))
}
}
impl WidgetImpl for Filler {
fn get_dims(&self) -> ScreenDims {
self.dims
}
fn set_pos(&mut self, top_left: ScreenPt) {
self.top_left = top_left;
}
fn event(&mut self, ctx: &mut EventCtx, _: &mut WidgetOutput) {
if ctx.input.is_window_resized() {
self.dims = ScreenDims::new(
self.square_width_pct * ctx.canvas.window_width,
self.square_width_pct * ctx.canvas.window_width,
);
}
}
fn draw(&self, _g: &mut GfxCtx) {}
}