Popup

Struct Popup 

Source
#[non_exhaustive]
pub struct Popup<'content, W> { pub body: W, pub title: Line<'content>, pub style: Style, pub borders: Borders, pub border_set: Set<'content>, pub border_style: Style, }
Expand description

Configuration for a popup.

This struct is used to configure a Popup. It can be created using Popup::new.

§Example

use ratatui::prelude::*;
use ratatui::symbols::border;
use tui_popup::Popup;

fn render_popup(frame: &mut Frame) {
    let popup = Popup::new("Press any key to exit")
        .title("tui-popup demo")
        .style(Style::new().white().on_blue())
        .border_set(border::ROUNDED)
        .border_style(Style::new().bold());
    frame.render_widget(popup, frame.area());
}

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§body: W

The body of the popup.

§title: Line<'content>

The title of the popup.

§style: Style

The style to apply to the entire popup.

§borders: Borders

The borders of the popup.

§border_set: Set<'content>

The symbols used to render the border.

§border_style: Style

Border style

Implementations§

Source§

impl<'content, W> Popup<'content, W>

Source

pub fn title(self, value: impl Into<Line<'content>>) -> Popup<'content, W>

Sets the title field of this struct.

Source

pub fn style(self, value: impl Into<Style>) -> Popup<'content, W>

Sets the style field of this struct.

Source

pub fn borders(self, value: impl Into<Borders>) -> Popup<'content, W>

Sets the borders field of this struct.

Source

pub fn border_set(self, value: impl Into<Set<'content>>) -> Popup<'content, W>

Sets the border_set field of this struct.

Source

pub fn border_style(self, value: impl Into<Style>) -> Popup<'content, W>

Sets the border_style field of this struct.

Source§

impl<W> Popup<'_, W>

Source

pub fn new(body: W) -> Popup<'_, W>

Create a new popup with the given title and body with all the borders.

§Parameters
  • body - The body of the popup. This can be any type that can be converted into a Text.
§Example
use tui_popup::Popup;

let popup = Popup::new("Press any key to exit").title("tui-popup demo");

Trait Implementations§

Source§

impl<W> Debug for Popup<'_, W>

Source§

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

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

impl<W> PartialEq for Popup<'_, W>
where W: PartialEq,

Source§

fn eq(&self, other: &Popup<'_, W>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<W> StatefulWidget for &Popup<'_, W>
where W: KnownSize, &'a W: for<'a> Widget,

Reference stateful render path for a popup body that renders by reference.

Use this when you have long-lived popup data and want to update PopupState without moving the popup each frame. This requires the body to support rendering by reference.

§Example

let popup = Popup::new(Text::from("Body"));
let popup_ref = &popup;
let mut state = PopupState::default();
popup_ref.render(buffer.area, &mut buffer, &mut state);
Source§

type State = PopupState

State associated with the stateful widget. Read more
Source§

fn render( self, area: Rect, buf: &mut Buffer, state: &mut <&Popup<'_, W> as StatefulWidget>::State, )

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom stateful widget.
Source§

impl<W> StatefulWidget for Popup<'_, W>
where W: KnownSize + Widget,

Owned stateful render path for a popup.

Use this when you have a PopupState that you want to update across frames and you can pass the popup by value in the render call.

§Example

let popup = Popup::new("Body");
let mut state = PopupState::default();
popup.render(buffer.area, &mut buffer, &mut state);
Source§

type State = PopupState

State associated with the stateful widget. Read more
Source§

fn render( self, area: Rect, buf: &mut Buffer, state: &mut <Popup<'_, W> as StatefulWidget>::State, )

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom stateful widget.
Source§

impl<W> Widget for &Popup<'_, W>
where W: KnownSize, &'a W: for<'a> Widget,

Reference render path for a popup body that supports rendering by reference.

Use this when you want to keep a Popup around and render it by reference. This is helpful when the body implements Widget for references (such as Text), or when you need to avoid rebuilding the widget each frame.

§Example

let popup = Popup::new(Text::from("Body"));
let popup_ref = &popup;
popup_ref.render(buffer.area, &mut buffer);
Source§

fn render(self, area: Rect, buf: &mut Buffer)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom widget.
Source§

impl<W> Widget for Popup<'_, W>
where W: KnownSize + Widget,

Owned render path for a popup.

Use this when you have an owned Popup value and want to render it by value. This is the simplest option for new users, and it works well with common bodies like &str or String.

§Example

let popup = Popup::new("Body");
popup.render(buffer.area, &mut buffer);
Source§

fn render(self, area: Rect, buf: &mut Buffer)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom widget.

Auto Trait Implementations§

§

impl<'content, W> Freeze for Popup<'content, W>
where W: Freeze,

§

impl<'content, W> RefUnwindSafe for Popup<'content, W>
where W: RefUnwindSafe,

§

impl<'content, W> Send for Popup<'content, W>
where W: Send,

§

impl<'content, W> Sync for Popup<'content, W>
where W: Sync,

§

impl<'content, W> Unpin for Popup<'content, W>
where W: Unpin,

§

impl<'content, W> UnwindSafe for Popup<'content, W>
where W: UnwindSafe,

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