Skip to main content

PopupState

Struct PopupState 

Source
pub struct PopupState { /* private fields */ }

Implementations§

Source§

impl PopupState

Auto-generated by derive_getters::Getters.

Source

pub fn area(&self) -> &Option<Rect>

The last rendered area of the popup

Examples found in repository?
examples/state.rs (line 76)
75fn render_status_bar(frame: &mut Frame, area: Rect, state: &PopupState) {
76    let popup_area = state.area().unwrap_or_default();
77    let text = format!("Popup area: {popup_area:?}");
78    let paragraph = Paragraph::new(text).style(Style::new().white().on_black());
79    frame.render_widget(paragraph, area);
80}
Source

pub fn drag_state(&self) -> &DragState

A state indicating whether the popup is being dragged or not

Source§

impl PopupState

Source

pub fn move_up(&mut self, amount: u16)

Examples found in repository?
examples/state.rs (line 97)
92fn handle_key_event(event: KeyEvent, popup: &mut PopupState, exit: &mut bool) {
93    match event.code {
94        KeyCode::Char('q') | KeyCode::Esc => *exit = true,
95        KeyCode::Char('r') => *popup = PopupState::default(),
96        KeyCode::Char('j') | KeyCode::Down => popup.move_down(1),
97        KeyCode::Char('k') | KeyCode::Up => popup.move_up(1),
98        KeyCode::Char('h') | KeyCode::Left => popup.move_left(1),
99        KeyCode::Char('l') | KeyCode::Right => popup.move_right(1),
100        _ => {}
101    }
102}
Source

pub fn move_down(&mut self, amount: u16)

Examples found in repository?
examples/state.rs (line 96)
92fn handle_key_event(event: KeyEvent, popup: &mut PopupState, exit: &mut bool) {
93    match event.code {
94        KeyCode::Char('q') | KeyCode::Esc => *exit = true,
95        KeyCode::Char('r') => *popup = PopupState::default(),
96        KeyCode::Char('j') | KeyCode::Down => popup.move_down(1),
97        KeyCode::Char('k') | KeyCode::Up => popup.move_up(1),
98        KeyCode::Char('h') | KeyCode::Left => popup.move_left(1),
99        KeyCode::Char('l') | KeyCode::Right => popup.move_right(1),
100        _ => {}
101    }
102}
Source

pub fn move_left(&mut self, amount: u16)

Examples found in repository?
examples/state.rs (line 98)
92fn handle_key_event(event: KeyEvent, popup: &mut PopupState, exit: &mut bool) {
93    match event.code {
94        KeyCode::Char('q') | KeyCode::Esc => *exit = true,
95        KeyCode::Char('r') => *popup = PopupState::default(),
96        KeyCode::Char('j') | KeyCode::Down => popup.move_down(1),
97        KeyCode::Char('k') | KeyCode::Up => popup.move_up(1),
98        KeyCode::Char('h') | KeyCode::Left => popup.move_left(1),
99        KeyCode::Char('l') | KeyCode::Right => popup.move_right(1),
100        _ => {}
101    }
102}
Source

pub fn move_right(&mut self, amount: u16)

Examples found in repository?
examples/state.rs (line 99)
92fn handle_key_event(event: KeyEvent, popup: &mut PopupState, exit: &mut bool) {
93    match event.code {
94        KeyCode::Char('q') | KeyCode::Esc => *exit = true,
95        KeyCode::Char('r') => *popup = PopupState::default(),
96        KeyCode::Char('j') | KeyCode::Down => popup.move_down(1),
97        KeyCode::Char('k') | KeyCode::Up => popup.move_up(1),
98        KeyCode::Char('h') | KeyCode::Left => popup.move_left(1),
99        KeyCode::Char('l') | KeyCode::Right => popup.move_right(1),
100        _ => {}
101    }
102}
Source

pub fn move_by(&mut self, x: i32, y: i32)

Move the popup by the given amount.

Source

pub const fn move_to(&mut self, x: u16, y: u16)

Move the popup to the given position.

Source

pub fn mouse_down(&mut self, col: u16, row: u16)

Set the state to dragging if the mouse click is in the popup title

Source

pub const fn mouse_up(&mut self, _col: u16, _row: u16)

Set the state to not dragging

Source

pub const fn mouse_drag(&mut self, col: u16, row: u16)

Move the popup if the state is dragging

Source

pub fn handle_mouse_event(&mut self, event: MouseEvent)

Examples found in repository?
examples/state.rs (line 87)
82fn handle_events(popup: &mut PopupState, exit: &mut bool) -> Result<()> {
83    let event = event::read()?;
84    if let Some(key) = event.as_key_press_event() {
85        handle_key_event(key, popup, exit);
86    } else if let Event::Mouse(event) = event {
87        popup.handle_mouse_event(event);
88    }
89    Ok(())
90}

Trait Implementations§

Source§

impl Clone for PopupState

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PopupState

Source§

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

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

impl Default for PopupState

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.