-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathstack-gradient.rs
51 lines (44 loc) · 1.31 KB
/
stack-gradient.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
51
// Copyright 2022 the Druid Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT
use druid::widget::{Align, Container, Label};
use druid::{
AppLauncher, Color, Data, Lens, LinearGradient, UnitPoint, Widget, WidgetExt, WindowDesc,
};
use druid_widget_nursery::Stack;
#[derive(Clone, Default, Data, Lens)]
struct AppState {}
fn build_ui() -> impl Widget<AppState> {
let gradient = LinearGradient::new(
UnitPoint::BOTTOM,
UnitPoint::TOP,
(Color::WHITE, Color::BLACK),
);
Stack::new()
.with_child(
Container::new(Label::new(""))
.fix_width(250.)
.fix_height(250.)
.background(Color::WHITE),
)
.with_child(
Container::new(
Align::new(
UnitPoint::CENTER,
Label::new("Foreground Text").with_text_size(20.),
)
.expand(),
)
.background(gradient)
.padding(5.),
)
.fix_width(250.)
.fix_height(250.)
}
pub fn main() {
let main_window = WindowDesc::new(build_ui().center()).title("Stack Test");
let state = AppState::default();
AppLauncher::with_window(main_window)
.log_to_console()
.launch(state)
.expect("launch failed");
}