Skip to content

Commit 6a54dcb

Browse files
YohYamasakiKeavon
andauthored
Remove the legacy Fill, Gradient, and PathStyle types now that paints live in attributes (#4297)
* Remove `Stroke.color` * Remove legacy Gradient struct usage * Fix gradient tool tests * Remove `Fill` enum * Fix direction of `gradient_orientation_rightward` * Remove `Gradient` struct * Remove `PathStyle` struct * Fix old `VectorData` migration * Refactor - Remove unnecessary wrapper functions - Use `as_ref` instead of `clone` for stroke if possible - Comment cleanup * Clean up stale style comments and bindings left by the paint attribute migration --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
1 parent 9f9899c commit 6a54dcb

28 files changed

Lines changed: 888 additions & 1335 deletions

File tree

editor/src/messages/clipboard/clipboard_message_handler.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,11 @@ impl MessageHandler<ClipboardMessage, ClipboardMessageContext<'_>> for Clipboard
402402
});
403403

404404
// Add default fill and stroke to the layer
405-
let fill = graphene_std::vector::style::Fill::solid(Color::WHITE);
406-
responses.add(GraphOperationMessage::FillSet { layer, fill });
405+
responses.add(GraphOperationMessage::FillColorSet { layer, color: Some(Color::WHITE) });
407406

408-
let stroke = graphene_std::vector::style::Stroke::new(Some(Color::BLACK), DEFAULT_STROKE_WIDTH);
409-
responses.add(GraphOperationMessage::StrokeSet { layer, stroke });
407+
let color = Some(Color::BLACK);
408+
let stroke = graphene_std::vector::style::Stroke::new(DEFAULT_STROKE_WIDTH);
409+
responses.add(GraphOperationMessage::StrokeSet { layer, color, stroke });
410410

411411
// Create new point ids and add those into the existing Vector path
412412
let mut points_map = HashMap::new();

