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