#![doc = include_str!("../readme.md")]
#![allow(clippy::collapsible_else_if)]
use ratatui_core::layout::{Alignment, Rect};
mod popup;
pub use popup::*;
pub mod event {
use rat_event::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum PopupOutcome {
Continue,
Unchanged,
Changed,
Hide,
}
impl ConsumedEvent for PopupOutcome {
fn is_consumed(&self) -> bool {
*self != PopupOutcome::Continue
}
}
impl From<PopupOutcome> for Outcome {
fn from(value: PopupOutcome) -> Self {
match value {
PopupOutcome::Continue => Outcome::Continue,
PopupOutcome::Unchanged => Outcome::Unchanged,
PopupOutcome::Changed => Outcome::Changed,
PopupOutcome::Hide => Outcome::Changed,
}
}
}
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Placement {
#[default]
None,
Above,
Below,
Left,
Right,
AboveOrBelow,
BelowOrAbove,
Position(u16, u16),
}
impl Placement {
pub fn into_constraint(self, alignment: Alignment, relative_to_area: Rect) -> PopupConstraint {
match self {
Placement::None => PopupConstraint::None,
Placement::Above => PopupConstraint::Above(alignment, relative_to_area),
Placement::Below => PopupConstraint::Below(alignment, relative_to_area),
Placement::Left => PopupConstraint::Left(alignment, relative_to_area),
Placement::Right => PopupConstraint::Right(alignment, relative_to_area),
Placement::AboveOrBelow => PopupConstraint::AboveOrBelow(alignment, relative_to_area),
Placement::BelowOrAbove => PopupConstraint::BelowOrAbove(alignment, relative_to_area),
Placement::Position(x, y) => PopupConstraint::Position(x, y),
}
}
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum PopupConstraint {
#[default]
None,
Above(Alignment, Rect),
Below(Alignment, Rect),
Left(Alignment, Rect),
Right(Alignment, Rect),
AboveOrBelow(Alignment, Rect),
BelowOrAbove(Alignment, Rect),
Position(u16, u16),
}
mod _private {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct NonExhaustive;
}