Skip to content

Commit 8eceaaf

Browse files
committed
Read min/max from figma
It used to be ignored
1 parent 7a5f080 commit 8eceaaf

File tree

12 files changed

+74
-6
lines changed

12 files changed

+74
-6
lines changed

crates/figma_import/src/figma_schema.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,10 @@ pub struct Node {
10131013
pub stroke_cap: StrokeCap,
10141014
pub bound_variables: Option<BoundVariables>,
10151015
pub explicit_variable_modes: Option<HashMap<String, String>>,
1016+
pub min_width: Option<f32>,
1017+
pub min_height: Option<f32>,
1018+
pub max_width: Option<f32>,
1019+
pub max_height: Option<f32>,
10161020
}
10171021

10181022
impl Node {

crates/figma_import/src/transform_flexbox.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ use dc_bundle::legacy_definition::view::text_style::{StyledTextRun, TextStyle};
5656
use dc_bundle::legacy_definition::view::view::{RenderMethod, ScrollInfo, View};
5757
use dc_bundle::legacy_definition::view::view_style::ViewStyle;
5858
use log::error;
59+
5960
use unicode_segmentation::UnicodeSegmentation;
6061

6162
// If an Auto content preview widget specifies a "Hug contents" sizing policy, this
@@ -116,6 +117,13 @@ fn compute_layout(
116117
style.layout_style.bounding_box.height = bounds.height();
117118
}
118119

120+
if let Some(max_width) = node.max_width {
121+
style.layout_style.max_width = DimensionProto::new_points(max_width);
122+
}
123+
if let Some(max_height) = node.max_height {
124+
style.layout_style.max_height = DimensionProto::new_points(max_height);
125+
}
126+
119127
// Frames can implement Auto Layout on their children.
120128
if let Some(frame) = node.frame() {
121129
style.layout_style.position_type = PositionType::Relative;
@@ -311,20 +319,32 @@ fn compute_layout(
311319
style.layout_style.height = DimensionProto::new_auto();
312320
}
313321
if let Some(bounds) = node.absolute_bounding_box {
314-
if !hug_width {
322+
if let Some(min_width) = node.min_width {
323+
error!("2. Node has min_width {:?}", min_width);
324+
style.layout_style.min_width = DimensionProto::new_points(min_width)
325+
} else if !hug_width {
315326
style.layout_style.min_width = DimensionProto::new_points(bounds.width().ceil());
316327
}
317-
if !hug_height {
328+
if let Some(min_height) = node.min_height {
329+
error!("2. Node has min_height {:?}", min_height);
330+
style.layout_style.min_height = DimensionProto::new_points(min_height)
331+
} else if !hug_height {
318332
style.layout_style.min_height = DimensionProto::new_points(bounds.height().ceil());
319333
}
320334
}
321335

322336
if let Some(size) = &node.size {
323337
if size.is_valid() {
324-
if !hug_width {
338+
if let Some(min_width) = node.min_width {
339+
error!("3. Node has min_width {:?}", min_width);
340+
style.layout_style.min_width = DimensionProto::new_points(min_width)
341+
} else if !hug_width {
325342
style.layout_style.min_width = DimensionProto::new_points(size.x());
326343
}
327-
if !hug_height {
344+
if let Some(min_height) = node.min_height {
345+
error!("3. Node has min_height {:?}", min_height);
346+
style.layout_style.min_height = DimensionProto::new_points(min_height)
347+
} else if !hug_height {
328348
style.layout_style.min_height = DimensionProto::new_points(size.y());
329349
}
330350
// Set fixed vector size
0 Bytes
Binary file not shown.

crates/layout/src/layout_style.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,43 @@
1515
use crate::into_taffy::{IntoTaffy, TryIntoTaffy};
1616
use dc_bundle::definition::element::DimensionExt;
1717
use dc_bundle::legacy_definition::layout::layout_style::LayoutStyle;
18+
use log::error;
1819

1920
impl TryIntoTaffy<taffy::prelude::Style> for &LayoutStyle {
2021
type Error = dc_bundle::Error;
2122
fn try_into_taffy(self) -> Result<taffy::prelude::Style, Self::Error> {
2223
let mut tstyle = taffy::prelude::Style::default();
2324

2425
tstyle.padding = (&self.padding).try_into_taffy()?;
25-
2626
tstyle.flex_grow = self.flex_grow;
2727
tstyle.flex_shrink = self.flex_shrink;
2828
tstyle.flex_basis = (&self.flex_basis).try_into_taffy()?;
2929
tstyle.gap.width = (&self.item_spacing).into_taffy();
3030
tstyle.gap.height = (&self.item_spacing).into_taffy();
3131

3232
tstyle.align_content = Some((&self.align_content).into_taffy());
33+
error!("Into taffy align_content {:?}", &self.align_content);
3334
tstyle.justify_content = Some((&self.justify_content).into_taffy());
35+
error!("Into taffy justify_content {:?}", &self.justify_content);
3436
tstyle.align_items = Some((&self.align_items).into_taffy());
37+
error!("Into taffy align_items {:?}", &self.align_items);
3538
tstyle.flex_direction = (&self.flex_direction).into_taffy();
39+
error!("Into taffy flex_direction {:?}", &self.flex_direction);
3640
tstyle.align_self = (&self.align_self).into_taffy();
41+
error!("Into taffy align_self {:?}", &self.align_self);
3742

3843
tstyle.size.width = (&self.width).try_into_taffy()?;
44+
error!("Into taffy width {:?}", &self.width);
3945
tstyle.size.height = (&self.height).try_into_taffy()?;
46+
error!("Into taffy height {:?}", &self.height);
4047
tstyle.min_size.width = (&self.min_width).try_into_taffy()?;
48+
error!("Into taffy min_width {:?}", &self.min_width);
4149
tstyle.min_size.height = (&self.min_height).try_into_taffy()?;
50+
error!("Into taffy min_height {:?}", &self.min_height);
4251
tstyle.max_size.width = (&self.max_width).try_into_taffy()?;
52+
error!("Into taffy max_width {:?}", &self.max_width);
4353
tstyle.max_size.height = (&self.max_height).try_into_taffy()?;
54+
error!("Into taffy max_height {:?}", &self.max_height);
4455

4556
// If we have a fixed size, use the bounding box since that takes into
4657
// account scale and rotation, and disregard min/max sizes.
@@ -49,11 +60,13 @@ impl TryIntoTaffy<taffy::prelude::Style> for &LayoutStyle {
4960
tstyle.size.width = taffy::prelude::Dimension::Points(self.bounding_box.width);
5061
tstyle.min_size.width = taffy::prelude::Dimension::Auto;
5162
tstyle.max_size.width = taffy::prelude::Dimension::Auto;
63+
error!("Into taffy override max/min width to auto");
5264
}
5365
if self.height.is_points()? {
5466
tstyle.size.height = taffy::prelude::Dimension::Points(self.bounding_box.height);
5567
tstyle.min_size.height = taffy::prelude::Dimension::Auto;
5668
tstyle.max_size.height = taffy::prelude::Dimension::Auto;
69+
error!("Into taffy override max/min height to auto");
5770
}
5871

5972
tstyle.position = (&self.position_type).into_taffy();
Binary file not shown.

integration-tests/validation/src/main/java/com/android/designcompose/testapp/validation/examples/AllExamples.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ val EXAMPLES: ArrayList<Triple<String, @Composable () -> Unit, String?>> =
2929
Triple("HelloVersion", { HelloVersion() }, HelloVersionDoc.javaClass.name),
3030
// Alphabetically ordered and trying to put similar tests together...
3131
Triple("Alignment", { AlignmentTest() }, AlignmentTestDoc.javaClass.name),
32+
Triple("AutoLayout", { AutoLayoutTest() }, AutoLayoutTestDoc.javaClass.name),
3233
Triple("Battleship", { BattleshipTest() }, BattleshipDoc.javaClass.name),
3334
Triple("Blend Modes", { BlendModeTest() }, BlendModeTestDoc.javaClass.name),
3435
Triple("Component Replace", { ComponentReplaceTest() }, ComponentReplaceDoc.javaClass.name),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.android.designcompose.testapp.validation.examples
18+
19+
import androidx.compose.runtime.Composable
20+
import com.android.designcompose.annotation.DesignComponent
21+
import com.android.designcompose.annotation.DesignDoc
22+
23+
@DesignDoc(id = "ArHVZAQIsKf2B9mATnVvLX")
24+
interface AutoLayoutTest {
25+
@DesignComponent(node = "#root") fun main()
26+
}
27+
28+
@Composable
29+
fun AutoLayoutTest() {
30+
AutoLayoutTestDoc.main()
31+
}
Loading
Loading

plugins/gradle-plugin-internal/src/main/java/com/android/designcompose/gradle/internal/InternalGradlePlugin.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ class InternalGradlePlugin : Plugin<Project> {
8989
test.inputs.properties(mapOf("isFetch" to isFetch))
9090
test.outputs.doNotCacheIf("Always fetch DCF files") { isFetch.get() }
9191

92-
9392
test.doFirst {
9493
if (isFetch.get()) {
9594
test.useJUnit {

0 commit comments

Comments
 (0)