Add color choices to the options bar of tools (#1199)

* Generalize PenColorType -> ToolColorType

* impl default for ToolColorOptions

* Add stroke color option to the freehand tool

* Consolidate working color update messages

* Update tool working colours when switching tools

* Update working colors on tool activation

* Add stroke color option to line tool

* Add fill color option to freehand tool

* Add tool color options to spline tool

* Fix freehand tool

* Add color options to text

* Add tool color/weight options to rectangle

* Add tool color/weight options to ellipse

* Add tool color/weight options to shape

* Fix spline default fill/stroke

* Reorder widgets and code cleanup

* Add CustomColor icon

* Fix warnings

* Change color defaults to secondary fill, primary stroke

* Fix spacing between brush options number inputs

* Add toolbar color option to brush

* Implement allowNone on color input widget

* Rearrange widget and remove X from brush

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Chase
2023-05-08 18:00:10 +08:00
committed by Keavon Chambers
co-authored by Keavon Chambers
parent ab2de96640
commit 7e1b452757
21 changed files with 929 additions and 310 deletions
@@ -0,0 +1,106 @@
use crate::messages::layout::utility_types::layout_widget::WidgetCallback;
use crate::messages::layout::utility_types::widget_prelude::{ColorInput, IconButton, RadioEntryData, RadioInput, TextLabel, WidgetHolder};
use graphene_core::Color;
use serde::{Deserialize, Serialize};
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, specta::Type)]
pub enum ToolColorType {
Primary,
Secondary,
Custom,
}
pub struct ToolColorOptions {
pub custom_color: Option<Color>,
pub primary_working_color: Option<Color>,
pub secondary_working_color: Option<Color>,
pub color_type: ToolColorType,
}
impl Default for ToolColorOptions {
fn default() -> Self {
Self {
color_type: ToolColorType::Primary,
custom_color: Some(Color::BLACK),
primary_working_color: Some(Color::BLACK),
secondary_working_color: Some(Color::WHITE),
}
}
}
impl ToolColorOptions {
pub fn new_primary() -> Self {
Self::default()
}
pub fn new_secondary() -> Self {
Self {
color_type: ToolColorType::Secondary,
..Default::default()
}
}
pub fn new_none() -> Self {
Self {
color_type: ToolColorType::Custom,
custom_color: None,
..Default::default()
}
}
pub fn active_color(&self) -> Option<Color> {
match self.color_type {
ToolColorType::Custom => self.custom_color,
ToolColorType::Primary => self.primary_working_color,
ToolColorType::Secondary => self.secondary_working_color,
}
}
pub fn create_widgets(
&self,
label_text: impl Into<String>,
color_allow_none: bool,
reset_callback: WidgetCallback<IconButton>,
radio_callback: fn(ToolColorType) -> WidgetCallback<()>,
color_callback: WidgetCallback<ColorInput>,
) -> Vec<WidgetHolder> {
let mut widgets = vec![TextLabel::new(label_text).widget_holder()];
if !color_allow_none {
widgets.push(WidgetHolder::unrelated_separator());
} else {
let mut reset = IconButton::new("CloseX", 12)
.disabled(self.custom_color.is_none() && self.color_type == ToolColorType::Custom)
.tooltip("Clear Color");
reset.on_update = reset_callback;
widgets.push(WidgetHolder::related_separator());
widgets.push(reset.widget_holder());
widgets.push(WidgetHolder::related_separator());
};
let entries = vec![
("WorkingColorsPrimary", "Primary Working Color", ToolColorType::Primary),
("WorkingColorsSecondary", "Secondary Working Color", ToolColorType::Secondary),
("CustomColor", "Custom Color", ToolColorType::Custom),
]
.into_iter()
.map(|(icon, tooltip, color_type)| {
let mut entry = RadioEntryData::new("").tooltip(tooltip).icon(icon);
entry.on_update = radio_callback(color_type);
entry
})
.collect();
let radio = RadioInput::new(entries).selected_index(self.color_type.clone() as u32).widget_holder();
widgets.push(radio);
widgets.push(WidgetHolder::related_separator());
let mut color_input = ColorInput::new(self.active_color()).allow_none(color_allow_none);
color_input.on_update = color_callback;
widgets.push(color_input.widget_holder());
widgets
}
}
@@ -1,3 +1,4 @@
pub mod color_selector;
pub mod graph_modification_utils;
pub mod overlay_renderer;
pub mod path_outline;