Implementation of the simple druid example of crates.io
parent
6413373c1a
commit
de11ee8b38
|
@ -1 +1,3 @@
|
||||||
/target
|
/target
|
||||||
|
Cargo.lock
|
||||||
|
.idea/
|
||||||
|
|
|
@ -6,3 +6,4 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
druid = "0.7.0"
|
||||||
|
|
23
src/main.rs
23
src/main.rs
|
@ -1,3 +1,22 @@
|
||||||
fn main() {
|
use druid::widget::{Button, Flex, Label};
|
||||||
println!("Hello, world!");
|
use druid::{AppLauncher, LocalizedString, PlatformError, Widget, WidgetExt, WindowDesc};
|
||||||
|
|
||||||
|
fn main() -> Result<(), PlatformError> {
|
||||||
|
let main_window = WindowDesc::new(ui_builder);
|
||||||
|
let data = 0_u32;
|
||||||
|
AppLauncher::with_window(main_window)
|
||||||
|
.use_simple_logger()
|
||||||
|
.launch(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ui_builder() -> impl Widget<u32> {
|
||||||
|
// The label text will be computed dynamically based on the current locale and count
|
||||||
|
let text =
|
||||||
|
LocalizedString::new("hello-counter").with_arg("count", |data: &u32, _env| (*data).into());
|
||||||
|
let label = Label::new(text).padding(5.0).center();
|
||||||
|
let button = Button::new("increment")
|
||||||
|
.on_click(|_ctx, data, _env| *data += 1)
|
||||||
|
.padding(2.0);
|
||||||
|
|
||||||
|
Flex::column().with_child(label).with_child(button)
|
||||||
|
}
|
Loading…
Reference in New Issue