Skip to content

Try factoring out the dropdown boilerplate #2589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

785 changes: 301 additions & 484 deletions editor/src/messages/portfolio/document/node_graph/node_properties.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -414,16 +414,15 @@ impl LayoutHolder for MenuBarMessageHandler {
action: MenuBarEntry::no_action(),
disabled: no_active_document || !has_selected_layers,
children: MenuBarEntryChildren(vec![{
let operations = BooleanOperation::list();
let icons = BooleanOperation::icons();
operations
.into_iter()
.zip(icons)
.map(move |(operation, icon)| MenuBarEntry {
label: operation.to_string(),
icon: Some(icon.into()),
let list = <BooleanOperation as graphene_core::registry::ChoiceTypeStatic>::list();
list.into_iter()
.map(|i| i.into_iter())
.flatten()
.map(move |(operation, info)| MenuBarEntry {
label: info.label.to_string(),
icon: info.icon.as_ref().map(|i| i.to_string()),
action: MenuBarEntry::create_action(move |_| {
let group_folder_type = GroupFolderType::BooleanOperation(operation);
let group_folder_type = GroupFolderType::BooleanOperation(*operation);
DocumentMessage::GroupSelectedLayers { group_folder_type }.into()
}),
disabled: no_active_document || !has_selected_layers,
Expand Down
16 changes: 10 additions & 6 deletions editor/src/messages/tool/tool_messages/select_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,18 @@ impl SelectTool {
}

fn boolean_widgets(&self, selected_count: usize) -> impl Iterator<Item = WidgetHolder> + use<> {
let operations = BooleanOperation::list();
let icons = BooleanOperation::icons();
operations.into_iter().zip(icons).map(move |(operation, icon)| {
IconButton::new(icon, 24)
.tooltip(operation.to_string())
let list = <BooleanOperation as graphene_core::registry::ChoiceTypeStatic>::list();
list.into_iter().map(|i| i.into_iter()).flatten().map(move |(operation, info)| {
let mut tooltip = info.label.to_string();
if let Some(doc) = info.docstring.as_deref() {
tooltip.push_str("\n\n");
tooltip.push_str(doc);
}
IconButton::new(info.icon.as_deref().unwrap(), 24)
.tooltip(tooltip)
.disabled(selected_count == 0)
.on_update(move |_| {
let group_folder_type = GroupFolderType::BooleanOperation(operation);
let group_folder_type = GroupFolderType::BooleanOperation(*operation);
DocumentMessage::GroupSelectedLayers { group_folder_type }.into()
})
.widget_holder()
Expand Down
16 changes: 3 additions & 13 deletions node-graph/gcore/src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ use crate::{Ctx, ExtractAnimationTime, ExtractTime};

const DAY: f64 = 1000. * 3600. * 24.;

#[derive(Debug, Clone, Copy, PartialEq, Eq, dyn_any::DynAny, Default, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, dyn_any::DynAny, Default, Hash, node_macro::ChoiceType)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Real Time Mode
pub enum RealTimeMode {
#[label("UTC")]
Utc,
Year,
Hour,
Expand All @@ -13,18 +15,6 @@ pub enum RealTimeMode {
Second,
Millisecond,
}
impl core::fmt::Display for RealTimeMode {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
RealTimeMode::Utc => write!(f, "UTC"),
RealTimeMode::Year => write!(f, "Year"),
RealTimeMode::Hour => write!(f, "Hour"),
RealTimeMode::Minute => write!(f, "Minute"),
RealTimeMode::Second => write!(f, "Second"),
RealTimeMode::Millisecond => write!(f, "Millisecond"),
}
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AnimationTimeMode {
Expand Down
12 changes: 3 additions & 9 deletions node-graph/gcore/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,20 +527,14 @@ fn extract_xy<T: Into<DVec2>>(_: impl Ctx, #[implementations(DVec2, IVec2, UVec2

#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "std", derive(specta::Type))]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, DynAny)]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, DynAny, node_macro::ChoiceType)]
#[widget(Dropdown)]
/// X or Y Component of Vector2
pub enum XY {
#[default]
X,
Y,
}
impl core::fmt::Display for XY {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
XY::X => write!(f, "X"),
XY::Y => write!(f, "Y"),
}
}
}

// TODO: Rename to "Passthrough"
/// Passes-through the input value without changing it. This is useful for rerouting wires for organization purposes.
Expand Down
Loading
Loading