feat: add durid
This commit is contained in:
1519
__gui/druid/Cargo.lock
generated
Normal file
1519
__gui/druid/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
11
__gui/druid/Cargo.toml
Normal file
11
__gui/druid/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "druid"
|
||||
version = "0.1.0"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
druid = "0.7.0"
|
||||
|
||||
52
__gui/druid/src/main.rs
Normal file
52
__gui/druid/src/main.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use druid::widget::{Button, Flex, Label};
|
||||
use druid::{AppLauncher, LocalizedString, PlatformError, Widget, WidgetExt, WindowDesc, Data, Point};
|
||||
|
||||
#[derive(Clone, Data)]
|
||||
struct Counter(i32);
|
||||
|
||||
fn main() -> Result<(), PlatformError> {
|
||||
// let menu = MenuDesc::new(LocalizedString::new("test"));
|
||||
|
||||
// Window builder. We set title and size
|
||||
let main_window = WindowDesc::new(ui_builder)
|
||||
.title("Hello, Druid!")
|
||||
.window_size((600.0, 400.0))
|
||||
// .menu(menu)
|
||||
.set_position(Point::new(300.0, 200.0));
|
||||
|
||||
// Data to be used in the app (=state)
|
||||
let data: Counter = Counter(0);
|
||||
|
||||
// Run the app
|
||||
AppLauncher::with_window(main_window)
|
||||
.use_simple_logger() // Neat!
|
||||
.launch(data)
|
||||
}
|
||||
|
||||
fn ui_builder() -> impl Widget<Counter> {
|
||||
// The label text will be computed dynamically based on the current locale and count
|
||||
let text = LocalizedString::new("hello-counter")
|
||||
.with_arg("count", |data: &Counter, _env| (*data).0.into());
|
||||
let label = Label::new(text).padding(5.0).center();
|
||||
|
||||
// Two buttons with on_click callback
|
||||
let button_plus = Button::new("+1")
|
||||
.fix_size(80.0, 30.0)
|
||||
.on_click(|_ctx, data: &mut Counter, _env| (*data).0 += 1)
|
||||
.padding(5.0);
|
||||
let button_minus = Button::new("-1")
|
||||
.fix_size(80.0, 30.0)
|
||||
.on_click(|_ctx, data: &mut Counter, _env| (*data).0 -= 1)
|
||||
.padding(5.0);
|
||||
|
||||
// Container for the two buttons
|
||||
let flex = Flex::row()
|
||||
.with_child(button_plus)
|
||||
.with_spacer(1.0)
|
||||
.with_child(button_minus);
|
||||
|
||||
// Container for the whole UI
|
||||
Flex::column()
|
||||
.with_child(label)
|
||||
.with_child(flex)
|
||||
}
|
||||
Reference in New Issue
Block a user