View that fits
Several layouts of one thing, of which it draws the first that fits the width: labels that give way to icons, a toolbar that moves tools behind a menu, tiles that shrink. Each layout is measured once and remembered.
Labels that give way
ViewThatFits::new(3).show(ui, |ui, layout| {
ui.horizontal(|ui| match layout {
0 => {
ui.add(Button::primary("Save changes").icon(glyph(ui.ctx(), "check")));
ui.add(Button::new("New document").icon(glyph(ui.ctx(), "plus")));
}
1 => {
ui.add(Button::primary("Save").icon(glyph(ui.ctx(), "check")));
ui.add(Button::new("New").icon(glyph(ui.ctx(), "plus")));
}
_ => {
ui.add(
Button::icon_only(glyph(ui.ctx(), "check"))
.role(fastframe_ui::ButtonRole::Primary),
);
ui.add(Button::icon_only(glyph(ui.ctx(), "plus")));
}
});
});
The story above is gallery/src/stories/view_that_fits.rs, running in your browser. Every snippet on this page is cut from it.