Rename and reorganize several widgets (#1462)

* Rename SwatchPairInput -> WorkingColorsButton

* Remove unnecessary Svelte each-loop keys

* Rename (and migrate) MenuBarInput -> MenuListButton

* Rename PivotAssist -> PivotInput

* Rename PersistentScrollbar -> ScrollbarInput and CanvasRuler -> RulerInput

* Rename DIalogModal -> Dialog

* Rename WidgetRow -> WidgetSpan
This commit is contained in:
Keavon Chambers
2023-11-18 04:34:30 -08:00
committed by GitHub
parent e3f5e7001f
commit 719c96ecd8
38 changed files with 375 additions and 389 deletions

View File

@@ -1,4 +1,4 @@
//! Handles modal dialogs that appear as floating menus in the center of the editor window.
//! Handles dialogs that appear as floating menus in the center of the editor window.
//!
//! Dialogs are represented as structs that implement the `DialogLayoutHolder` trait.
//!

View File

@@ -1,7 +1,7 @@
use crate::messages::layout::utility_types::widget_prelude::*;
use crate::messages::prelude::*;
/// A dialog for confirming the closing of all documents viewable via `file -> close all` in the menu bar.
/// A dialog for confirming the closing of all documents viewable via `File -> Close All` in the menu bar.
pub struct CloseAllDocumentsDialog {
pub unsaved_document_names: Vec<String>,
}

View File

@@ -196,10 +196,10 @@ impl<F: Fn(&MessageDiscriminant) -> Vec<KeysGroup>> MessageHandler<LayoutMessage
let callback_message = (parameter_expose_button.on_update.callback)(parameter_expose_button);
responses.add(callback_message);
}
Widget::PivotAssist(pivot_assist) => {
let update_value = value.as_str().expect("RadioInput update was not of type: u64");
pivot_assist.position = update_value.into();
let callback_message = (pivot_assist.on_update.callback)(pivot_assist);
Widget::PivotInput(pivot_input) => {
let update_value = value.as_str().expect("PivotInput update was not of type: u64");
pivot_input.position = update_value.into();
let callback_message = (pivot_input.on_update.callback)(pivot_input);
responses.add(callback_message);
}
Widget::PopoverButton(_) => {}
@@ -210,7 +210,6 @@ impl<F: Fn(&MessageDiscriminant) -> Vec<KeysGroup>> MessageHandler<LayoutMessage
responses.add(callback_message);
}
Widget::Separator(_) => {}
Widget::SwatchPairInput(_) => {}
Widget::TextAreaInput(text_area_input) => {
let update_value = value.as_str().expect("TextAreaInput update was not of type: string");
text_area_input.value = update_value.into();
@@ -228,6 +227,7 @@ impl<F: Fn(&MessageDiscriminant) -> Vec<KeysGroup>> MessageHandler<LayoutMessage
responses.add(callback_message);
}
Widget::TextLabel(_) => {}
Widget::WorkingColorsButton(_) => {}
};
responses.add(ResendActiveWidget { layout_target, dirty_id: widget_id });
}

View File

