Skip to content

Commit

Permalink
Convert the positioning enums and LayoutView to Proto
Browse files Browse the repository at this point in the history
Fixes #1725
Fixes #1723
  • Loading branch information
timothyfroehlich committed Nov 7, 2024
1 parent 04f4826 commit 460e637
Show file tree
Hide file tree
Showing 78 changed files with 548 additions and 676 deletions.
58 changes: 58 additions & 0 deletions crates/dc_bundle/src/definition/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,63 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use crate::definition::element::{DimensionProto, DimensionRect, Size};
use crate::definition::layout::item_spacing::ItemSpacingType;
use crate::Error;
use crate::Error::MissingFieldError;

include!(concat!(env!("OUT_DIR"), "/designcompose.definition.layout.rs"));

impl ItemSpacing {
pub fn new_default() -> Option<Self> {
Some(Self { item_spacing_type: Some(ItemSpacingType::Fixed(0)) })
}
}

impl LayoutStyle {
pub fn bounding_box(&self) -> Result<&Size, Error> {
self.bounding_box.as_ref().ok_or(MissingFieldError { field: "bounding_box".to_string() })
}

pub(crate) fn new_default() -> LayoutStyle {
LayoutStyle {
margin: DimensionRect::new(),
padding: DimensionRect::new(),
item_spacing: ItemSpacing::new_default(),
top: DimensionProto::new_undefined(),
left: DimensionProto::new_undefined(),
bottom: DimensionProto::new_undefined(),
right: DimensionProto::new_undefined(),
width: DimensionProto::new_undefined(),
height: DimensionProto::new_undefined(),
min_width: DimensionProto::new_undefined(),
max_width: DimensionProto::new_undefined(),
min_height: DimensionProto::new_undefined(),
max_height: DimensionProto::new_undefined(),
bounding_box: Some(Size::default()),
flex_grow: 0.0,
flex_shrink: 0.0,
flex_basis: DimensionProto::new_undefined(),
align_self: AlignSelf::Auto.into(),
align_content: AlignContent::Stretch.into(),
align_items: AlignItems::Stretch.into(),
flex_direction: FlexDirection::Row.into(),
justify_content: JustifyContent::FlexStart.into(),
position_type: PositionType::Relative.into(),
}
}
}

impl ItemSpacing {
pub fn fixed(value: i32) -> Self {
Self { item_spacing_type: Some(item_spacing::ItemSpacingType::Fixed(value)) }
}
pub fn auto(width: i32, height: i32) -> Self {
Self {
item_spacing_type: Some(item_spacing::ItemSpacingType::Auto(item_spacing::Auto {
width,
height,
})),
}
}
}
2 changes: 0 additions & 2 deletions crates/dc_bundle/src/legacy_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ use std::sync::Arc;
// To help keep the legacy definition files clear we alias `crate::definition`, which is the base
// module for the generated protobuf files to `proto`, so that all of the protobuf-generated types
// inside `legacy_definition` must be prepended with `proto::`
pub(crate) use crate::definition as proto;
use crate::definition::element::ImageKey;
use crate::definition::element::VariableMap;
use crate::legacy_definition::element::node::NodeQuery;

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

Expand Down
122 changes: 0 additions & 122 deletions crates/dc_bundle/src/legacy_definition/layout/layout_style.rs

This file was deleted.

Loading

0 comments on commit 460e637

Please sign in to comment.