Skip to content

Commit 6e408a6

Browse files
committed
Convert gentests to use custom Measurable
1 parent 3d913f3 commit 6e408a6

File tree

926 files changed

+1937
-2821
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

926 files changed

+1937
-2821
lines changed

scripts/gentest/src/main.rs

Lines changed: 67 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ fn generate_test(name: impl AsRef<str>, description: &Value) -> TokenStream {
209209
fn #name() {
210210
#[allow(unused_imports)]
211211
use taffy::{tree::{Layout, MeasureFunc}, prelude::*, Taffy};
212-
let mut taffy : Taffy<MeasureFunc<()>> = Taffy::new();
212+
let mut taffy : Taffy<super::TextMeasure> = Taffy::new();
213213
#set_rounding_mode
214214
#node_description
215215
taffy.compute_layout(node, #available_space).unwrap();
@@ -870,66 +870,76 @@ fn generate_generic_measure_function() -> TokenStream {
870870
Vertical,
871871
}
872872

873-
// WARNING: This function is generated by the gentest script. Do not edit directly
874-
#[allow(dead_code)]
875-
fn measure_standard_text(
876-
known_dimensions: taffy::geometry::Size<Option<f32>>,
877-
available_space: taffy::geometry::Size<taffy::style::AvailableSpace>,
878-
text_content: &str,
873+
struct TextMeasure {
874+
text_content: &'static str,
879875
writing_mode: WritingMode,
880876
_aspect_ratio: Option<f32>,
881-
) -> taffy::geometry::Size<f32> {
882-
use taffy::geometry::AbsoluteAxis;
883-
use taffy::prelude::*;
884-
const ZWS: char = '\u{200B}';
885-
const H_WIDTH: f32 = 10.0;
886-
const H_HEIGHT: f32 = 10.0;
887-
888-
if let Size { width: Some(width), height: Some(height) } = known_dimensions {
889-
return Size { width, height };
890-
}
877+
}
891878

892-
let inline_axis = match writing_mode {
893-
WritingMode::Horizontal => AbsoluteAxis::Horizontal,
894-
WritingMode::Vertical => AbsoluteAxis::Vertical,
895-
};
896-
let block_axis = inline_axis.other_axis();
879+
// WARNING: This function is generated by the gentest script. Do not edit directly
880+
#[allow(dead_code)]
881+
impl taffy::tree::Measurable for TextMeasure {
882+
type Context = ();
883+
884+
fn measure(
885+
&mut self,
886+
known_dimensions: taffy::geometry::Size<Option<f32>>,
887+
available_space: taffy::geometry::Size<taffy::style::AvailableSpace>,
888+
_context: &mut (),
889+
) -> taffy::geometry::Size<f32> {
890+
use taffy::geometry::AbsoluteAxis;
891+
use taffy::prelude::*;
892+
const ZWS: char = '\u{200B}';
893+
const H_WIDTH: f32 = 10.0;
894+
const H_HEIGHT: f32 = 10.0;
895+
896+
if let Size { width: Some(width), height: Some(height) } = known_dimensions {
897+
return Size { width, height };
898+
}
897899

898-
let lines: Vec<&str> = text_content.split(ZWS).collect();
899-
if lines.is_empty() {
900-
return Size::ZERO;
901-
}
900+
let inline_axis = match self.writing_mode {
901+
WritingMode::Horizontal => AbsoluteAxis::Horizontal,
902+
WritingMode::Vertical => AbsoluteAxis::Vertical,
903+
};
904+
let block_axis = inline_axis.other_axis();
902905

903-
let min_line_length: usize = lines.iter().map(|line| line.len()).max().unwrap_or(0);
904-
let max_line_length: usize = lines.iter().map(|line| line.len()).sum();
905-
let inline_size =
906-
known_dimensions.get_abs(inline_axis).unwrap_or_else(|| match available_space.get_abs(inline_axis) {
907-
AvailableSpace::MinContent => min_line_length as f32 * H_WIDTH,
908-
AvailableSpace::MaxContent => max_line_length as f32 * H_WIDTH,
909-
AvailableSpace::Definite(inline_size) => {
910-
inline_size.min(max_line_length as f32 * H_WIDTH).max(min_line_length as f32 * H_WIDTH)
906+
let lines: Vec<&str> = self.text_content.split(ZWS).collect();
907+
if lines.is_empty() {
908+
return Size::ZERO;
909+
}
910+
911+
let min_line_length: usize = lines.iter().map(|line| line.len()).max().unwrap_or(0);
912+
let max_line_length: usize = lines.iter().map(|line| line.len()).sum();
913+
let inline_size = known_dimensions.get_abs(inline_axis).unwrap_or_else(|| {
914+
match available_space.get_abs(inline_axis) {
915+
AvailableSpace::MinContent => min_line_length as f32 * H_WIDTH,
916+
AvailableSpace::MaxContent => max_line_length as f32 * H_WIDTH,
917+
AvailableSpace::Definite(inline_size) => {
918+
inline_size.min(max_line_length as f32 * H_WIDTH).max(min_line_length as f32 * H_WIDTH)
919+
}
911920
}
912921
});
913-
let block_size = known_dimensions.get_abs(block_axis).unwrap_or_else(|| {
914-
let inline_line_length = (inline_size / H_WIDTH).floor() as usize;
915-
let mut line_count = 1;
916-
let mut current_line_length = 0;
917-
for line in &lines {
918-
if current_line_length + line.len() > inline_line_length {
919-
if current_line_length > 0 {
920-
line_count += 1
922+
let block_size = known_dimensions.get_abs(block_axis).unwrap_or_else(|| {
923+
let inline_line_length = (inline_size / H_WIDTH).floor() as usize;
924+
let mut line_count = 1;
925+
let mut current_line_length = 0;
926+
for line in &lines {
927+
if current_line_length + line.len() > inline_line_length {
928+
if current_line_length > 0 {
929+
line_count += 1
930+
};
931+
current_line_length = line.len();
932+
} else {
933+
current_line_length += line.len();
921934
};
922-
current_line_length = line.len();
923-
} else {
924-
current_line_length += line.len();
925-
};
926-
}
927-
(line_count as f32) * H_HEIGHT
928-
});
935+
}
936+
(line_count as f32) * H_HEIGHT
937+
});
929938

930-
match writing_mode {
931-
WritingMode::Horizontal => Size { width: inline_size, height: block_size },
932-
WritingMode::Vertical => Size { width: block_size, height: inline_size },
939+
match self.writing_mode {
940+
WritingMode::Horizontal => Size { width: inline_size, height: block_size },
941+
WritingMode::Vertical => Size { width: block_size, height: inline_size },
942+
}
933943
}
934944
}
935945
)
@@ -947,9 +957,10 @@ fn generate_measure_function(text_content: &str, writing_mode: Option<&str>, asp
947957
};
948958

949959
quote!(
950-
taffy::tree::MeasureFunc::Raw(|known_dimensions, available_space, _context| {
951-
const TEXT : &str = #text_content;
952-
super::measure_standard_text(known_dimensions, available_space, TEXT, #writing_mode_token, #aspect_ratio_token)
953-
})
960+
super::TextMeasure {
961+
text_content: #text_content,
962+
writing_mode: #writing_mode_token,
963+
_aspect_ratio: #aspect_ratio_token,
964+
}
954965
)
955966
}

tests/generated/absolute_aspect_ratio_aspect_ratio_overrides_height_of_full_inset.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_aspect_ratio_fill_height.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_aspect_ratio_fill_height_from_inset.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_aspect_ratio_fill_max_height.rs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_aspect_ratio_fill_max_width.rs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_aspect_ratio_fill_min_height.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_aspect_ratio_fill_min_width.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_aspect_ratio_fill_width.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_aspect_ratio_fill_width_from_inset.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_aspect_ratio_height_overrides_inset.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_aspect_ratio_width_overrides_inset.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_child_with_cross_margin.rs

Lines changed: 6 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_child_with_main_margin.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_child_with_max_height.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_child_with_max_height_larger_shrinkable_grandchild.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_layout_align_items_and_justify_content_center.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_layout_align_items_and_justify_content_center_and_bottom_position.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_layout_align_items_and_justify_content_center_and_left_position.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_layout_align_items_and_justify_content_center_and_right_position.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_layout_align_items_and_justify_content_center_and_top_position.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_layout_align_items_and_justify_content_flex_end.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_layout_align_items_center.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_layout_align_items_center_on_child_only.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/generated/absolute_layout_child_order.rs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)