@@ -1,4 +1,3 @@
use super::widgets::assist_widgets::*;
use super::widgets::button_widgets::*;
use super::widgets::input_widgets::*;
use super::widgets::label_widgets::*;
@@ -337,7 +336,7 @@ impl LayoutGroup {
Widget::TextInput(x) => &mut x.tooltip,
Widget::TextLabel(x) => &mut x.tooltip,
Widget::BreadcrumbTrailButtons(x) => &mut x.tooltip,
Widget::InvisibleStandinInput(_) | Widget::PivotAssist(_) | Widget::RadioInput(_) | Widget::Separator(_) | Widget::SwatchPairInput(_) => continue,
Widget::InvisibleStandinInput(_) | Widget::PivotInput(_) | Widget::RadioInput(_) | Widget::Separator(_) | Widget::WorkingColorsButton(_) => continue,
};
if val.is_empty() {
*val = tooltip.clone();
@@ -483,15 +482,15 @@ pub enum Widget {
NumberInput(NumberInput),
OptionalInput(OptionalInput),
ParameterExposeButton(ParameterExposeButton),
PivotAssist(PivotAssist),
PivotInput(PivotInput),
PopoverButton(PopoverButton),
RadioInput(RadioInput),
Separator(Separator),
SwatchPairInput(SwatchPairInput),
TextAreaInput(TextAreaInput),
TextButton(TextButton),
TextInput(TextInput),
TextLabel(TextLabel),
WorkingColorsButton(WorkingColorsButton),
}
/// A single change to part of the UI, containing the location of the change and the new value.
@@ -559,13 +558,13 @@ impl DiffUpdate {
| Widget::ImageLabel(_)
| Widget::CurveInput(_)
| Widget::InvisibleStandinInput(_)
| Widget::PivotAssist(_)
| Widget::PivotInput(_)
| Widget::RadioInput(_)
| Widget::Separator(_)
| Widget::SwatchPairInput(_)
| Widget::TextAreaInput(_)
| Widget::TextInput(_)
| Widget::TextLabel(_) => None,
| Widget::TextLabel(_)
| Widget::WorkingColorsButton(_) => None,
};
if let Some((tooltip, Some(tooltip_shortcut))) = &mut tooltip_shortcut {
apply_shortcut_to_tooltip(tooltip_shortcut, tooltip);

View File

@@ -3,7 +3,6 @@ pub mod widgets;
pub mod widget_prelude {
pub use super::layout_widget::*;
pub use super::widgets::assist_widgets::*;
pub use super::widgets::button_widgets::*;
pub use super::widgets::input_widgets::*;
pub use super::widgets::label_widgets::*;

View File

@@ -1,102 +0,0 @@
use crate::messages::layout::utility_types::widget_prelude::*;
use graphite_proc_macros::WidgetBuilder;
use derivative::*;
use glam::DVec2;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Derivative, Serialize, Deserialize, WidgetBuilder, specta::Type)]
#[derivative(Debug, PartialEq)]
pub struct PivotAssist {
#[widget_builder(constructor)]
pub position: PivotPosition,
pub disabled: bool,
// Callbacks
#[serde(skip)]
#[derivative(Debug = "ignore", PartialEq = "ignore")]
pub on_update: WidgetCallback<PivotAssist>,
}
#[derive(Clone, Copy, Serialize, Deserialize, Debug, Default, PartialEq, Eq, specta::Type)]
pub enum PivotPosition {
#[default]
None,
TopLeft,
TopCenter,
TopRight,
CenterLeft,
Center,
CenterRight,
BottomLeft,
BottomCenter,
BottomRight,
}
impl From<&str> for PivotPosition {
fn from(input: &str) -> Self {
match input {
"None" => PivotPosition::None,
"TopLeft" => PivotPosition::TopLeft,
"TopCenter" => PivotPosition::TopCenter,
"TopRight" => PivotPosition::TopRight,
"CenterLeft" => PivotPosition::CenterLeft,
"Center" => PivotPosition::Center,
"CenterRight" => PivotPosition::CenterRight,
"BottomLeft" => PivotPosition::BottomLeft,
"BottomCenter" => PivotPosition::BottomCenter,
"BottomRight" => PivotPosition::BottomRight,
_ => panic!("Failed parsing unrecognized PivotPosition enum value '{input}'"),
}
}
}
impl From<PivotPosition> for Option<DVec2> {
fn from(input: PivotPosition) -> Self {
match input {
PivotPosition::None => None,
PivotPosition::TopLeft => Some(DVec2::new(0., 0.)),
PivotPosition::TopCenter => Some(DVec2::new(0.5, 0.)),
PivotPosition::TopRight => Some(DVec2::new(1., 0.)),
PivotPosition::CenterLeft => Some(DVec2::new(0., 0.5)),
PivotPosition::Center => Some(DVec2::new(0.5, 0.5)),
PivotPosition::CenterRight => Some(DVec2::new(1., 0.5)),
PivotPosition::BottomLeft => Some(DVec2::new(0., 1.)),
PivotPosition::BottomCenter => Some(DVec2::new(0.5, 1.)),
PivotPosition::BottomRight => Some(DVec2::new(1., 1.)),
}
}
}
impl From<DVec2> for PivotPosition {
fn from(input: DVec2) -> Self {
const TOLERANCE: f64 = 1e-5_f64;
if input.y.abs() < TOLERANCE {
if input.x.abs() < TOLERANCE {
return PivotPosition::TopLeft;
} else if (input.x - 0.5).abs() < TOLERANCE {
return PivotPosition::TopCenter;
} else if (input.x - 1.).abs() < TOLERANCE {
return PivotPosition::TopRight;
}
} else if (input.y - 0.5).abs() < TOLERANCE {
if input.x.abs() < TOLERANCE {
return PivotPosition::CenterLeft;
} else if (input.x - 0.5).abs() < TOLERANCE {
return PivotPosition::Center;
} else if (input.x - 1.).abs() < TOLERANCE {
return PivotPosition::CenterRight;
}
} else if (input.y - 1.).abs() < TOLERANCE {
if input.x.abs() < TOLERANCE {
return PivotPosition::BottomLeft;
} else if (input.x - 0.5).abs() < TOLERANCE {
return PivotPosition::BottomCenter;
} else if (input.x - 1.).abs() < TOLERANCE {
return PivotPosition::BottomRight;
}
}
PivotPosition::None
}
}

View File

@@ -106,6 +106,16 @@ pub struct TextButton {
pub on_update: WidgetCallback<TextButton>,
}
#[derive(Clone, Serialize, Deserialize, Derivative, WidgetBuilder, specta::Type)]
#[derivative(Debug, PartialEq, Default)]
pub struct WorkingColorsButton {
#[widget_builder(constructor)]
pub primary: Color,
#[widget_builder(constructor)]
pub secondary: Color,
}
#[derive(Clone, Derivative, Serialize, Deserialize, WidgetBuilder, specta::Type)]
#[derivative(Debug, PartialEq, Default)]
pub struct ColorButton {

View File

@@ -3,11 +3,11 @@ use crate::messages::layout::utility_types::widget_prelude::*;
use document_legacy::layers::layer_info::LayerDataTypeDiscriminant;
use document_legacy::LayerId;
use graphene_core::raster::color::Color;
use graphene_core::raster::curve::Curve;
use graphite_proc_macros::WidgetBuilder;
use derivative::*;
use glam::DVec2;
use serde::{Deserialize, Serialize};
#[derive(Clone, Derivative, Serialize, Deserialize, WidgetBuilder, specta::Type)]
@@ -339,16 +339,6 @@ pub struct RadioEntryData {
pub on_update: WidgetCallback<()>,
}
#[derive(Clone, Serialize, Deserialize, Derivative, WidgetBuilder, specta::Type)]
#[derivative(Debug, PartialEq, Default)]
pub struct SwatchPairInput {
#[widget_builder(constructor)]
pub primary: Color,
#[widget_builder(constructor)]
pub secondary: Color,
}
#[derive(Clone, Serialize, Deserialize, Derivative, WidgetBuilder, specta::Type)]
#[derivative(Debug, PartialEq, Default)]
pub struct TextAreaInput {
@@ -405,3 +395,99 @@ pub struct CurveInput {
#[derivative(Debug = "ignore", PartialEq = "ignore")]
pub on_update: WidgetCallback<CurveInput>,
}
#[derive(Clone, Default, Derivative, Serialize, Deserialize, WidgetBuilder, specta::Type)]
#[derivative(Debug, PartialEq)]
pub struct PivotInput {
#[widget_builder(constructor)]
pub position: PivotPosition,
pub disabled: bool,
// Callbacks
#[serde(skip)]
#[derivative(Debug = "ignore", PartialEq = "ignore")]
pub on_update: WidgetCallback<PivotInput>,
}
#[derive(Clone, Copy, Serialize, Deserialize, Debug, Default, PartialEq, Eq, specta::Type)]
pub enum PivotPosition {
#[default]
None,
TopLeft,
TopCenter,
TopRight,
CenterLeft,
Center,
CenterRight,
BottomLeft,
BottomCenter,
BottomRight,
}
impl From<&str> for PivotPosition {
fn from(input: &str) -> Self {
match input {
"None" => PivotPosition::None,
"TopLeft" => PivotPosition::TopLeft,
"TopCenter" => PivotPosition::TopCenter,
"TopRight" => PivotPosition::TopRight,
"CenterLeft" => PivotPosition::CenterLeft,
"Center" => PivotPosition::Center,
"CenterRight" => PivotPosition::CenterRight,
"BottomLeft" => PivotPosition::BottomLeft,
"BottomCenter" => PivotPosition::BottomCenter,
"BottomRight" => PivotPosition::BottomRight,
_ => panic!("Failed parsing unrecognized PivotPosition enum value '{input}'"),
}
}
}
impl From<PivotPosition> for Option<DVec2> {
fn from(input: PivotPosition) -> Self {
match input {
PivotPosition::None => None,
PivotPosition::TopLeft => Some(DVec2::new(0., 0.)),
PivotPosition::TopCenter => Some(DVec2::new(0.5, 0.)),
PivotPosition::TopRight => Some(DVec2::new(1., 0.)),
PivotPosition::CenterLeft => Some(DVec2::new(0., 0.5)),
PivotPosition::Center => Some(DVec2::new(0.5, 0.5)),
PivotPosition::CenterRight => Some(DVec2::new(1., 0.5)),
PivotPosition::BottomLeft => Some(DVec2::new(0., 1.)),
PivotPosition::BottomCenter => Some(DVec2::new(0.5, 1.)),
PivotPosition::BottomRight => Some(DVec2::new(1., 1.)),
}
}
}
impl From<DVec2> for PivotPosition {
fn from(input: DVec2) -> Self {
const TOLERANCE: f64 = 1e-5_f64;
if input.y.abs() < TOLERANCE {
if input.x.abs() < TOLERANCE {
return PivotPosition::TopLeft;
} else if (input.x - 0.5).abs() < TOLERANCE {
return PivotPosition::TopCenter;
} else if (input.x - 1.).abs() < TOLERANCE {
return PivotPosition::TopRight;
}
} else if (input.y - 0.5).abs() < TOLERANCE {
if input.x.abs() < TOLERANCE {
return PivotPosition::CenterLeft;
} else if (input.x - 0.5).abs() < TOLERANCE {
return PivotPosition::Center;
} else if (input.x - 1.).abs() < TOLERANCE {
return PivotPosition::CenterRight;
}
} else if (input.y - 1.).abs() < TOLERANCE {
if input.x.abs() < TOLERANCE {
return PivotPosition::BottomLeft;
} else if (input.x - 0.5).abs() < TOLERANCE {
return PivotPosition::BottomCenter;
} else if (input.x - 1.).abs() < TOLERANCE {
return PivotPosition::BottomRight;
}
}
PivotPosition::None
}
}

View File

@@ -1,4 +1,3 @@
pub mod assist_widgets;
pub mod button_widgets;
pub mod input_widgets;
pub mod label_widgets;

View File

@@ -1181,8 +1181,8 @@ pub fn transform_properties(document_node: &DocumentNode, node_id: NodeId, _cont
{
widgets.push(Separator::new(SeparatorType::Unrelated).widget_holder());
widgets.push(
PivotAssist::new(pivot.into())
.on_update(update_value(|pivot: &PivotAssist| TaggedValue::DVec2(Into::<Option<DVec2>>::into(pivot.position).unwrap()), node_id, 5))
PivotInput::new(pivot.into())
.on_update(update_value(|pivot: &PivotInput| TaggedValue::DVec2(Into::<Option<DVec2>>::into(pivot.position).unwrap()), node_id, 5))
.widget_holder(),
);
} else {

View File

@@ -167,8 +167,8 @@ fn node_section_transform(layer: &Layer, persistent_data: &PersistentData) -> La
widgets: vec![
TextLabel::new("Location").widget_holder(),
Separator::new(SeparatorType::Unrelated).widget_holder(),
PivotAssist::new(layer.pivot.into())
.on_update(|pivot_assist: &PivotAssist| PropertiesPanelMessage::SetPivot { new_position: pivot_assist.position }.into())
PivotInput::new(layer.pivot.into())
.on_update(|pivot_input: &PivotInput| PropertiesPanelMessage::SetPivot { new_position: pivot_input.position }.into())
.widget_holder(),
Separator::new(SeparatorType::Unrelated).widget_holder(),
NumberInput::new(Some(layer.transform.x() + pivot.x))

View File

@@ -116,8 +116,8 @@ impl SelectTool {
// }
fn pivot_widget(&self, disabled: bool) -> WidgetHolder {
PivotAssist::new(self.tool_data.pivot.to_pivot_position())
.on_update(|pivot_assist: &PivotAssist| SelectToolMessage::SetPivot { position: pivot_assist.position }.into())
PivotInput::new(self.tool_data.pivot.to_pivot_position())
.on_update(|pivot_input: &PivotInput| SelectToolMessage::SetPivot { position: pivot_input.position }.into())
.disabled(disabled)
.widget_holder()
}

View File

@@ -140,7 +140,7 @@ impl DocumentToolData {
pub fn update_working_colors(&self, responses: &mut VecDeque<Message>) {
let layout = WidgetLayout::new(vec![
LayoutGroup::Row {
widgets: vec![SwatchPairInput::new(self.primary_color, self.secondary_color).widget_holder()],
widgets: vec![WorkingColorsButton::new(self.primary_color, self.secondary_color).widget_holder()],
},
LayoutGroup::Row {
widgets: vec![