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
use kas::class::*;
use kas::prelude::*;
#[handler(msg = <W as Handler>::Msg)]
#[derive(Clone, Debug, Default, Widget)]
pub struct Frame<W: Widget> {
#[widget_core]
core: CoreData,
#[widget]
child: W,
m0: Size,
m1: Size,
}
impl<W: Widget> Frame<W> {
#[inline]
pub fn new(child: W) -> Self {
Frame {
core: Default::default(),
child,
m0: Size::ZERO,
m1: Size::ZERO,
}
}
}
impl<W: Widget> Layout for Frame<W> {
fn size_rules(&mut self, size_handle: &mut dyn SizeHandle, axis: AxisInfo) -> SizeRules {
let size = size_handle.frame();
let margins = Margins::ZERO;
let frame_rules = SizeRules::extract_fixed(axis.is_vertical(), size + size, margins);
let child_rules = self.child.size_rules(size_handle, axis);
let m = child_rules.margins();
if axis.is_horizontal() {
self.m0.0 = size.0 + m.0 as u32;
self.m1.0 = size.0 + m.1 as u32;
} else {
self.m0.1 = size.1 + m.0 as u32;
self.m1.1 = size.1 + m.1 as u32;
}
child_rules.surrounded_by(frame_rules, true)
}
fn set_rect(&mut self, mut rect: Rect, align: AlignHints) {
self.core.rect = rect;
rect.pos += self.m0;
rect.size -= self.m0 + self.m1;
self.child.set_rect(rect, align);
}
#[inline]
fn find_id(&self, coord: Coord) -> Option<WidgetId> {
if !self.rect().contains(coord) {
return None;
}
self.child.find_id(coord).or(Some(self.id()))
}
fn draw(&self, draw_handle: &mut dyn DrawHandle, mgr: &event::ManagerState, disabled: bool) {
draw_handle.outer_frame(self.core_data().rect);
let disabled = disabled || self.is_disabled();
self.child.draw(draw_handle, mgr, disabled);
}
}
impl<W: HasBool + Widget> HasBool for Frame<W> {
fn get_bool(&self) -> bool {
self.child.get_bool()
}
fn set_bool(&mut self, state: bool) -> TkAction {
self.child.set_bool(state)
}
}
impl<W: HasText + Widget> HasText for Frame<W> {
fn get_text(&self) -> &str {
self.child.get_text()
}
fn set_cow_string(&mut self, text: CowString) -> TkAction {
self.child.set_cow_string(text)
}
}
impl<W: Editable + Widget> Editable for Frame<W> {
fn is_editable(&self) -> bool {
self.child.is_editable()
}
fn set_editable(&mut self, editable: bool) {
self.child.set_editable(editable);
}
}