Struct widgetui::chunks::Chunks

source ·
pub struct Chunks { /* private fields */ }

Implementations§

source§

impl Chunks

source

pub fn clear(&mut self)

source

pub fn register_chunk<T: Any>(&mut self, rect: Rect)

Examples found in repository?
examples/custom_chunk.rs (line 19)
11
12
13
14
15
16
17
18
19
20
21
22
pub fn chunk_generator(frame: &mut WidgetFrame, mut chunks: RefMut<Chunks>) -> WidgetResult {
    let chunk = layout! {
        frame.size(),
        constraint!(%50),
        constraint!(#1) => {constraint!(#3), constraint!(%100), constraint!(#3)},
        constraint!(%50)
    }[1][1];

    chunks.register_chunk::<TestChunk>(chunk);

    Ok(())
}
More examples
Hide additional examples
examples/message.rs (line 21)
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fn chunk_builder(frame: &mut WidgetFrame, mut chunks: RefMut<Chunks>) -> WidgetResult {
    let popup = layout![
        frame.size(),
        constraint!(%50),
        constraint!(>3) => {
            constraint!(%10),
            constraint!(%80),
            constraint!(%10)
        },
        constraint!(%50)
    ][1][1];

    chunks.register_chunk::<MessageChunk>(popup);

    Ok(())
}
examples/custom_state.rs (line 20)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
pub fn handle_state(
    frame: &mut WidgetFrame,
    mut custom_state: RefMut<CustomState>,
    mut events: RefMut<Events>,
    mut chunks: RefMut<Chunks>,
) -> WidgetResult {
    // Register A Test Chunk
    chunks.register_chunk::<CustomChunk>(frame.size());
    let chunk = chunks.get_chunk::<CustomChunk>()?;

    custom_state.state += 1;

    if custom_state.state >= 50 {
        events.register_exit();
    }

    frame.render_widget(
        Paragraph::new(format!("Custom State: {}", custom_state.state)),
        chunk,
    );

    Ok(())
}
source

pub fn get_chunk<T: Any>(&self) -> Result<Rect, Box<dyn Error>>

Examples found in repository?
examples/custom_chunk.rs (line 29)
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
pub fn render(
    frame: &mut WidgetFrame,
    chunks: RefMut<Chunks>,
    mut events: RefMut<Events>,
) -> WidgetResult {
    let chunk = chunks.get_chunk::<TestChunk>()?;

    frame.render_widget(Paragraph::new("Hello, world!"), chunk);

    if events.key(crossterm::event::KeyCode::Char('q')) {
        events.register_exit();
    }

    Ok(())
}
More examples
Hide additional examples
examples/custom_state.rs (line 21)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
pub fn handle_state(
    frame: &mut WidgetFrame,
    mut custom_state: RefMut<CustomState>,
    mut events: RefMut<Events>,
    mut chunks: RefMut<Chunks>,
) -> WidgetResult {
    // Register A Test Chunk
    chunks.register_chunk::<CustomChunk>(frame.size());
    let chunk = chunks.get_chunk::<CustomChunk>()?;

    custom_state.state += 1;

    if custom_state.state >= 50 {
        events.register_exit();
    }

    frame.render_widget(
        Paragraph::new(format!("Custom State: {}", custom_state.state)),
        chunk,
    );

    Ok(())
}

Trait Implementations§

source§

impl Default for Chunks

source§

fn default() -> Chunks

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

impl FromStates for Chunks

source§

fn from_state(states: &mut States) -> Result<State<Self>, Box<dyn Error>>

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.