From 993081419d0dc901cdb4d2b6cc7415294c8cc162 Mon Sep 17 00:00:00 2001 From: Enrico Lumetti Date: Fri, 13 Nov 2020 19:25:03 +0100 Subject: [PATCH] Add toolbar binary as a testing ground --- Cargo.toml | 3 +- src/bin/canvas_tool_list.rs | 85 +++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 src/bin/canvas_tool_list.rs diff --git a/Cargo.toml b/Cargo.toml index dc2905d..fa7de17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,8 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" [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] version = "0.8.1" diff --git a/src/bin/canvas_tool_list.rs b/src/bin/canvas_tool_list.rs new file mode 100644 index 0000000..977e8e1 --- /dev/null +++ b/src/bin/canvas_tool_list.rs @@ -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 . + +//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, +} + +fn build_ui() -> impl Widget { + 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"); +}