-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathsplits.rs
50 lines (43 loc) · 1.51 KB
/
splits.rs
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
// Copyright 2021 the Druid Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT
use druid::im::Vector;
use druid::widget::{Container, Flex, Label, Scroll, WidgetExt};
use druid::{AppLauncher, Data, Env, Lens, Widget, WindowDesc};
use druid_widget_nursery::splits::Splits;
#[derive(Data, Clone, Lens)]
struct AppState {
collection: Vector<String>,
}
fn main_widget() -> impl Widget<AppState> {
Flex::column()
.main_axis_alignment(druid::widget::MainAxisAlignment::Start)
.cross_axis_alignment(druid::widget::CrossAxisAlignment::Start)
.with_child(Container::new(
Scroll::new(
Splits::new(|| {
Label::new(|text: &String, _: &Env| format!("Collection: {text}"))
.fix_height(120.)
})
.horizontal()
.min_size(180.)
.draggable(true)
.bar_size(6.),
)
.horizontal()
.lens(AppState::collection),
))
}
pub fn main() {
let main_window = WindowDesc::new(main_widget())
.title("Dropdown")
.window_size((500., 140.));
let mut collection = Vector::new();
collection.push_back("Column 1".to_string());
collection.push_back("Column 2".to_string());
collection.push_back("Column 3".to_string());
let initial_state = AppState { collection };
AppLauncher::with_window(main_window)
.log_to_console()
.launch(initial_state)
.expect("Failed to launch application");
}