Implementation of the simple druid example of crates.io

main
p1ng0ut 2022-07-12 17:54:40 +02:00
parent 6413373c1a
commit de11ee8b38
3 changed files with 24 additions and 2 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
/target
Cargo.lock
.idea/

View File

@ -6,3 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
druid = "0.7.0"

View File

@ -1,3 +1,22 @@
fn main() {
println!("Hello, world!");
use druid::widget::{Button, Flex, Label};
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)
}