Skip to main content

Stack

Struct Stack 

pub struct Stack<'a> { /* private fields */ }
Expand description

The sections a stack is given, in order ([Sections::show]).

Implementations§

§

impl<'a> Stack<'a>

pub fn section( &mut self, section: Section, body: impl FnOnce(&mut Ui) + 'a, ) -> &mut Stack<'a>

Adds a section, body its content (called only while it is open, in a scroll area of its own).

pub fn rows( &mut self, section: Section, count: usize, draw: impl FnOnce(&mut Ui, Range<usize>) + 'a, ) -> &mut Stack<'a>

Adds a section of count rows of one height (Section::row_height) in a scroll area of its own, windowed: draw is called only while it is open, with the rows in view and the one past them, on every pass, so the window follows the section’s size and scroll.

It draws them from the top of its ui, which has no spacing between items, each exactly that tall (with [Ui::add_sized], say), or they drift from their place in the scroll. Its least height is two rows, or all of them when it has fewer.

use egui_stack::sections::{Section, Sections, laid_out, row_height};

let ctx = egui::Context::default();
let mut out = ctx.run_ui(Default::default(), |ui| {
    let height = row_height(ui);
    Sections::new("log").show(ui, |stack| {
        stack.rows(Section::new("lines", "Lines"), 100_000, move |ui, range| {
            for i in range {
                let width = ui.available_width();
                ui.add_sized([width, height], egui::Label::new(format!("Line {i}")));
            }
        });
    });
});
out.textures_delta.clear();
let window = laid_out(&ctx, "log")[0].window.clone().unwrap();
assert!(window.len() < 1_000, "{window:?}");

pub fn bare( &mut self, section: Section, body: impl FnOnce(&mut Ui) + 'a, ) -> &mut Stack<'a>

Adds a section whose body has no scroll area around it (called only while it is open): for an application’s own view that scrolls itself, such as a virtualised list, which would otherwise nest two scrolls. It fills the body, clipped to it.

The stack cannot see into that view, so the wheel over a bare body always stops there, whether or not the view has anywhere to go.

Trait Implementations§

§

impl Debug for Stack<'_>

§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Stack<'a>

§

impl<'a> !RefUnwindSafe for Stack<'a>

§

impl<'a> !Send for Stack<'a>

§

impl<'a> !Sync for Stack<'a>

§

impl<'a> Unpin for Stack<'a>

§

impl<'a> UnsafeUnpin for Stack<'a>

§

impl<'a> !UnwindSafe for Stack<'a>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

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

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,