Skip to content

Commit

Permalink
Reduce churn in PR
Browse files Browse the repository at this point in the history
  • Loading branch information
alice-i-cecile committed Jun 11, 2022
1 parent 504eee2 commit c046f96
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions src/flexbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ impl Forest {
};

let node_inner_size = Size {
width: Some(node_size.width.unwrap_or_default() - padding_border.horizontal_axis_sum()),
height: Some(node_size.height.unwrap_or_default() - padding_border.vertical_axis_sum()),
width: node_size.width.maybe_sub(padding_border.horizontal_axis_sum()),
height: node_size.height.maybe_sub(padding_border.vertical_axis_sum()),
};

let container_size = Size::zero();
Expand Down Expand Up @@ -307,19 +307,19 @@ impl Forest {
parent_size: Size<Option<f32>>,
constants: &AlgoConstants,
) -> Size<Option<f32>> {
let width = match node_size.width {
Some(width) => Some(width),
None => parent_size.width.maybe_sub(constants.margin.horizontal_axis_sum()),
};

let height = match node_size.height {
Some(height) => Some(height),
None => parent_size.height.maybe_sub(constants.margin.vertical_axis_sum()),
};

Size {
width: Some(
node_size
.width
.unwrap_or(parent_size.width.unwrap_or_default() - constants.margin.horizontal_axis_sum())
- constants.padding_border.horizontal_axis_sum(),
),
height: Some(
node_size
.height
.unwrap_or(parent_size.height.unwrap_or_default() - constants.margin.vertical_axis_sum())
- constants.padding_border.vertical_axis_sum(),
),
width: width.maybe_sub(constants.padding_border.horizontal_axis_sum()),
height: height.maybe_sub(constants.padding_border.vertical_axis_sum()),
}
}

Expand Down Expand Up @@ -610,10 +610,7 @@ impl Forest {
})
.sum();

let initial_free_space = match constants.node_inner_size.main(constants.dir) {
Some(inner_size) => inner_size - used_space,
None => 0.0,
};
let initial_free_space = constants.node_inner_size.main(constants.dir).maybe_sub(used_space).unwrap_or(0.0);

// 4. Loop

Expand Down Expand Up @@ -711,7 +708,7 @@ impl Forest {

let total_violation = unfrozen.iter_mut().fold(0.0, |acc, child| -> f32 {
// TODO - not really spec abiding but needs to be done somewhere. probably somewhere else though.
// The following logic was developed not from the spec but by trail and error looking into how
// The following logic was developed not from the spec but by trial and error looking into how
// webkit handled various scenarios. Can probably be solved better by passing in
// min-content max-content constraints from the top. Need to figure out correct thing to do here as
// just piling on more conditionals.
Expand Down Expand Up @@ -1426,10 +1423,10 @@ impl Forest {
let child_position_bottom = child_style.position.bottom.resolve(container_height);
let child_margin_bottom = child_style.margin.bottom.resolve(container_height);

let start = Some(child_position_start.unwrap_or_default() + child_margin_start.unwrap_or_default());
let end = Some(child_position_end.unwrap_or_default() + child_margin_end.unwrap_or_default());
let top = Some(child_position_top.unwrap_or_default() + child_margin_top.unwrap_or_default());
let bottom = Some(child_position_bottom.unwrap_or_default() + child_margin_bottom.unwrap_or_default());
let start = child_position_start.maybe_add(child_margin_start);
let end = child_position_end.maybe_add(child_margin_end);
let top = child_position_top.maybe_add(child_margin_top);
let bottom = child_position_bottom.maybe_add(child_margin_bottom);

let (start_main, end_main) = if constants.is_row { (start, end) } else { (top, bottom) };
let (start_cross, end_cross) = if constants.is_row { (top, bottom) } else { (start, end) };
Expand Down

0 comments on commit c046f96

Please sign in to comment.