Add toolbar binary as a testing ground
This commit is contained in:
parent
d456725e23
commit
993081419d
|
|
@ -13,7 +13,8 @@ serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
druid = { git = "https://github.com/doppioandante/druid", branch = "stylus_events_0.6.0", features = ["im"] }
|
druid = { git = "https://github.com/doppioandante/druid", branch = "v0.6.0_stiletto", features = ["im"] }
|
||||||
|
#druid = { path = "../druid/druid", features = ["im"] }
|
||||||
|
|
||||||
[dependencies.gtk]
|
[dependencies.gtk]
|
||||||
version = "0.8.1"
|
version = "0.8.1"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,85 @@
|
||||||
|
// Stiletto
|
||||||
|
// Copyright (C) 2020 Stiletto Authors
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//use log::{info, warn};
|
||||||
|
|
||||||
|
use druid::im::{vector, Vector};
|
||||||
|
use druid::widget::prelude::*;
|
||||||
|
use druid::{AppLauncher, Color, Data, LocalizedString, WindowDesc, Lens};
|
||||||
|
|
||||||
|
#[derive(Clone, Data, Lens)]
|
||||||
|
struct AppState {
|
||||||
|
numbers: Vector<u32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_ui() -> impl Widget<AppState> {
|
||||||
|
use druid::UnitPoint;
|
||||||
|
use druid::widget::{Align, Label, Button, CrossAxisAlignment, Flex, List, ListGrowDirection, WidgetExt, SizedBox};
|
||||||
|
|
||||||
|
let list_buttons = Flex::row()
|
||||||
|
.cross_axis_alignment(CrossAxisAlignment::Center)
|
||||||
|
.with_child(Button::new("Add"))
|
||||||
|
.with_child(Button::new("Remove"));
|
||||||
|
|
||||||
|
let number_list = Flex::row()
|
||||||
|
.cross_axis_alignment(CrossAxisAlignment::Center)
|
||||||
|
.with_flex_child(
|
||||||
|
List::new(|| {
|
||||||
|
SizedBox::new(
|
||||||
|
Label::new(|item: &u32, _env: &_| format!("{}", item))
|
||||||
|
.align_horizontal(UnitPoint::CENTER)
|
||||||
|
.background(Color::rgb(0.5, 0.5, 0.5))
|
||||||
|
.fix_width(100.0)
|
||||||
|
.fix_height(100.0)
|
||||||
|
)
|
||||||
|
.padding((10.0, 0.0))
|
||||||
|
})
|
||||||
|
.grow(ListGrowDirection::Right)
|
||||||
|
.lens(AppState::numbers)
|
||||||
|
, 1.0);
|
||||||
|
|
||||||
|
let toolbar = Flex::row()
|
||||||
|
.cross_axis_alignment(CrossAxisAlignment::Center)
|
||||||
|
.with_spacer(30.0)
|
||||||
|
.with_child(Align::left(list_buttons))
|
||||||
|
.with_spacer(30.0)
|
||||||
|
.with_flex_child(Align::left(number_list), 1.0);
|
||||||
|
|
||||||
|
Flex::column()
|
||||||
|
.cross_axis_alignment(CrossAxisAlignment::Center)
|
||||||
|
.with_child(
|
||||||
|
SizedBox::new(toolbar)
|
||||||
|
.height(100.0)
|
||||||
|
.expand_width()
|
||||||
|
.align_horizontal(UnitPoint::TOP)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
let window = WindowDesc::new(build_ui)
|
||||||
|
.window_size((1000.0, 400.00))
|
||||||
|
.title(
|
||||||
|
LocalizedString::new("custom-widget-demo-window-title").with_placeholder("Tools"),
|
||||||
|
);
|
||||||
|
let app_state = AppState {
|
||||||
|
numbers: vector![1,2],
|
||||||
|
};
|
||||||
|
|
||||||
|
AppLauncher::with_window(window)
|
||||||
|
.use_simple_logger()
|
||||||
|
.launch(app_state)
|
||||||
|
.expect("launch failed");
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue