diff --git a/.gitignore b/.gitignore index ea8c4bf..77147e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /target +Cargo.lock +.idea/ diff --git a/Cargo.toml b/Cargo.toml index 1a13993..3b68435 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/main.rs b/src/main.rs index e7a11a9..009c5ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 { + // 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) +} \ No newline at end of file