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 63)
62fn render_status_bar(frame: &mut Frame, area: Rect, state: &PopupState) {
63    let popup_area = state.area().unwrap_or_default();
64    let text = format!("Popup area: {popup_area:?}");
65    let paragraph = Paragraph::new(text).style(Style::new().white().on_black());
66    frame.render_widget(paragraph, area);
67}
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 85)
80fn handle_key_event(event: KeyEvent, popup: &mut PopupState, exit: &mut bool) {
81    match event.code {
82        KeyCode::Char('q') | KeyCode::Esc => *exit = true,
83        KeyCode::Char('r') => *popup = PopupState::default(),
84        KeyCode::Char('j') | KeyCode::Down => popup.move_down(1),
85        KeyCode::Char('k') | KeyCode::Up => popup.move_up(1),
86        KeyCode::Char('h') | KeyCode::Left => popup.move_left(1),
87        KeyCode::Char('l') | KeyCode::Right => popup.move_right(1),
88        _ => {}
89    }
90}
Source

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

Examples found in repository?
examples/state.rs (line 84)
80fn handle_key_event(event: KeyEvent, popup: &mut PopupState, exit: &mut bool) {
81    match event.code {
82        KeyCode::Char('q') | KeyCode::Esc => *exit = true,
83        KeyCode::Char('r') => *popup = PopupState::default(),
84        KeyCode::Char('j') | KeyCode::Down => popup.move_down(1),
85        KeyCode::Char('k') | KeyCode::Up => popup.move_up(1),
86        KeyCode::Char('h') | KeyCode::Left => popup.move_left(1),
87        KeyCode::Char('l') | KeyCode::Right => popup.move_right(1),
88        _ => {}
89    }
90}
Source

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

Examples found in repository?
examples/state.rs (line 86)
80fn handle_key_event(event: KeyEvent, popup: &mut PopupState, exit: &mut bool) {
81    match event.code {
82        KeyCode::Char('q') | KeyCode::Esc => *exit = true,
83        KeyCode::Char('r') => *popup = PopupState::default(),
84        KeyCode::Char('j') | KeyCode::Down => popup.move_down(1),
85        KeyCode::Char('k') | KeyCode::Up => popup.move_up(1),
86        KeyCode::Char('h') | KeyCode::Left => popup.move_left(1),
87        KeyCode::Char('l') | KeyCode::Right => popup.move_right(1),
88        _ => {}
89    }
90}
Source

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

Examples found in repository?
examples/state.rs (line 87)
80fn handle_key_event(event: KeyEvent, popup: &mut PopupState, exit: &mut bool) {
81    match event.code {
82        KeyCode::Char('q') | KeyCode::Esc => *exit = true,
83        KeyCode::Char('r') => *popup = PopupState::default(),
84        KeyCode::Char('j') | KeyCode::Down => popup.move_down(1),
85        KeyCode::Char('k') | KeyCode::Up => popup.move_up(1),
86        KeyCode::Char('h') | KeyCode::Left => popup.move_left(1),
87        KeyCode::Char('l') | KeyCode::Right => popup.move_right(1),
88        _ => {}
89    }
90}
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 74)
69fn handle_events(popup: &mut PopupState, exit: &mut bool) -> Result<()> {
70    match event::read()? {
71        Event::Key(event) if event.kind == KeyEventKind::Press => {
72            handle_key_event(event, popup, exit);
73        }
74        Event::Mouse(event) => popup.handle_mouse_event(event),
75        _ => (),
76    }
77    Ok(())
78}

Trait Implementations§

Source§

impl Clone for PopupState

Source§

fn clone(&self) -> PopupState

Returns a duplicate of the value. Read more
1.0.0 · 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() -> PopupState

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