Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions crates/core/fission-layout/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ pub trait TextMeasurer: Send + Sync {
) -> usize {
// Default: concatenate text and use plain hit_test
let text: String = runs.iter().map(|r| r.text.as_str()).collect();
let font_size = runs.first().map(|r| r.style.font_size).unwrap_or(13.0);
let font_size = runs.first().map(|r| r.style.font_size).unwrap_or(0.0);
self.hit_test(&text, font_size, None, x, y)
}

Expand Down Expand Up @@ -1595,9 +1595,9 @@ impl LayoutEngine {
let mut target_h = *height;

if target_w.is_some() && target_h.is_none() {
target_h = Some(target_w.unwrap() / ratio);
target_h = target_w.map(|w| w / ratio);
} else if target_h.is_some() && target_w.is_none() {
target_w = Some(target_h.unwrap() * ratio);
target_w = target_h.map(|h| h * ratio);
} else if target_w.is_none() && target_h.is_none() {
if local.is_width_bounded() || local.is_height_bounded() {
let (mut w, mut h) = if local.is_width_bounded() {
Expand Down Expand Up @@ -1655,20 +1655,24 @@ impl LayoutEngine {
})
.unwrap_or((None, None, None, None));
let mut child_constraints = base_child_constraints;
let stretch_width = child_constraints.min_w == child_constraints.max_w
&& child_width.is_none()
&& child_max_width.is_none();
let tight_width = child_constraints.min_w == child_constraints.max_w;
let stretch_width =
tight_width && child_width.is_none() && child_max_width.is_none();
if stretch_width {
child_constraints.min_w = child_constraints.max_w;
} else {
} else if tight_width
&& (child_width.is_some() || child_max_width.is_some())
{
child_constraints.min_w = 0.0;
}
let stretch_height = child_constraints.min_h == child_constraints.max_h
&& child_height.is_none()
&& child_max_height.is_none();
let tight_height = child_constraints.min_h == child_constraints.max_h;
let stretch_height =
tight_height && child_height.is_none() && child_max_height.is_none();
if stretch_height {
child_constraints.min_h = child_constraints.max_h;
} else {
} else if tight_height
&& (child_height.is_some() || child_max_height.is_some())
{
child_constraints.min_h = 0.0;
}
let child_size = self.layout_node_constraints(
Expand Down Expand Up @@ -2183,7 +2187,9 @@ impl LayoutEngine {
// SHRINK logic
let mut total_shrink_scaled = 0.0f32;
for entry in &measured {
let child = self.graph_state.node(entry.id).unwrap();
let Some(child) = self.graph_state.node(entry.id) else {
continue;
};
let main_size = if is_row {
entry.size.width
} else {
Expand All @@ -2195,7 +2201,9 @@ impl LayoutEngine {
if total_shrink_scaled > 0.0 {
let overflow = (final_children_main + gap_total) - max_main;
for entry in &mut measured {
let child = self.graph_state.node(entry.id).unwrap();
let Some(child) = self.graph_state.node(entry.id) else {
continue;
};
let main_size = if is_row {
entry.size.width
} else {
Expand Down Expand Up @@ -2513,7 +2521,9 @@ impl LayoutEngine {
let mut auto_col = 0;

for child_id in &flow_children {
let child = self.graph_state.node(*child_id).unwrap();
let Some(child) = self.graph_state.node(*child_id) else {
continue;
};
let (row, col) = if let LayoutOp::GridItem {
row_start,
col_start,
Expand Down
4 changes: 2 additions & 2 deletions crates/tools/fission-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl TextMeasurer for MockTextMeasurer {
// Avoid division by zero
let safe_w = w.max(char_width);
let lines = (full_width / safe_w).ceil();
return (w, lines * line_height);
return (safe_w, lines * line_height);
}
}
(full_width, line_height)
Expand Down Expand Up @@ -70,7 +70,7 @@ impl TextMeasurer for MockTextMeasurer {
if full_w > w {
let safe_w = w.max(char_width);
let lines = (full_w / safe_w).ceil();
return (w, lines * line_height);
return (safe_w, lines * line_height);
}
}
(full_w.max(10.0), line_height)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ fn test_stepper_button_layout() {
}

#[test]
#[ignore] // FIXME: SplitView layout stretch issue
fn test_email_list_width() {
struct InboxLayout;
impl Widget<State> for InboxLayout {
Expand All @@ -91,7 +90,7 @@ fn test_email_list_width() {
second: Box::new(
Container::new(Text::new("Detail").into_node()).into_node(),
),
split_ratio: 0.3,
split_ratio: 0.4,
on_resize: None,
}
.build(_ctx, _view),
Expand Down
Loading