pub struct VerticalStack { /* private fields */ }Expand description
A component that displays multiple panels stacked vertically, each with resize handles, all contained within a scroll area.
This is very useful for layouts that need multiple ‘panel’ views.
The amount of panels is dynamic and can be added or removed at runtime.
Example use:
use egui_vertical_stack::VerticalStack;
struct MyApp {
vertical_stack: VerticalStack,
}
impl MyApp {
pub fn new() -> Self {
Self {
vertical_stack: VerticalStack::new()
.min_panel_height(50.0)
.default_panel_height(150.0),
}
}
}
impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::SidePanel::left("left_panel").show(ctx, |ui| {
self.vertical_stack
.id_salt(ui.id().with("vertical_stack"))
.body(ui, |body|{
// Panels can be conditionally added/removed at runtime.
// Panels are added to the stack in the same order as the calls to `add_panel`
// Each panel needs a unique ID, which is generated from the ID salt and the panel's hash
body.add_panel("top", |ui|{
ui.label("top");
});
body.add_panel("middle", |ui|{
ui.style_mut().wrap_mode = Some(eframe::egui::TextWrapMode::Extend);
ui.label("middle with some non-wrapping text");
});
body.add_panel("bottom", |ui|{
ui.label("bottom");
});
});
});
egui::CentralPanel::default().show(ctx, |ui| {
ui.label("main content");
});
}
}
fn main() -> eframe::Result {
let native_options = eframe::NativeOptions::default();
eframe::run_native("egui_vertical_stack - Simple", native_options, Box::new(|_cc| Ok(Box::new(MyApp::new()))))
}For a more complete example, check out the demos folder in the source.
Implementations§
Source§impl VerticalStack
impl VerticalStack
pub fn new() -> Self
pub fn inner_margin(self, inner_margin: f32) -> Self
pub fn framed(self, framed: bool) -> Self
Sourcepub fn max_height(self, height: Option<f32>) -> Self
pub fn max_height(self, height: Option<f32>) -> Self
Sets the maximum height for the scroll area. If None, will use all available height.
Sourcepub fn min_panel_height(self, height: f32) -> Self
pub fn min_panel_height(self, height: f32) -> Self
Sets the minimum height for panels.
Sourcepub fn max_panel_height(self, height: Option<f32>) -> Self
pub fn max_panel_height(self, height: Option<f32>) -> Self
Sets the maximum height for individual panels. If None, panels can grow as large as needed (or up to the entire scroll area).
Sourcepub fn default_panel_height(self, height: f32) -> Self
pub fn default_panel_height(self, height: f32) -> Self
Set the default height for new panels.
Sourcepub fn scroll_bar_visibility(self, visibility: ScrollBarVisibility) -> Self
pub fn scroll_bar_visibility(self, visibility: ScrollBarVisibility) -> Self
Adjust the scroll-area’s scrollbar visibility, the default is ‘when needed’, but using ‘always visible’ will likely yield a better UX.