editor/src/messages/portfolio/document/data_panel/data_panel_message_handler.rs

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use graphene_std::list::List;
1313
use graphene_std::memo::IORecord;
1414
use graphene_std::raster_types::{CPU, GPU, Raster};
1515
use graphene_std::vector::Vector;
16-
use graphene_std::vector::style::{Fill, FillChoice, FillChoiceUI, GradientSpreadMethod, GradientType};
16+
use graphene_std::vector::style::{FillChoice, FillChoiceUI, GradientSpreadMethod, GradientType};
1717
use graphene_std::{Artboard, Color, Context, Graphic};
1818
use std::any::Any;
1919
use std::sync::Arc;
@@ -385,61 +385,7 @@ impl TableItemLayout for Vector {
385385
VectorTableTab::Properties => {
386386
table_rows.push(column_headings(&["property", "value"]));
387387

388-
match self.style.fill.clone() {
389-
Fill::None => table_rows.push(vec![
390-
TextLabel::new("Fill").narrow(true).widget_instance(),
391-
ColorInput::new(FillChoiceUI::None)
392-
.disabled(true)
393-
.menu_direction(Some(MenuDirection::Top))
394-
.narrow(true)
395-
.widget_instance(),
396-
]),
397-
Fill::Solid(color) => table_rows.push(vec![
398-
TextLabel::new("Fill").narrow(true).widget_instance(),
399-
ColorInput::new(FillChoiceUI::from(&FillChoice::Solid(color)))
400-
.disabled(true)
401-
.menu_direction(Some(MenuDirection::Top))
402-
.narrow(true)
403-
.widget_instance(),
404-
]),
405-
Fill::Gradient(gradient) => {
406-
table_rows.push(vec![
407-
TextLabel::new("Fill").narrow(true).widget_instance(),
408-
ColorInput::new(FillChoiceUI::from(&FillChoice::Gradient(gradient.stops)))
409-
.disabled(true)
410-
.menu_direction(Some(MenuDirection::Top))
411-
.narrow(true)
412-
.widget_instance(),
413-
]);
414-
table_rows.push(vec![
415-
TextLabel::new("Fill Gradient Type").narrow(true).widget_instance(),
416-
TextLabel::new(gradient.gradient_type.to_string()).narrow(true).widget_instance(),
417-
]);
418-
table_rows.push(vec![
419-
TextLabel::new("Fill Gradient Start").narrow(true).widget_instance(),
420-
TextLabel::new(format_dvec2(gradient.start)).narrow(true).widget_instance(),
421-
]);
422-
table_rows.push(vec![
423-
TextLabel::new("Fill Gradient End").narrow(true).widget_instance(),
424-
TextLabel::new(format_dvec2(gradient.end)).narrow(true).widget_instance(),
425-
]);
426-
table_rows.push(vec![
427-
TextLabel::new("Fill Gradient Transform").narrow(true).widget_instance(),
428-
TextLabel::new(format_transform_matrix(gradient.transform)).narrow(true).widget_instance(),
429-
]);
430-
}
431-
}
432-
433-
if let Some(stroke) = self.style.stroke.clone() {
434-
let color = if let Some(color) = stroke.color { FillChoice::Solid(color) } else { FillChoice::None };
435-
table_rows.push(vec![
436-
TextLabel::new("Stroke").narrow(true).widget_instance(),
437-
ColorInput::new(FillChoiceUI::from(&color))
438-
.disabled(true)
439-
.menu_direction(Some(MenuDirection::Top))
440-
.narrow(true)
441-
.widget_instance(),
442-
]);
388+
if let Some(stroke) = self.stroke.as_ref() {
443389
table_rows.push(vec![
444390
TextLabel::new("Stroke Weight").narrow(true).widget_instance(),
445391
TextLabel::new(format!("{} px", stroke.weight)).narrow(true).widget_instance(),

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ use graphene_std::math::quad::Quad;
4242
use graphene_std::path_bool_nodes::boolean_intersect;
4343
use graphene_std::raster::BlendMode;
4444
use graphene_std::subpath::Subpath;
45-
use graphene_std::vector::PointId;
4645
use graphene_std::vector::click_target::{ClickTarget, ClickTargetType};
4746
use graphene_std::vector::misc::dvec2_to_point;
48-
use graphene_std::vector::style::{Fill, Gradient, RenderMode};
47+
use graphene_std::vector::style::RenderMode;
48+
use graphene_std::vector::{PointId, graphic_types};
4949
use kurbo::{Affine, BezPath, Line, PathSeg};
5050
use std::collections::HashSet;
5151
use std::path::PathBuf;
@@ -125,7 +125,7 @@ pub struct DocumentMessageHandler {
125125
/// network path, the node itself, and its original relative gradient. The deferred migration removes each entry as its bake lands.
126126
/// Transient migration state, but persisted in the saved document so unfinished bakes retry on the next open instead of losing placement.
127127
#[serde(default, skip_serializing_if = "Vec::is_empty")]
128-
pub(crate) pending_gradient_bbox_bake: Vec<(Vec<NodeId>, NodeId, Gradient)>,
128+
pub(crate) pending_gradient_bbox_bake: Vec<(Vec<NodeId>, NodeId, graphic_types::migrations::legacy::Gradient)>,
129129

130130
// =============================================
131131
// Fields omitted from the saved document format
@@ -2763,30 +2763,20 @@ impl DocumentMessageHandler {
27632763
let mut resulting_layers: Vec<NodeId> = Vec::new();
27642764

27652765
for layer in selected_layers {
2766-
let style = self.network_interface.document_metadata().layer_vector_data.get(&layer).map(|arc| arc.style.clone());
2767-
let Some(style) = style else {
2766+
let Some(vector_data) = self.network_interface.document_metadata().layer_vector_data.get(&layer) else {
27682767
resulting_layers.push(layer.to_node());
27692768
continue;
27702769
};
2770+
let stroke = vector_data.stroke.as_ref();
27712771

27722772
let fill_graphic_list = self.network_interface.document_metadata().layer_fill_attributes.get(&layer);
27732773
let stroke_graphic_list = self.network_interface.document_metadata().layer_stroke_attributes.get(&layer);
27742774

2775-
// `ATTR_FILL` is the source of truth when set; fall back to the legacy `style.fill` only when no attribute is present
2776-
let has_fill = if let Some(list) = fill_graphic_list {
2777-
is_paint_present(list)
2778-
} else {
2779-
!matches!(style.fill, Fill::None)
2780-
};
2781-
// `style.stroke` is `Some` whenever a `Stroke` node is in the chain, even with weight 0 or a transparent color.
2782-
// So `is_some()` would treat invisibly-stroked fill-only layers as having a stroke.
2783-
// `ATTR_STROKE` is the source of truth when set; fall back to `style.stroke.color` only when no attribute is present.
2784-
let stroke_visible = if let Some(list) = stroke_graphic_list {
2785-
list.element(0).is_some_and(|g| !g.is_fully_transparent())
2786-
} else {
2787-
style.stroke.as_ref().and_then(|s| s.color()).is_some_and(|c| c.a() != 0.)
2788-
};
2789-
let has_stroke = style.stroke.as_ref().is_some_and(|s| s.has_renderable_stroke()) && stroke_visible;
2775+
let has_fill = fill_graphic_list.is_some_and(|list| is_paint_present(list));
2776+
// `Vector.stroke` captures stroke geometry, even with weight 0 or transparent paint.
2777+
// So stroke visibility must be checked from `ATTR_STROKE`, the paint source of truth.
2778+
let stroke_visible = stroke_graphic_list.is_some_and(|list| list.element(0).is_some_and(|g| !g.is_fully_transparent()));
2779+
let has_stroke = stroke.as_ref().is_some_and(|s| s.has_renderable_stroke()) && stroke_visible;
27902780

27912781
// No stroke means there's nothing to solidify. Fill-only layers are already in the desired form, so skip.
27922782
if !has_stroke {
@@ -4017,7 +4007,7 @@ mod document_message_handler_tests {
40174007
#[test]
40184008
fn pending_gradient_bakes_round_trip_through_serialization() {
40194009
let document = DocumentMessageHandler {
4020-
pending_gradient_bbox_bake: vec![(vec![NodeId(7)], NodeId(42), Gradient::default())],
4010+
pending_gradient_bbox_bake: vec![(vec![NodeId(7)], NodeId(42), graphic_types::migrations::legacy::Gradient::default())],
40214011
..Default::default()
40224012
};
40234013

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,22 @@ use graphene_std::raster::BlendMode;
1010
use graphene_std::raster_types::Image;
1111
use graphene_std::subpath::Subpath;
1212
use graphene_std::text::{Font, TypesettingConfig};
13-
use graphene_std::vector::style::{Fill, GradientSpreadMethod, GradientType, Stroke};
13+
use graphene_std::vector::style::{GradientSpreadMethod, GradientType, Stroke};
1414
use graphene_std::vector::{GradientStops, PointId, VectorModificationType};
1515

1616
#[impl_message(Message, DocumentMessage, GraphOperation)]
1717
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
1818
pub enum GraphOperationMessage {
19-
FillSet {
19+
FillColorSet {
2020
layer: LayerNodeIdentifier,
21-
fill: Fill,
21+
color: Option<Color>,
22+
},
23+
FillGradientSet {
24+
layer: LayerNodeIdentifier,
25+
gradient: GradientStops,
26+
gradient_type: GradientType,
27+
spread_method: GradientSpreadMethod,
28+
transform: DAffine2,
2229
},
2330
BlendingFillSet {
2431
layer: LayerNodeIdentifier,
@@ -28,10 +35,9 @@ pub enum GraphOperationMessage {
2835
layer: LayerNodeIdentifier,
2936
stops: GradientStops,
3037
},
31-
GradientLineSet {
38+
GradientTransformSet {
3239
layer: LayerNodeIdentifier,
33-
start: DVec2,
34-
end: DVec2,
40+
transform: DAffine2,
3541
},
3642
GradientTypeSet {
3743
layer: LayerNodeIdentifier,
@@ -54,6 +60,7 @@ pub enum GraphOperationMessage {
5460
},
5561
StrokeSet {
5662
layer: LayerNodeIdentifier,
63+
color: Option<Color>,
5764
stroke: Stroke,
5865
},
5966
TransformChange {

0 commit comments

Comments
 (0)