Skip to content

Commit 629a1f4

Browse files
authored
Redesign how the control bar handles fill and stroke colors (#4137)
* Revamp how the control bar handles fill and stroke colors * Fix bugs * Code review
1 parent f6def3b commit 629a1f4

25 files changed

Lines changed: 1353 additions & 547 deletions

editor/src/messages/color_picker/color_picker_message_handler.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ impl MessageHandler<ColorPickerMessage, ()> for ColorPickerMessageHandler {
102102
self.gradient = None;
103103
self.active_marker_index = None;
104104
self.active_marker_is_midpoint = false;
105+
106+
responses.add(DocumentMessage::EndTransaction);
105107
}
106108
ColorPickerMessage::VisualUpdate { update } => {
107109
self.hue = update.hue;

editor/src/messages/layout/utility_types/widgets/button_widgets.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ pub struct ColorInput {
202202
#[serde(rename = "menuDirection")]
203203
pub menu_direction: Option<MenuDirection>,
204204
pub disabled: bool,
205+
pub mixed: bool,
206+
207+
// Sizing
208+
#[serde(rename = "minWidth")]
209+
pub min_width: u32,
210+
#[serde(rename = "maxWidth")]
211+
pub max_width: u32,
205212

206213
// Styling
207214
pub narrow: bool,

editor/src/messages/layout/utility_types/widgets/input_widgets.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub struct CheckboxInput {
2020
#[serde(rename = "forLabel")]
2121
pub for_label: CheckboxId,
2222
pub disabled: bool,
23+
pub mixed: bool,
2324

2425
// Tooltips
2526
#[serde(rename = "tooltipLabel")]

editor/src/messages/portfolio/document/graph_operation/graph_operation_message_handler.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageContext<'_>> for
323323
let layer = modify_inputs.create_layer(id);
324324
modify_inputs.insert_text(text, font, typesetting, layer);
325325
network_interface.move_layer_to_stack(layer, parent, insert_index, &[]);
326-
responses.add(GraphOperationMessage::StrokeSet { layer, stroke: Stroke::default() });
327326
responses.add(NodeGraphMessage::RunDocumentGraph);
328327
}
329328
GraphOperationMessage::ResizeArtboard { layer, location, dimensions } => {

editor/src/messages/portfolio/document/graph_operation/utility_types.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,6 @@ impl<'a> ModifyInputsContext<'a> {
267267
let transform = resolve_proto_node_type(graphene_std::transform_nodes::transform::IDENTIFIER)
268268
.expect("Transform node does not exist")
269269
.default_node_template();
270-
let stroke = resolve_proto_node_type(graphene_std::vector_nodes::stroke::IDENTIFIER)
271-
.expect("Stroke node does not exist")
272-
.default_node_template();
273270
let fill = resolve_proto_node_type(graphene_std::vector_nodes::fill::IDENTIFIER)
274271
.expect("Fill node does not exist")
275272
.default_node_template();
@@ -282,10 +279,6 @@ impl<'a> ModifyInputsContext<'a> {
282279
self.network_interface.insert_node(transform_id, transform, &[]);
283280
self.network_interface.move_node_to_chain_start(&transform_id, layer, &[], self.import);
284281

285-
let stroke_id = NodeId::new();
286-
self.network_interface.insert_node(stroke_id, stroke, &[]);
287-
self.network_interface.move_node_to_chain_start(&stroke_id, layer, &[], self.import);
288-
289282
let fill_id = NodeId::new();
290283
self.network_interface.insert_node(fill_id, fill, &[]);
291284
self.network_interface.move_node_to_chain_start(&fill_id, layer, &[], self.import);

editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -355,19 +355,21 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
355355
responses.add(NodeGraphMessage::DeleteSelectedNodes { delete_children: true });
356356
}
357357
NodeGraphMessage::DeleteNodes { node_ids, delete_children } => {
358-
// Detect stroke proto nodes among the doomed nodes before they're gone, so the stroke-using tools'
359-
// Weight widgets can re-read the layer (they'll now read 0 px since the stroke node is missing).
360-
let any_stroke_deleted = node_ids.iter().any(|node_id| {
358+
// Detect stroke/fill proto nodes among the doomed nodes before they're gone so the tool control bars can re-sync
359+
let stroke = DefinitionIdentifier::ProtoNode(graphene_std::vector::stroke::IDENTIFIER);
360+
let fill = DefinitionIdentifier::ProtoNode(graphene_std::vector::fill::IDENTIFIER);
361+
let any_fill_or_stroke_deleted = node_ids.iter().any(|node_id| {
361362
network_interface
362363
.reference(node_id, selection_network_path)
363-
.is_some_and(|reference| reference == DefinitionIdentifier::ProtoNode(graphene_std::vector::stroke::IDENTIFIER))
364+
.is_some_and(|reference| reference == stroke || reference == fill)
364365
});
365366
network_interface.delete_nodes(node_ids, delete_children, selection_network_path);
366-
if any_stroke_deleted {
367+
if any_fill_or_stroke_deleted {
367368
responses.add(PenToolMessage::SelectionChanged);
368369
responses.add(FreehandToolMessage::SelectionChanged);
369370
responses.add(SplineToolMessage::SelectionChanged);
370371
responses.add(ShapeToolMessage::SelectionChanged);
372+
responses.add(TextToolMessage::SelectionChanged);
371373
}
372374
}
373375
// Deletes selected_nodes. If `reconnect` is true, then all children nodes (secondary input) of the selected nodes are deleted and the siblings (primary input/output) are reconnected.
@@ -1740,21 +1742,17 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
17401742
}
17411743
}
17421744
NodeGraphMessage::SetInputValue { node_id, input_index, value } => {
1745+
use graphene_std::vector::generator_nodes::*;
1746+
17431747
let is_fill = matches!(value, TaggedValue::Fill(_));
17441748
let reference = network_interface.reference(&node_id, selection_network_path);
17451749
let is_text_node = reference.as_ref().is_some_and(|r| *r == DefinitionIdentifier::ProtoNode(graphene_std::text::text::IDENTIFIER));
17461750
let is_stroke_node = reference.as_ref().is_some_and(|r| *r == DefinitionIdentifier::ProtoNode(graphene_std::vector::stroke::IDENTIFIER));
1751+
let is_fill_node = reference.as_ref().is_some_and(|r| *r == DefinitionIdentifier::ProtoNode(graphene_std::vector::fill::IDENTIFIER));
17471752
let is_shape_generator_node = reference.as_ref().is_some_and(|r| {
1748-
[
1749-
graphene_std::vector::generator_nodes::regular_polygon::IDENTIFIER,
1750-
graphene_std::vector::generator_nodes::star::IDENTIFIER,
1751-
graphene_std::vector::generator_nodes::arc::IDENTIFIER,
1752-
graphene_std::vector::generator_nodes::spiral::IDENTIFIER,
1753-
graphene_std::vector::generator_nodes::grid::IDENTIFIER,
1754-
graphene_std::vector::generator_nodes::arrow::IDENTIFIER,
1755-
]
1756-
.into_iter()
1757-
.any(|id| *r == DefinitionIdentifier::ProtoNode(id))
1753+
[regular_polygon::IDENTIFIER, star::IDENTIFIER, arc::IDENTIFIER, spiral::IDENTIFIER, grid::IDENTIFIER, arrow::IDENTIFIER]
1754+
.into_iter()
1755+
.any(|id| *r == DefinitionIdentifier::ProtoNode(id))
17581756
});
17591757

17601758
let input = NodeInput::value(value, false);
@@ -1766,15 +1764,12 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
17661764
if is_fill {
17671765
responses.add(OverlaysMessage::Draw);
17681766
}
1769-
if is_text_node {
1770-
responses.add(TextToolMessage::SelectionChanged);
1771-
}
1772-
if is_stroke_node || is_shape_generator_node {
1773-
// The dispatcher delivers each only to its tool when active, so this just covers all four stroke-using tools.
1767+
if is_stroke_node || is_fill_node || is_shape_generator_node || is_text_node {
17741768
responses.add(PenToolMessage::SelectionChanged);
17751769
responses.add(FreehandToolMessage::SelectionChanged);
17761770
responses.add(SplineToolMessage::SelectionChanged);
17771771
responses.add(ShapeToolMessage::SelectionChanged);
1772+
responses.add(TextToolMessage::SelectionChanged);
17781773
}
17791774
if network_interface.connected_to_output(&node_id, selection_network_path) {
17801775
responses.add(NodeGraphMessage::RunDocumentGraph);

0 commit comments

Comments
 (0)