VerticalStack

Struct VerticalStack 

Source
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

Source

pub fn new() -> Self

Source

pub fn id_salt(&mut self, id: impl Hash) -> &mut Self

Sets a custom ID salt for the stack.

Source

pub fn inner_margin(self, inner_margin: f32) -> Self

Source

pub fn framed(self, framed: bool) -> Self

Source

pub fn max_height(self, height: Option<f32>) -> Self

Sets the maximum height for the scroll area. If None, will use all available height.

Source

pub fn min_panel_height(self, height: f32) -> Self

Sets the minimum height for panels.

Source

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).

Source

pub fn default_panel_height(self, height: f32) -> Self

Set the default height for new panels.

Source

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.

Source

pub fn body<F>(&mut self, ui: &mut Ui, collect_panels: F)
where F: FnMut(&mut StackBodyBuilder),

The main function to render the stack and add panels.

Trait Implementations§

Source§

impl Debug for VerticalStack

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for VerticalStack

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.