Compare commits
4 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
481db6b96f | |
|
|
2d961a6e9c | |
|
|
9369c3113d | |
|
|
993081419d |
|
|
@ -257,7 +257,7 @@ checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "druid"
|
name = "druid"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
source = "git+https://github.com/doppioandante/druid?branch=stylus_events_0.6.0#b0f9dc0268409a56b5066f569ad245e5df016166"
|
source = "git+https://github.com/doppioandante/druid?branch=v0.6.0_stiletto#f8f8a566b77795cfa10caf7f2861f9240d159e90"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"console_log",
|
"console_log",
|
||||||
"druid-derive",
|
"druid-derive",
|
||||||
|
|
@ -278,7 +278,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "druid-derive"
|
name = "druid-derive"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
source = "git+https://github.com/doppioandante/druid?branch=stylus_events_0.6.0#b0f9dc0268409a56b5066f569ad245e5df016166"
|
source = "git+https://github.com/doppioandante/druid?branch=v0.6.0_stiletto#f8f8a566b77795cfa10caf7f2861f9240d159e90"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
@ -288,7 +288,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "druid-shell"
|
name = "druid-shell"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
source = "git+https://github.com/doppioandante/druid?branch=stylus_events_0.6.0#b0f9dc0268409a56b5066f569ad245e5df016166"
|
source = "git+https://github.com/doppioandante/druid?branch=v0.6.0_stiletto#f8f8a566b77795cfa10caf7f2861f9240d159e90"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
|
|
|
||||||
|
|
@ -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,122 @@
|
||||||
|
// 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::widget::{Align, Label, Button, CrossAxisAlignment, Flex, List, ListGrowDirection, WidgetExt, SizedBox, ViewSwitcher};
|
||||||
|
use druid::{AppLauncher, Color, Data, LocalizedString, WindowDesc, Lens, UnitPoint};
|
||||||
|
|
||||||
|
#[derive(Clone, Data)]
|
||||||
|
enum CanvasToolState {
|
||||||
|
Pen { thickness: f64, color: Color },
|
||||||
|
Eraser,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq)]
|
||||||
|
enum CanvasToolType {
|
||||||
|
Pen,
|
||||||
|
Eraser,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CanvasToolState {
|
||||||
|
fn tool_type(&self) -> CanvasToolType {
|
||||||
|
match self {
|
||||||
|
CanvasToolState::Pen { .. } => CanvasToolType::Pen,
|
||||||
|
CanvasToolState::Eraser => CanvasToolType::Eraser,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_simple_tool_widget(tool_state: &CanvasToolState) -> Box<dyn Widget<CanvasToolState>> {
|
||||||
|
let (label_text, bg_color) = match tool_state {
|
||||||
|
CanvasToolState::Pen { thickness, color } =>
|
||||||
|
(format!("pen {}", thickness), color.clone()),
|
||||||
|
CanvasToolState::Eraser =>
|
||||||
|
(String::from("eraser"), Color::rgb(200, 200, 200))
|
||||||
|
};
|
||||||
|
|
||||||
|
Box::new(
|
||||||
|
SizedBox::new(
|
||||||
|
Label::new(label_text)
|
||||||
|
.align_horizontal(UnitPoint::CENTER)
|
||||||
|
.background(bg_color)
|
||||||
|
.fix_width(100.0)
|
||||||
|
.fix_height(100.0)
|
||||||
|
)
|
||||||
|
.padding((10.0, 0.0)))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Clone, Data, Lens)]
|
||||||
|
struct AppState {
|
||||||
|
tools: Vector<CanvasToolState>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_ui() -> impl Widget<AppState> {
|
||||||
|
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(|| {
|
||||||
|
ViewSwitcher::<CanvasToolState, CanvasToolType>::new(
|
||||||
|
|tool_state, _| tool_state.tool_type(),
|
||||||
|
|_, tool_state, _| {
|
||||||
|
build_simple_tool_widget(&tool_state)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.grow(ListGrowDirection::Right)
|
||||||
|
.lens(AppState::tools)
|
||||||
|
, 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 {
|
||||||
|
tools: vector![CanvasToolState::Eraser, CanvasToolState::Pen { thickness: 3.3, color: Color::rgb(30.0, 0.4, 0.4) }]
|
||||||
|
};
|
||||||
|
|
||||||
|
AppLauncher::with_window(window)
|
||||||
|
.use_simple_logger()
|
||||||
|
.launch(app_state)
|
||||||
|
.expect("launch failed");
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue