Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove fill_major_axis flex attribute #812

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
42 changes: 1 addition & 41 deletions masonry/src/widget/flex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub struct Flex {
direction: Axis,
cross_alignment: CrossAxisAlignment,
main_alignment: MainAxisAlignment,
fill_major_axis: bool,
children: Vec<Child>,
old_bc: BoxConstraints,
gap: Option<f64>,
Expand Down Expand Up @@ -124,7 +123,6 @@ impl Flex {
children: Vec::new(),
cross_alignment: CrossAxisAlignment::Center,
main_alignment: MainAxisAlignment::Start,
fill_major_axis: false,
old_bc: BoxConstraints::tight(Size::ZERO),
gap: None,
}
Expand Down Expand Up @@ -157,13 +155,6 @@ impl Flex {
self
}

/// Builder-style method for setting whether the container must expand
/// to fill the available space on its main axis.
pub fn must_fill_main_axis(mut self, fill: bool) -> Self {
self.fill_major_axis = fill;
self
}

/// Builder-style method for setting the spacing along the
/// major axis between any two elements in logical pixels.
///
Expand Down Expand Up @@ -320,13 +311,6 @@ impl Flex {
this.ctx.request_layout();
}

/// Set whether the container must expand to fill the available space on
/// its main axis.
pub fn set_must_fill_main_axis(this: &mut WidgetMut<'_, Self>, fill: bool) {
this.widget.fill_major_axis = fill;
this.ctx.request_layout();
}

/// Set the spacing along the major axis between any two elements in logical pixels.
///
/// Equivalent to the css [gap] property.
Expand Down Expand Up @@ -1051,13 +1035,7 @@ impl Widget for Flex {
}

// figure out if we have extra space on major axis, and if so how to use it
let extra = if self.fill_major_axis {
(remaining - major_flex).max(0.0)
} else {
// if we are *not* expected to fill our available space this usually
// means we don't have any extra, unless dictated by our constraints.
(self.direction.major(bc.min()) - (major_non_flex + major_flex)).max(0.0)
};
let extra = (remaining - major_flex).max(0.0);

let mut spacing = Spacing::new(self.main_alignment, extra, self.children.len());

Expand Down Expand Up @@ -1392,15 +1370,6 @@ mod tests {
Flex::set_main_axis_alignment(&mut flex, MainAxisAlignment::SpaceAround);
});
assert_render_snapshot!(harness, "row_main_axis_spaceAround");

// FILL MAIN AXIS
// TODO - This doesn't seem to do anything?

harness.edit_root_widget(|mut flex| {
let mut flex = flex.downcast::<Flex>();
Flex::set_must_fill_main_axis(&mut flex, true);
});
assert_render_snapshot!(harness, "row_fill_main_axis");
}

#[test]
Expand Down Expand Up @@ -1497,15 +1466,6 @@ mod tests {
Flex::set_main_axis_alignment(&mut flex, MainAxisAlignment::SpaceAround);
});
assert_render_snapshot!(harness, "col_main_axis_spaceAround");

// FILL MAIN AXIS
// TODO - This doesn't seem to do anything?

harness.edit_root_widget(|mut flex| {
let mut flex = flex.downcast::<Flex>();
Flex::set_must_fill_main_axis(&mut flex, true);
});
assert_render_snapshot!(harness, "col_fill_main_axis");
}

#[test]
Expand Down

This file was deleted.

This file was deleted.

4 changes: 1 addition & 3 deletions xilem/examples/http_cats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ impl HttpCats {
portal(sized_box(info_area).expand_width()).flex(1.),
))
.direction(Axis::Horizontal)
.must_fill_major_axis(true)
.flex(1.),
))
.must_fill_major_axis(true),
)),
worker(
worker_value,
|proxy, mut rx| async move {
Expand Down
5 changes: 3 additions & 2 deletions xilem/examples/stopwatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ fn app_logic(data: &mut Stopwatch) -> impl WidgetView<Stopwatch> {
flex((
FlexSpacer::Fixed(5.0),
label(get_formatted_duration(data.displayed_duration)).text_size(70.0),
flex((lap_reset_button(data), start_stop_button(data))).direction(Axis::Horizontal),
flex((lap_reset_button(data), start_stop_button(data)))
.direction(Axis::Horizontal)
.main_axis_alignment(MainAxisAlignment::Center),
FlexSpacer::Fixed(1.0),
laps_section(data),
label(data.displayed_error.as_ref()),
Expand Down Expand Up @@ -173,7 +175,6 @@ fn single_lap(
.direction(Axis::Horizontal)
.cross_axis_alignment(CrossAxisAlignment::Center)
.main_axis_alignment(MainAxisAlignment::Start)
.must_fill_major_axis(true)
}

fn start_stop_button(data: &mut Stopwatch) -> impl WidgetView<Stopwatch> {
Expand Down
1 change: 0 additions & 1 deletion xilem/examples/variable_clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ impl TimeZone {
},
),
))
.must_fill_major_axis(true)
.direction(Axis::Horizontal)
.flex(1.),
flex((
Expand Down
11 changes: 0 additions & 11 deletions xilem/src/view/flex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub fn flex<State, Action, Seq: FlexSequence<State, Action>>(
axis: Axis::Vertical,
cross_axis_alignment: CrossAxisAlignment::Center,
main_axis_alignment: MainAxisAlignment::Start,
fill_major_axis: false,
gap: None,
phantom: PhantomData,
}
Expand All @@ -33,7 +32,6 @@ pub struct Flex<Seq, State, Action = ()> {
axis: Axis,
cross_axis_alignment: CrossAxisAlignment,
main_axis_alignment: MainAxisAlignment,
fill_major_axis: bool,
gap: Option<f64>,
phantom: PhantomData<fn() -> (State, Action)>,
}
Expand All @@ -53,11 +51,6 @@ impl<Seq, State, Action> Flex<Seq, State, Action> {
self
}

pub fn must_fill_major_axis(mut self, fill_major_axis: bool) -> Self {
self.fill_major_axis = fill_major_axis;
self
}

/// Set the spacing along the major axis between any two elements in logical pixels.
///
/// Equivalent to the css [gap] property.
Expand Down Expand Up @@ -101,7 +94,6 @@ where
let mut widget = widget::Flex::for_axis(self.axis)
.raw_gap(self.gap)
.cross_axis_alignment(self.cross_axis_alignment)
.must_fill_main_axis(self.fill_major_axis)
.main_axis_alignment(self.main_axis_alignment);
let seq_state = self.sequence.seq_build(ctx, &mut elements);
for child in elements.into_inner() {
Expand Down Expand Up @@ -132,9 +124,6 @@ where
if prev.main_axis_alignment != self.main_axis_alignment {
widget::Flex::set_main_axis_alignment(&mut element, self.main_axis_alignment);
}
if prev.fill_major_axis != self.fill_major_axis {
widget::Flex::set_must_fill_main_axis(&mut element, self.fill_major_axis);
}
if prev.gap != self.gap {
widget::Flex::set_raw_gap(&mut element, self.gap);
}
Expand Down
Loading