#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.body: WThe body of the popup.
title: Line<'content>The title of the popup.
style: StyleThe style to apply to the entire popup.
borders: BordersThe borders of the popup.
border_set: Set<'content>The symbols used to render the border.
border_style: StyleBorder style
Implementations§
Source§impl<'content, W> Popup<'content, W>
impl<'content, W> Popup<'content, W>
Sourcepub fn title(self, value: impl Into<Line<'content>>) -> Self
pub fn title(self, value: impl Into<Line<'content>>) -> Self
Sets the title field of this struct.
Examples found in repository?
More examples
44fn render_popup(frame: &mut Frame, area: Rect, state: &mut PopupState) {
45 let body = Text::from_iter([
46 "q: exit",
47 "r: reset",
48 "j: move down",
49 "k: move up",
50 "h: move left",
51 "l: move right",
52 ]);
53 let popup = Popup::new(body)
54 .title("Popup")
55 .style(Style::new().white().on_blue());
56 frame.render_stateful_widget(popup, area, state);
57}46 fn render_popup(&self, frame: &mut Frame) {
47 let lines: Text = (0..10).map(|i| Span::raw(format!("Line {i}"))).collect();
48 let paragraph = Paragraph::new(lines).scroll((self.scroll, 0));
49 let wrapper = KnownSizeWrapper {
50 inner: paragraph,
51 width: 21,
52 height: 5,
53 };
54 let popup = Popup::new(wrapper)
55 .title("scroll: ↑/↓ quit: Esc")
56 .style(Style::new().white().on_blue());
57 frame.render_widget(popup, frame.area());
58 }Sourcepub fn style(self, value: impl Into<Style>) -> Self
pub fn style(self, value: impl Into<Style>) -> Self
Sets the style field of this struct.
Examples found in repository?
More examples
44fn render_popup(frame: &mut Frame, area: Rect, state: &mut PopupState) {
45 let body = Text::from_iter([
46 "q: exit",
47 "r: reset",
48 "j: move down",
49 "k: move up",
50 "h: move left",
51 "l: move right",
52 ]);
53 let popup = Popup::new(body)
54 .title("Popup")
55 .style(Style::new().white().on_blue());
56 frame.render_stateful_widget(popup, area, state);
57}46 fn render_popup(&self, frame: &mut Frame) {
47 let lines: Text = (0..10).map(|i| Span::raw(format!("Line {i}"))).collect();
48 let paragraph = Paragraph::new(lines).scroll((self.scroll, 0));
49 let wrapper = KnownSizeWrapper {
50 inner: paragraph,
51 width: 21,
52 height: 5,
53 };
54 let popup = Popup::new(wrapper)
55 .title("scroll: ↑/↓ quit: Esc")
56 .style(Style::new().white().on_blue());
57 frame.render_widget(popup, frame.area());
58 }Sourcepub fn border_set(self, value: impl Into<Set<'content>>) -> Self
pub fn border_set(self, value: impl Into<Set<'content>>) -> Self
Sets the border_set field of this struct.
Sourcepub fn border_style(self, value: impl Into<Style>) -> Self
pub fn border_style(self, value: impl Into<Style>) -> Self
Sets the border_style field of this struct.
Source§impl<W> Popup<'_, W>
impl<W> Popup<'_, W>
Sourcepub fn new(body: W) -> Self
pub fn new(body: W) -> Self
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 aText.
§Example
use tui_popup::Popup;
let popup = Popup::new("Press any key to exit").title("tui-popup demo");Examples found in repository?
More examples
44fn render_popup(frame: &mut Frame, area: Rect, state: &mut PopupState) {
45 let body = Text::from_iter([
46 "q: exit",
47 "r: reset",
48 "j: move down",
49 "k: move up",
50 "h: move left",
51 "l: move right",
52 ]);
53 let popup = Popup::new(body)
54 .title("Popup")
55 .style(Style::new().white().on_blue());
56 frame.render_stateful_widget(popup, area, state);
57}46 fn render_popup(&self, frame: &mut Frame) {
47 let lines: Text = (0..10).map(|i| Span::raw(format!("Line {i}"))).collect();
48 let paragraph = Paragraph::new(lines).scroll((self.scroll, 0));
49 let wrapper = KnownSizeWrapper {
50 inner: paragraph,
51 width: 21,
52 height: 5,
53 };
54 let popup = Popup::new(wrapper)
55 .title("scroll: ↑/↓ quit: Esc")
56 .style(Style::new().white().on_blue());
57 frame.render_widget(popup, frame.area());
58 }Trait Implementations§
Source§impl<W> StatefulWidget for &Popup<'_, W>
Reference stateful render path for a popup body that renders by reference.
impl<W> StatefulWidget for &Popup<'_, W>
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§impl<W: KnownSize + Widget> StatefulWidget for Popup<'_, W>
Owned stateful render path for a popup.
impl<W: KnownSize + Widget> StatefulWidget for Popup<'_, W>
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§impl<W> Widget for &Popup<'_, W>
Reference render path for a popup body that supports rendering by reference.
impl<W> Widget for &Popup<'_, W>
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§impl<W: KnownSize + Widget> Widget for Popup<'_, W>
Owned render path for a popup.
impl<W: KnownSize + Widget> Widget for Popup<'_, W>
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);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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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