tuix_widgets/containers/
list.rs1#![allow(dead_code)]
2
3use crate::common::*;
4use tuix_core::CursorIcon;
5
6pub struct Row {}
7
8impl Row {
9 pub fn new() -> Self {
10 Self {}
11 }
12}
13
14impl Widget for Row {
15 type Ret = Entity;
16 type Data = ();
17 fn on_build(&mut self, state: &mut State, entity: Entity) -> Self::Ret {
18 entity
19 .set_layout_type(state, LayoutType::Row)
20 .set_focusable(state, false)
21 .set_element(state, "row")
22 }
25}
26
27pub struct Column {}
28
29impl Column {
30 pub fn new() -> Self {
31 Self {}
32 }
33}
34
35impl Widget for Column {
36 type Ret = Entity;
37 type Data = ();
38 fn on_build(&mut self, state: &mut State, entity: Entity) -> Self::Ret {
39 entity
40 .set_layout_type(state, LayoutType::Column)
41 .set_focusable(state, false)
42 .set_element(state, "column")
43 }
46}
47
48pub struct ResizableColumn {
49 resizing: bool,
50 previous_width: f32,
51}
52
53impl ResizableColumn {
54 pub fn new() -> Self {
55 Self {
56 resizing: false,
57 previous_width: 0.0,
58 }
59 }
60}
61
62impl Widget for ResizableColumn {
63 type Ret = Entity;
64 type Data = ();
65 fn on_build(&mut self, _state: &mut State, entity: Entity) -> Self::Ret {
66 entity
67 }
74
75 fn on_event(&mut self, state: &mut State, entity: Entity, event: &mut Event) {
76 if let Some(window_event) = event.message.downcast::<WindowEvent>() {
77 match window_event {
78 WindowEvent::MouseDown(button) => {
79 if *button == MouseButton::Left {
80 if state.mouse.left.pos_down.0
81 >= state.data.get_posx(entity) + state.data.get_width(entity) - 4.0
82 && state.mouse.left.pos_down.0
83 <= state.data.get_posx(entity) + state.data.get_width(entity)
84 {
85 self.resizing = true;
86 self.previous_width = state.data.get_width(entity);
87 state.capture(entity);
88 }
89 }
90 }
91
92 WindowEvent::MouseUp(button) => {
93 if *button == MouseButton::Left {
94 if self.resizing == true {
95 self.resizing = false;
97 state.insert_event(
98 Event::new(WindowEvent::MouseMove(
99 state.mouse.cursorx,
100 state.mouse.cursory,
101 ))
102 .target(entity),
103 );
104 }
105 }
106 }
107
108 WindowEvent::MouseOut => {
110 if !self.resizing {
111 state.insert_event(Event::new(WindowEvent::SetCursor(CursorIcon::Arrow)));
112 }
113 }
114
115 WindowEvent::MouseMove(x, _) => {
116 if self.resizing {
117 let distx = *x - state.mouse.left.pos_down.0;
118 entity.set_width(state, Units::Pixels(self.previous_width + distx));
119 } else {
120 if *x > state.data.get_posx(entity) + state.data.get_width(entity) - 4.0
121 && *x < state.data.get_posx(entity) + state.data.get_width(entity)
122 {
123 } else {
127 state.release(entity);
131 }
132 }
133 }
134
135 _ => {}
136 }
137 }
138 }
139}