init
This commit is contained in:
commit
728b98d29c
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
45
.vscode/launch.json
vendored
Normal file
45
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug executable 'gui'",
|
||||
"cargo": {
|
||||
"args": [
|
||||
"build",
|
||||
"--bin=gui",
|
||||
"--package=gui"
|
||||
],
|
||||
"filter": {
|
||||
"name": "gui",
|
||||
"kind": "bin"
|
||||
}
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug unit tests in executable 'gui'",
|
||||
"cargo": {
|
||||
"args": [
|
||||
"test",
|
||||
"--no-run",
|
||||
"--bin=gui",
|
||||
"--package=gui"
|
||||
],
|
||||
"filter": {
|
||||
"name": "gui",
|
||||
"kind": "bin"
|
||||
}
|
||||
},
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}"
|
||||
}
|
||||
]
|
||||
}
|
1529
Cargo.lock
generated
Normal file
1529
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
9
Cargo.toml
Normal file
9
Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "gui"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
druid = "0.7.0"
|
72
src/main.rs
Normal file
72
src/main.rs
Normal file
@ -0,0 +1,72 @@
|
||||
// Copyright 2019 The Druid Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use druid::widget::{Button, Flex, Label};
|
||||
use druid::{
|
||||
AppLauncher, Data, Env, FontDescriptor, FontFamily, Lens, LocalizedString, UnitPoint, Widget,
|
||||
WidgetExt, WindowDesc,
|
||||
};
|
||||
|
||||
const VERTICAL_WIDGET_SPACING: f64 = 20.0;
|
||||
const WINDOW_TITLE: LocalizedString<HelloState> = LocalizedString::new("Hello World!");
|
||||
|
||||
#[derive(Clone, Data, Lens)]
|
||||
struct HelloState {
|
||||
value: u8,
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
// describe the main window
|
||||
let main_window = WindowDesc::new(build_root_widget)
|
||||
.title(WINDOW_TITLE)
|
||||
.window_size((400.0, 400.0));
|
||||
|
||||
// create the initial app state
|
||||
let initial_state = HelloState {
|
||||
value: 0,
|
||||
};
|
||||
|
||||
// start the application
|
||||
AppLauncher::with_window(main_window)
|
||||
.launch(initial_state)
|
||||
.expect("Failed to launch application");
|
||||
}
|
||||
|
||||
fn build_root_widget() -> impl Widget<HelloState> {
|
||||
// a label that will determine its text based on the current app data.
|
||||
let label = Label::new(|data: &HelloState, _env: &Env| {
|
||||
format!("{} %", data.value)
|
||||
})
|
||||
.with_font(FontDescriptor::new(FontFamily::SERIF).with_size(32.0))
|
||||
.align_horizontal(UnitPoint::CENTER);
|
||||
|
||||
let button_inc = Button::new("inc")
|
||||
.on_click(|_ctx, data: &mut HelloState, _env| data.value += 1)
|
||||
.padding(5.0);
|
||||
|
||||
let button_dec = Button::new("dec")
|
||||
.on_click(|_ctx, data: &mut HelloState, _env| data.value -= 1)
|
||||
.padding(5.0);
|
||||
|
||||
let inc_dec_row = Flex::row()
|
||||
.with_child(button_inc)
|
||||
.with_child(button_dec)
|
||||
.align_horizontal(UnitPoint::CENTER);
|
||||
|
||||
Flex::column()
|
||||
.with_child(label)
|
||||
.with_spacer(VERTICAL_WIDGET_SPACING)
|
||||
.with_child(inc_dec_row)
|
||||
.align_vertical(UnitPoint::CENTER)
|
||||
}
|
Loading…
Reference in New Issue
Block a user