Skip to content
This repository was archived by the owner on May 12, 2022. It is now read-only.

Commit f843bcd

Browse files
committed
Add fake GUI elements
1 parent 65d0e44 commit f843bcd

File tree

5 files changed

+131
-9
lines changed

5 files changed

+131
-9
lines changed

stella2/meta/lib.tcwdl

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ comp crate::view::MainView {
4141
zoom = [Some(1), None][get!(&wnd_state).sidebar_visible as usize],
4242
};
4343

44+
// Sidebar
45+
// -----------------------------------------------------------------------
4446
const sidebar_view_wrap = StyledBox::new! {
4547
style_manager,
4648
class_set = elem_id::SIDEBAR,
@@ -52,6 +54,8 @@ comp crate::view::MainView {
5254
text = "sidebar: todo!".to_string(),
5355
};
5456

57+
// The main area
58+
// -----------------------------------------------------------------------
5559
const split_editor = Split::new! {
5660
style_manager,
5761
vertical = true,
@@ -61,6 +65,8 @@ comp crate::view::MainView {
6165
class_set = ClassSet::SPLITTER | ClassSet::VERTICAL | elem_id::EDITOR_SPLIT,
6266
};
6367

68+
// Chat log
69+
// -----------------------------------------------------------------------
6470
const log_view_wrap = StyledBox::new! {
6571
style_manager,
6672
class_set = elem_id::LOG_VIEW,
@@ -72,15 +78,58 @@ comp crate::view::MainView {
7278
text = "log: todo!".to_string(),
7379
};
7480

81+
// Composing area
82+
// -----------------------------------------------------------------------
7583
const editor_view_wrap = StyledBox::new! {
7684
style_manager,
7785
class_set = elem_id::EDITOR,
78-
subview_generic = get!(editor_view.view),
86+
subview_generic = get!(editor_view),
7987
};
80-
const editor_view = PlaceholderView::new! {
81-
wm,
88+
const editor_view = HView::new! {
89+
layout = TableLayout::stack_horz(
90+
[
91+
(get!(&editor_field.view), AlignFlags::JUSTIFY),
92+
(get!(&spacer1.view), AlignFlags::HORZ_JUSTIFY),
93+
(get!(&send_button.view), AlignFlags::HORZ_JUSTIFY | AlignFlags::TOP),
94+
]
95+
.iter()
96+
.map(|&(view, align)| (view.clone(), align))
97+
),
98+
};
99+
100+
const editor_field = StyledBox::new! {
101+
style_manager,
102+
view_flags = {
103+
// Make `set_cursor_shape` work
104+
use tcw3::uicore::ViewFlags;
105+
ViewFlags::default() | ViewFlags::ACCEPT_MOUSE_OVER
106+
},
107+
class_set = elem_id::EDITOR_FIELD,
108+
subview_generic = HView::new! {
109+
// Align the text to the upper-left corner
110+
layout = TableLayout::stack_horz(
111+
Some((get!(editor_placeholder.view), AlignFlags::TOP | AlignFlags::LEFT))
112+
),
113+
},
114+
};
115+
const editor_placeholder = Label::new! {
82116
style_manager,
83-
text = "editor: todo!".to_string(),
117+
text = "Message #random",
118+
};
119+
on (init) {
120+
// TODO: find a prettier way
121+
get!(&editor_field).set_subelement(
122+
tcw3::ui::theming::Role::Generic,
123+
Some(get!(editor_placeholder.style_elem))
124+
);
125+
get!(&editor_field.view).set_cursor_shape(Some(tcw3::uicore::CursorShape::Text));
126+
}
127+
128+
const spacer1 = FixedSpacer::new! { wm, size = [5.0, 0.0].into() };
129+
130+
const send_button = Button::new! {
131+
style_manager,
132+
caption = "Send",
84133
};
85134

86135
on (init) get!(&this).init();
@@ -149,10 +198,28 @@ pub(crate) comp ToolbarView {
149198
on (go_forward_button.activated) dbg!();
150199

151200
// TODO
152-
const search_bar = PlaceholderView::new! {
153-
wm,
201+
const search_bar = StyledBox::new! {
202+
style_manager,
203+
view_flags = {
204+
// Make `set_cursor_shape` work
205+
use tcw3::uicore::ViewFlags;
206+
ViewFlags::default() | ViewFlags::ACCEPT_MOUSE_OVER
207+
},
208+
class_set = elem_id::SEARCH_FIELD,
209+
subview_generic = get!(search_bar_placeholder.view),
210+
};
211+
on (init) {
212+
// TODO: find a prettier way
213+
get!(&search_bar).set_subelement(
214+
tcw3::ui::theming::Role::Generic,
215+
Some(get!(search_bar_placeholder.style_elem))
216+
);
217+
get!(&search_bar.view).set_cursor_shape(Some(tcw3::uicore::CursorShape::Text));
218+
}
219+
220+
const search_bar_placeholder = Label::new! {
154221
style_manager,
155-
text = "search: todo!".to_string(),
222+
text = "Search",
156223
};
157224
}
158225

stella2/src/stylesheet.rs

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
use cggeom::box2;
12
use cgmath::Vector2;
23
use stella2_assets as assets;
34
use stvg_tcw3::StvgImg;
45
use tcw3::{
6+
images::himg_from_rounded_rect,
57
stylesheet,
68
ui::theming::{Manager, Metrics, Role, Stylesheet},
79
};
@@ -16,24 +18,29 @@ pub mod elem_id {
1618
, SIDEBAR_SHOW
1719
, SIDEBAR_HIDE
1820

21+
, SEARCH_FIELD
22+
1923
, TOOLBAR
2024
, SIDEBAR
2125
, LOG_VIEW
2226
, EDITOR
2327
, EDITOR_SPLIT
28+
, EDITOR_FIELD
2429
}
2530
}
2631

2732
fn new_custom_stylesheet() -> impl Stylesheet {
33+
use std::f32::NAN;
34+
2835
// Import IDs (e.g., `#GO_BACK`) into the scope
2936
use self::elem_id::*;
3037

3138
const TOOLBAR_IMG_SIZE: Vector2<f32> = Vector2::new(24.0, 16.0);
3239
const TOOLBAR_IMG_METRICS: Metrics = Metrics {
33-
margin: [std::f32::NAN; 4],
40+
margin: [NAN; 4],
3441
size: TOOLBAR_IMG_SIZE,
3542
};
36-
const TOOLBAR_BTN_MIN_SIZE: Vector2<f32> = Vector2::new(30.0, 20.0);
43+
const TOOLBAR_BTN_MIN_SIZE: Vector2<f32> = Vector2::new(30.0, 22.0);
3744

3845
let himg_from_stvg = |data| StvgImg::new(data).into_himg();
3946

@@ -116,6 +123,50 @@ fn new_custom_stylesheet() -> impl Stylesheet {
116123
layer_metrics[1]: TOOLBAR_IMG_METRICS,
117124
min_size: TOOLBAR_BTN_MIN_SIZE,
118125
},
126+
127+
// Toolbar elements
128+
([#SEARCH_FIELD]) (priority = 10000) {
129+
num_layers: 2,
130+
131+
layer_img[0]: Some(
132+
himg_from_rounded_rect([0.0, 0.0, 0.0, 0.2].into(), [[3.0; 2]; 4])
133+
),
134+
layer_center[0]: box2! { point: [0.5, 0.5] },
135+
136+
layer_img[1]: Some(himg_from_stvg(assets::SEARCH)),
137+
layer_metrics[1]: Metrics {
138+
margin: [NAN, NAN, NAN, 4.0],
139+
size: [16.0, 16.0].into(),
140+
},
141+
142+
min_size: [150.0, TOOLBAR_BTN_MIN_SIZE.y].into(),
143+
144+
subview_metrics[Role::Generic]: Metrics {
145+
margin: [2.0, 2.0, 2.0, 22.0],
146+
..Default::default()
147+
},
148+
},
149+
([.LABEL] < [#SEARCH_FIELD]) (priority = 10000) {
150+
fg_color: [1.0, 1.0, 1.0, 0.6].into(),
151+
},
152+
153+
// Composing area
154+
([#EDITOR_FIELD]) (priority = 10000) {
155+
num_layers: 1,
156+
157+
layer_img[0]: Some(
158+
himg_from_rounded_rect([1.0; 4].into(), [[3.0; 2]; 4])
159+
),
160+
layer_center[0]: box2! { point: [0.5, 0.5] },
161+
162+
subview_metrics[Role::Generic]: Metrics {
163+
margin: [3.0; 4],
164+
..Default::default()
165+
},
166+
},
167+
([.LABEL] < [#EDITOR_FIELD]) (priority = 10000) {
168+
fg_color: [0.0, 0.0, 0.0, 0.4].into(),
169+
},
119170
}
120171
}
121172

stella2/src/view.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ impl WndView {
107107
hwnd.content_view()
108108
.set_layout(FillLayout::new(main_view.view().clone()));
109109

110+
hwnd.set_caption("Stella 2");
110111
hwnd.set_listener(WndViewWndListener);
111112
hwnd.set_visibility(true);
112113

stella2_assets/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ macro_rules! stvg {
99
};
1010
}
1111

12+
pub static SEARCH: Stvg = stvg!("src/search.svg");
13+
1214
pub mod toolbar {
1315
use super::*;
1416

stella2_assets/src/search.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)