parent
827d8d6a1c
commit
56ed3b7c01
File diff suppressed because it is too large
Load Diff
11
Cargo.toml
11
Cargo.toml
|
|
@ -6,23 +6,24 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
log = "0.4"
|
||||
druid = { version = "0.6.0", features = ["im", "svg"] }
|
||||
druid = { version = "0.7.0", features = ["im", "svg"] }
|
||||
im = { version = "*" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
#serde_bare = "0.3.0"
|
||||
serde_json = "1.0"
|
||||
|
||||
[patch.crates-io]
|
||||
druid = { git = "https://github.com/doppioandante/druid", branch = "v0.6.0_stiletto", features = ["im", "svg"] }
|
||||
druid = { git = "https://github.com/doppioandante/druid", branch = "v0.7.0_stiletto", features = ["im", "svg"] }
|
||||
#druid = { path = "../druid/druid/", features = ["im", "svg"] }
|
||||
|
||||
[dependencies.gtk]
|
||||
version = "0.8.1"
|
||||
version = "0.9.2"
|
||||
features = ["v3_22"]
|
||||
|
||||
[dependencies.gio]
|
||||
version = "0.8.1"
|
||||
version = "0.9.1"
|
||||
features = ["v2_56"]
|
||||
|
||||
[dependencies.gdk]
|
||||
version = "0.12.1"
|
||||
version = "0.13.2"
|
||||
features = ["v3_22"]
|
||||
|
|
|
|||
48
src/main.rs
48
src/main.rs
|
|
@ -19,12 +19,10 @@ use log::{info, warn};
|
|||
use druid::commands;
|
||||
use druid::im::vector;
|
||||
use druid::widget::prelude::*;
|
||||
use druid::widget::{
|
||||
Align, Button, CrossAxisAlignment, Flex, List, ListGrowDirection, SizedBox, WidgetExt,
|
||||
};
|
||||
use druid::widget::{Align, Button, CrossAxisAlignment, Flex, List, SizedBox, WidgetExt};
|
||||
use druid::{
|
||||
AppDelegate, AppLauncher, Color, Command, Data, DelegateCtx, Env, FileDialogOptions, FileSpec,
|
||||
Lens, LocalizedString, Target, WindowDesc,
|
||||
Handled, Lens, LocalizedString, Target, WindowDesc,
|
||||
};
|
||||
|
||||
use im::Vector;
|
||||
|
|
@ -44,11 +42,11 @@ pub fn main() {
|
|||
|
||||
let default_pen_params = CanvasToolParams::Pen {
|
||||
thickness: 2.0,
|
||||
color: Color::rgb(0, 0, 0),
|
||||
color: Color::rgb(0.0, 0.0, 0.0),
|
||||
};
|
||||
let default_pen_params_2 = CanvasToolParams::Pen {
|
||||
thickness: 2.0,
|
||||
color: Color::rgb(255, 0, 0),
|
||||
color: Color::rgb(255.0, 0.0, 0.0),
|
||||
};
|
||||
let canvas_data = StilettoState {
|
||||
canvas: CanvasState {
|
||||
|
|
@ -106,22 +104,18 @@ fn build_ui() -> impl Widget<StilettoState> {
|
|||
let save_buttons = Flex::row()
|
||||
.cross_axis_alignment(CrossAxisAlignment::Center)
|
||||
.with_child(Button::new("Open").on_click(move |ctx, _, _| {
|
||||
ctx.submit_command(
|
||||
Command::new(
|
||||
druid::commands::SHOW_OPEN_PANEL,
|
||||
open_dialog_options.clone(),
|
||||
),
|
||||
None,
|
||||
)
|
||||
ctx.submit_command(Command::new(
|
||||
druid::commands::SHOW_OPEN_PANEL,
|
||||
open_dialog_options.clone(),
|
||||
Target::Auto,
|
||||
))
|
||||
}))
|
||||
.with_child(Button::new("Save").on_click(move |ctx, _, _| {
|
||||
ctx.submit_command(
|
||||
Command::new(
|
||||
druid::commands::SHOW_SAVE_PANEL,
|
||||
save_dialog_options.clone(),
|
||||
),
|
||||
None,
|
||||
)
|
||||
ctx.submit_command(Command::new(
|
||||
druid::commands::SHOW_SAVE_PANEL,
|
||||
save_dialog_options.clone(),
|
||||
Target::Auto,
|
||||
))
|
||||
}));
|
||||
|
||||
let tool_buttons = Flex::row()
|
||||
|
|
@ -132,10 +126,10 @@ fn build_ui() -> impl Widget<StilettoState> {
|
|||
.padding((8.0, 0.0))
|
||||
.on_click(|ctx, tool_state, _| {
|
||||
tool_state.selected = true;
|
||||
ctx.submit_command(stiletto::commands::UPDATE_TOOL, None);
|
||||
ctx.submit_command(stiletto::commands::UPDATE_TOOL);
|
||||
})
|
||||
})
|
||||
.grow(ListGrowDirection::Right)
|
||||
.horizontal()
|
||||
.lens(StilettoState::tool_icons),
|
||||
1.0,
|
||||
);
|
||||
|
|
@ -167,10 +161,10 @@ impl AppDelegate<StilettoState> for Delegate {
|
|||
cmd: &Command,
|
||||
data: &mut StilettoState,
|
||||
_env: &Env,
|
||||
) -> bool {
|
||||
) -> Handled {
|
||||
use std::fs::File;
|
||||
|
||||
if let Some(Some(file_info)) = cmd.get(commands::SAVE_FILE) {
|
||||
if let Some(file_info) = cmd.get(commands::SAVE_FILE_AS) {
|
||||
let res_file = File::create(file_info.path());
|
||||
if let Ok(f) = res_file {
|
||||
let write_res =
|
||||
|
|
@ -183,7 +177,7 @@ impl AppDelegate<StilettoState> for Delegate {
|
|||
} else {
|
||||
warn!("Cannot create file: {:?}", res_file.err());
|
||||
}
|
||||
return true;
|
||||
return Handled::Yes;
|
||||
}
|
||||
if let Some(file_info) = cmd.get(commands::OPEN_FILE) {
|
||||
if let Ok(f) = File::open(file_info.path()) {
|
||||
|
|
@ -196,7 +190,7 @@ impl AppDelegate<StilettoState> for Delegate {
|
|||
warn!("didn't work: {:?}", res_snapshot.err());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return Handled::Yes;
|
||||
}
|
||||
if cmd.get(stiletto::commands::UPDATE_TOOL).is_some() {
|
||||
let old_tool = data.current_tool;
|
||||
|
|
@ -214,6 +208,6 @@ impl AppDelegate<StilettoState> for Delegate {
|
|||
));
|
||||
}
|
||||
}
|
||||
false
|
||||
Handled::No
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
use druid::widget::{Container, SizedBox, Svg, SvgData, ViewSwitcher, WidgetExt};
|
||||
use druid::{Color, Data, UnitPoint};
|
||||
|
||||
use crate::tool::{CanvasToolParams, CanvasToolType};
|
||||
use crate::tool::CanvasToolParams;
|
||||
|
||||
#[derive(Clone, Data)]
|
||||
pub struct CanvasToolIconState {
|
||||
|
|
@ -26,10 +26,6 @@ pub struct CanvasToolIconState {
|
|||
}
|
||||
|
||||
impl CanvasToolIconState {
|
||||
fn tool_type(&self) -> CanvasToolType {
|
||||
self.tool_params.tool_type()
|
||||
}
|
||||
|
||||
fn svg_data(&self) -> SvgData {
|
||||
match self.tool_params {
|
||||
CanvasToolParams::Pen { .. } => include_str!("../../icons/pen.svg")
|
||||
|
|
@ -46,9 +42,9 @@ pub fn build_simple_tool_widget(
|
|||
width: f64,
|
||||
height: f64,
|
||||
padding: f64,
|
||||
) -> ViewSwitcher<CanvasToolIconState, (CanvasToolType, bool)> {
|
||||
ViewSwitcher::<CanvasToolIconState, (CanvasToolType, bool)>::new(
|
||||
|tool_state, _| (tool_state.tool_type(), tool_state.selected),
|
||||
) -> ViewSwitcher<CanvasToolIconState, CanvasToolIconState> {
|
||||
ViewSwitcher::<CanvasToolIconState, CanvasToolIconState>::new(
|
||||
|tool_state, _| tool_state.clone(),
|
||||
move |_, tool_state, _| {
|
||||
Box::new(
|
||||
Container::new(
|
||||
|
|
@ -62,7 +58,7 @@ pub fn build_simple_tool_widget(
|
|||
)
|
||||
.border(
|
||||
if tool_state.selected {
|
||||
Color::rgb(10, 10, 10)
|
||||
Color::rgb(10.0, 10.0, 10.0)
|
||||
} else {
|
||||
Color::BLACK
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue