use crate::responsive::responsive_ext::ResponsiveExt;
#[must_use]
pub struct Flex {
pub(crate) flex: egui_flex::Flex,
wrap_on_mobile: bool,
}
impl Flex {
pub fn row() -> Self {
Self {
flex: egui_flex::Flex::horizontal(),
wrap_on_mobile: true,
}
}
pub fn column() -> Self {
Self {
flex: egui_flex::Flex::vertical(),
wrap_on_mobile: false,
}
}
pub fn gap(self, gap: f32) -> Self {
Self {
flex: self.flex.gap(egui::vec2(gap, gap)),
wrap_on_mobile: self.wrap_on_mobile,
}
}
pub fn wrap(self) -> Self {
Self {
flex: self.flex.wrap(true),
wrap_on_mobile: self.wrap_on_mobile,
}
}
pub fn no_wrap_on_mobile(self) -> Self {
Self {
flex: self.flex,
wrap_on_mobile: false,
}
}
pub fn align_start(self) -> Self {
Self {
flex: self.flex.align_items(egui_flex::FlexAlign::Start),
wrap_on_mobile: self.wrap_on_mobile,
}
}
pub fn align_center(self) -> Self {
Self {
flex: self.flex.align_items(egui_flex::FlexAlign::Center),
wrap_on_mobile: self.wrap_on_mobile,
}
}
pub fn align_end(self) -> Self {
Self {
flex: self.flex.align_items(egui_flex::FlexAlign::End),
wrap_on_mobile: self.wrap_on_mobile,
}
}
pub fn align_stretch(self) -> Self {
Self {
flex: self.flex.align_items(egui_flex::FlexAlign::Stretch),
wrap_on_mobile: self.wrap_on_mobile,
}
}
pub fn justify_start(self) -> Self {
Self {
flex: self.flex.justify(egui_flex::FlexJustify::Start),
wrap_on_mobile: self.wrap_on_mobile,
}
}
pub fn justify_center(self) -> Self {
Self {
flex: self.flex.justify(egui_flex::FlexJustify::Center),
wrap_on_mobile: self.wrap_on_mobile,
}
}
pub fn justify_end(self) -> Self {
Self {
flex: self.flex.justify(egui_flex::FlexJustify::End),
wrap_on_mobile: self.wrap_on_mobile,
}
}
pub fn justify_between(self) -> Self {
Self {
flex: self.flex.justify(egui_flex::FlexJustify::SpaceBetween),
wrap_on_mobile: self.wrap_on_mobile,
}
}
pub fn justify_around(self) -> Self {
Self {
flex: self.flex.justify(egui_flex::FlexJustify::SpaceAround),
wrap_on_mobile: self.wrap_on_mobile,
}
}
pub fn justify_evenly(self) -> Self {
Self {
flex: self.flex.justify(egui_flex::FlexJustify::SpaceEvenly),
wrap_on_mobile: self.wrap_on_mobile,
}
}
pub fn w_full(self) -> Self {
Self {
flex: self.flex.w_full(),
wrap_on_mobile: self.wrap_on_mobile,
}
}
pub fn h_full(self) -> Self {
Self {
flex: self.flex.h_full(),
wrap_on_mobile: self.wrap_on_mobile,
}
}
pub fn width(self, width: f32) -> Self {
Self {
flex: self.flex.width(width),
wrap_on_mobile: self.wrap_on_mobile,
}
}
pub fn height(self, height: f32) -> Self {
Self {
flex: self.flex.height(height),
wrap_on_mobile: self.wrap_on_mobile,
}
}
pub fn grow_items(self, grow: f32) -> Self {
Self {
flex: self.flex.grow_items(grow),
wrap_on_mobile: self.wrap_on_mobile,
}
}
pub fn show<R>(
self,
ui: &mut egui::Ui,
f: impl FnOnce(&mut super::flex_instance::FlexInst) -> R,
) -> egui::InnerResponse<R> {
let wrap = self.wrap_on_mobile
&& (ui.on_mobile()
|| ui.available_width()
< crate::responsive::breakpoint::Breakpoint::MOBILE_MAX_WIDTH);
let flex = if wrap {
self.flex.wrap(true)
} else {
self.flex
};
flex.show(ui, |instance| {
let mut inst = super::flex_instance::FlexInst(instance);
f(&mut inst)
})
}
}