Skip to content

Commit

Permalink
Refactor: Move meter data to definition package
Browse files Browse the repository at this point in the history
Moves the meter data types from the legacy_definition package to the definition package.
This change simplifies the codebase by removing the redundant legacy_definition package.

Additionally, this change refactors the DesignCompose code to use the new meter data types.
  • Loading branch information
timothyfroehlich committed Nov 13, 2024
1 parent 2b00867 commit 9d77c6b
Show file tree
Hide file tree
Showing 45 changed files with 168 additions and 184 deletions.
1 change: 0 additions & 1 deletion crates/dc_bundle/src/legacy_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use crate::definition::element::VariableMap;
use crate::legacy_definition::element::node::NodeQuery;

pub mod element;
pub mod plugin;
pub mod view;

/// EncodedImageMap contains a mapping from ImageKey to network bytes. It can create an
Expand Down
17 changes: 0 additions & 17 deletions crates/dc_bundle/src/legacy_definition/plugin.rs

This file was deleted.

2 changes: 1 addition & 1 deletion crates/dc_bundle/src/legacy_definition/view/node_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::definition::modifier::{
BlendMode, FilterOp, TextAlign, TextAlignVertical, TextOverflow,
};
use crate::definition::modifier::{BoxShadow, LayoutTransform, TextShadow};
use crate::legacy_definition::plugin::meter_data::MeterData;
use crate::definition::plugin::meter_data::MeterData;
use serde::{Deserialize, Serialize};

#[derive(Copy, Clone, PartialEq, Debug, Serialize, Deserialize)]
Expand Down
27 changes: 27 additions & 0 deletions crates/figma_import/src/figma_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use std::collections::HashMap;

use dc_bundle::definition::element;
use dc_bundle::definition::element::Color;
use dc_bundle::definition::element::FloatColor;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -1372,3 +1373,29 @@ pub struct VariablesResponse {
pub status: i32,
pub meta: VariablesMeta,
}

pub(crate) fn parse_path(path: &Path) -> Option<element::Path> {
let mut output = element::Path::new();
for segment in svgtypes::SimplifyingPathParser::from(path.path.as_str()) {
match segment {
Ok(svgtypes::SimplePathSegment::MoveTo { x, y }) => {
output.move_to(x as f32, y as f32);
}
Ok(svgtypes::SimplePathSegment::LineTo { x, y }) => {
output.line_to(x as f32, y as f32);
}
Ok(svgtypes::SimplePathSegment::CurveTo { x1, y1, x2, y2, x, y }) => {
output.cubic_to(x1 as f32, y1 as f32, x2 as f32, y2 as f32, x as f32, y as f32);
}
Ok(svgtypes::SimplePathSegment::Quadratic { x1, y1, x, y }) => {
output.quad_to(x1 as f32, y1 as f32, x as f32, y as f32);
}
Ok(svgtypes::SimplePathSegment::ClosePath) => {
output.close();
}
Err(_) => return None,
}
}
output.with_winding_rule(path.winding_rule.into());
Some(output)
}
2 changes: 1 addition & 1 deletion crates/figma_import/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ mod extended_layout_schema;
mod fetch;
mod figma_schema;
mod image_context;
pub mod meter_schema;
pub mod reaction_schema;
pub mod toolkit_style;
pub mod tools;
mod transform_flexbox;
mod variable_utils;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! `toolkit_style` contains all of the style-related types that `toolkit_schema::View`
//! uses.
use crate::figma_schema;

use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct RotationMeterData {
pub struct RotationMeterJson {
pub enabled: bool,
pub start: f32,
pub end: f32,
Expand All @@ -28,7 +31,7 @@ pub struct RotationMeterData {

#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct ArcMeterData {
pub struct ArcMeterJson {
pub enabled: bool,
pub start: f32,
pub end: f32,
Expand All @@ -39,7 +42,7 @@ pub struct ArcMeterData {

#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct ProgressBarMeterData {
pub struct ProgressBarMeterJson {
pub enabled: bool,
pub discrete: bool,
pub discrete_value: f32,
Expand All @@ -53,7 +56,7 @@ pub struct ProgressBarMeterData {

#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct ProgressMarkerMeterData {
pub struct ProgressMarkerMeterJson {
pub enabled: bool,
pub discrete: bool,
pub discrete_value: f32,
Expand All @@ -69,22 +72,32 @@ pub struct ProgressMarkerMeterData {
pub end_y: f32,
}

// Schema for progress vector data that we write to serialized data
// // Schema for progress vector data that we write to serialized data
// #[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
// #[serde(rename_all = "camelCase")]
// pub struct ProgressVectorMeterJson {
// pub enabled: bool,
// pub discrete: bool,
// pub discrete_value: f32,
// }

// Schema for progress vector data that we read from Figma plugin data
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct ProgressVectorMeterData {
pub struct ProgressVectorMeterJson {
pub enabled: bool,
pub discrete: bool,
pub discrete_value: f32,
pub paths: Vec<figma_schema::Path>,
}

// Schema for dials & gauges data that we write to serialized data
// Schema for dials & gauges Figma plugin data
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum MeterData {
ArcData(ArcMeterData),
RotationData(RotationMeterData),
ProgressBarData(ProgressBarMeterData),
ProgressMarkerData(ProgressMarkerMeterData),
ProgressVectorData(ProgressVectorMeterData),
pub enum MeterJson {
ArcJson(ArcMeterJson),
RotationJson(RotationMeterJson),
ProgressBarJson(ProgressBarMeterJson),
ProgressMarkerJson(ProgressMarkerMeterJson),
ProgressVectorJson(ProgressVectorMeterJson),
}
14 changes: 5 additions & 9 deletions crates/figma_import/src/reflection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,19 @@ pub fn registry() -> serde_reflection::Result<serde_reflection::Registry> {
.trace_type::<dc_bundle::definition::layout::GridLayoutType>(&samples)
.expect("couldn't trace GridLayoutType");
tracer
.trace_type::<dc_bundle::legacy_definition::plugin::meter_data::RotationMeterData>(&samples)
.trace_type::<dc_bundle::definition::plugin::RotationMeterData>(&samples)
.expect("couldn't trace RotationMeterData");
tracer
.trace_type::<dc_bundle::legacy_definition::plugin::meter_data::ArcMeterData>(&samples)
.trace_type::<dc_bundle::definition::plugin::ArcMeterData>(&samples)
.expect("couldn't trace ArcMeterData");
tracer
.trace_type::<dc_bundle::legacy_definition::plugin::meter_data::ProgressBarMeterData>(
&samples,
)
.trace_type::<dc_bundle::definition::plugin::ProgressBarMeterData>(&samples)
.expect("couldn't trace ProgressBarMeterData");
tracer
.trace_type::<dc_bundle::legacy_definition::plugin::meter_data::ProgressVectorMeterData>(
&samples,
)
.trace_type::<dc_bundle::definition::plugin::ProgressVectorMeterData>(&samples)
.expect("couldn't trace ProgressVectorMeterData");
tracer
.trace_type::<dc_bundle::legacy_definition::plugin::meter_data::MeterData>(&samples)
.trace_type::<dc_bundle::definition::plugin::meter_data::MeterData>(&samples)
.expect("couldn't trace MeterData");
tracer
.trace_type::<dc_bundle::definition::layout::PositionType>(&samples)
Expand Down
62 changes: 0 additions & 62 deletions crates/figma_import/src/toolkit_style.rs

This file was deleted.

Loading

0 comments on commit 9d77c6b

Please sign in to comment.