mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-30 08:38:11 +08:00
added operation type widget
This commit is contained in:
@@ -1,10 +1,7 @@
|
|||||||
use super::tool_prelude::*;
|
use super::tool_prelude::*;
|
||||||
use crate::consts::DEFAULT_STROKE_WIDTH;
|
|
||||||
use crate::messages::portfolio::document::overlays::utility_types::OverlayContext;
|
use crate::messages::portfolio::document::overlays::utility_types::OverlayContext;
|
||||||
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
|
use crate::messages::portfolio::document::utility_types::document_metadata::LayerNodeIdentifier;
|
||||||
use crate::messages::tool::common_functionality::color_selector::{ToolColorOptions, ToolColorType};
|
|
||||||
use crate::messages::tool::common_functionality::shapes::shape_utility::extract_circular_repeat_parameters;
|
use crate::messages::tool::common_functionality::shapes::shape_utility::extract_circular_repeat_parameters;
|
||||||
use graphene_std::Color;
|
|
||||||
|
|
||||||
#[derive(Default, ExtractField)]
|
#[derive(Default, ExtractField)]
|
||||||
pub struct OperationTool {
|
pub struct OperationTool {
|
||||||
@@ -14,17 +11,13 @@ pub struct OperationTool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct OperationOptions {
|
pub struct OperationOptions {
|
||||||
line_weight: f64,
|
operation_type: OperationType,
|
||||||
fill: ToolColorOptions,
|
|
||||||
stroke: ToolColorOptions,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for OperationOptions {
|
impl Default for OperationOptions {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
line_weight: DEFAULT_STROKE_WIDTH,
|
operation_type: OperationType::CircularRepeat,
|
||||||
fill: ToolColorOptions::new_none(),
|
|
||||||
stroke: ToolColorOptions::new_primary(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,12 +49,7 @@ enum OperationToolFsmState {
|
|||||||
|
|
||||||
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||||
pub enum OperationOptionsUpdate {
|
pub enum OperationOptionsUpdate {
|
||||||
FillColor(Option<Color>),
|
OperationType(OperationType),
|
||||||
FillColorType(ToolColorType),
|
|
||||||
LineWeight(f64),
|
|
||||||
StrokeColor(Option<Color>),
|
|
||||||
StrokeColorType(ToolColorType),
|
|
||||||
WorkingColors(Option<Color>, Option<Color>),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToolMetadata for OperationTool {
|
impl ToolMetadata for OperationTool {
|
||||||
@@ -76,76 +64,29 @@ impl ToolMetadata for OperationTool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_weight_widget(line_weight: f64) -> WidgetHolder {
|
fn create_operation_type_option_widget(operation_type: OperationType) -> WidgetHolder {
|
||||||
NumberInput::new(Some(line_weight))
|
let entries = vec![vec![
|
||||||
.unit(" px")
|
MenuListEntry::new("Repeat").label("Repeat").on_commit(move |_| {
|
||||||
.label("Weight")
|
|
||||||
.min(0.)
|
|
||||||
.max((1_u64 << f64::MANTISSA_DIGITS) as f64)
|
|
||||||
.on_update(|number_input: &NumberInput| {
|
|
||||||
OperationToolMessage::UpdateOptions {
|
OperationToolMessage::UpdateOptions {
|
||||||
options: OperationOptionsUpdate::LineWeight(number_input.value.unwrap()),
|
options: OperationOptionsUpdate::OperationType(OperationType::Repeat),
|
||||||
}
|
}
|
||||||
.into()
|
.into()
|
||||||
})
|
}),
|
||||||
.widget_holder()
|
MenuListEntry::new("Repeat").label("Circular Repeat").on_commit(move |_| {
|
||||||
|
OperationToolMessage::UpdateOptions {
|
||||||
|
options: OperationOptionsUpdate::OperationType(OperationType::CircularRepeat),
|
||||||
|
}
|
||||||
|
.into()
|
||||||
|
}),
|
||||||
|
]];
|
||||||
|
DropdownInput::new(entries).selected_index(Some(operation_type as u32)).widget_holder()
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LayoutHolder for OperationTool {
|
impl LayoutHolder for OperationTool {
|
||||||
fn layout(&self) -> Layout {
|
fn layout(&self) -> Layout {
|
||||||
let mut widgets = self.options.fill.create_widgets(
|
let mut widgets = vec![];
|
||||||
"Fill",
|
|
||||||
true,
|
|
||||||
|_| {
|
|
||||||
OperationToolMessage::UpdateOptions {
|
|
||||||
options: OperationOptionsUpdate::FillColor(None),
|
|
||||||
}
|
|
||||||
.into()
|
|
||||||
},
|
|
||||||
|color_type: ToolColorType| {
|
|
||||||
WidgetCallback::new(move |_| {
|
|
||||||
OperationToolMessage::UpdateOptions {
|
|
||||||
options: OperationOptionsUpdate::FillColorType(color_type.clone()),
|
|
||||||
}
|
|
||||||
.into()
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|color: &ColorInput| {
|
|
||||||
OperationToolMessage::UpdateOptions {
|
|
||||||
options: OperationOptionsUpdate::FillColor(color.value.as_solid().map(|color| color.to_linear_srgb())),
|
|
||||||
}
|
|
||||||
.into()
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
widgets.push(Separator::new(SeparatorType::Unrelated).widget_holder());
|
widgets.push(create_operation_type_option_widget(self.options.operation_type));
|
||||||
|
|
||||||
widgets.append(&mut self.options.stroke.create_widgets(
|
|
||||||
"Stroke",
|
|
||||||
true,
|
|
||||||
|_| {
|
|
||||||
OperationToolMessage::UpdateOptions {
|
|
||||||
options: OperationOptionsUpdate::StrokeColor(None),
|
|
||||||
}
|
|
||||||
.into()
|
|
||||||
},
|
|
||||||
|color_type: ToolColorType| {
|
|
||||||
WidgetCallback::new(move |_| {
|
|
||||||
OperationToolMessage::UpdateOptions {
|
|
||||||
options: OperationOptionsUpdate::StrokeColorType(color_type.clone()),
|
|
||||||
}
|
|
||||||
.into()
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|color: &ColorInput| {
|
|
||||||
OperationToolMessage::UpdateOptions {
|
|
||||||
options: OperationOptionsUpdate::StrokeColor(color.value.as_solid().map(|color| color.to_linear_srgb())),
|
|
||||||
}
|
|
||||||
.into()
|
|
||||||
},
|
|
||||||
));
|
|
||||||
widgets.push(Separator::new(SeparatorType::Unrelated).widget_holder());
|
|
||||||
widgets.push(create_weight_widget(self.options.line_weight));
|
|
||||||
|
|
||||||
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row { widgets }]))
|
Layout::WidgetLayout(WidgetLayout::new(vec![LayoutGroup::Row { widgets }]))
|
||||||
}
|
}
|
||||||
@@ -159,23 +100,7 @@ impl<'a> MessageHandler<ToolMessage, &mut ToolActionMessageContext<'a>> for Oper
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
match options {
|
match options {
|
||||||
OperationOptionsUpdate::LineWeight(line_weight) => self.options.line_weight = line_weight,
|
OperationOptionsUpdate::OperationType(operation_type) => self.options.operation_type = operation_type,
|
||||||
OperationOptionsUpdate::FillColor(color) => {
|
|
||||||
self.options.fill.custom_color = color;
|
|
||||||
self.options.fill.color_type = ToolColorType::Custom;
|
|
||||||
}
|
|
||||||
OperationOptionsUpdate::FillColorType(color_type) => self.options.fill.color_type = color_type,
|
|
||||||
OperationOptionsUpdate::StrokeColor(color) => {
|
|
||||||
self.options.stroke.custom_color = color;
|
|
||||||
self.options.stroke.color_type = ToolColorType::Custom;
|
|
||||||
}
|
|
||||||
OperationOptionsUpdate::StrokeColorType(color_type) => self.options.stroke.color_type = color_type,
|
|
||||||
OperationOptionsUpdate::WorkingColors(primary, secondary) => {
|
|
||||||
self.options.stroke.primary_working_color = primary;
|
|
||||||
self.options.stroke.secondary_working_color = secondary;
|
|
||||||
self.options.fill.primary_working_color = primary;
|
|
||||||
self.options.fill.secondary_working_color = secondary;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.send_layout(responses, LayoutTarget::ToolOptions);
|
self.send_layout(responses, LayoutTarget::ToolOptions);
|
||||||
@@ -396,3 +321,10 @@ impl Fsm for OperationToolFsmState {
|
|||||||
responses.add(FrontendMessage::UpdateMouseCursor { cursor: MouseCursorIcon::Default });
|
responses.add(FrontendMessage::UpdateMouseCursor { cursor: MouseCursorIcon::Default });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||||
|
pub enum OperationType {
|
||||||
|
#[default]
|
||||||
|
CircularRepeat = 0,
|
||||||
|
Repeat = 1,
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user