use std::sync::Arc;
use crate::{math::Rect, Context, Ui};
#[derive(Clone, Default)]
pub struct Output {
pub cursor_icon: CursorIcon,
pub open_url: Option<String>,
pub copied_text: String,
pub needs_repaint: bool,
}
#[derive(Clone, Copy)]
pub enum CursorIcon {
Default,
PointingHand,
ResizeHorizontal,
ResizeNeSw,
ResizeNwSe,
ResizeVertical,
Text,
}
impl Default for CursorIcon {
fn default() -> Self {
Self::Default
}
}
#[derive(Clone, Copy, Debug)]
pub struct InteractInfo {
pub sense: Sense,
pub hovered: bool,
pub clicked: bool,
pub double_clicked: bool,
pub active: bool,
pub has_kb_focus: bool,
pub rect: Rect,
}
impl InteractInfo {
pub fn nothing() -> Self {
Self {
sense: Sense::nothing(),
hovered: false,
clicked: false,
double_clicked: false,
active: false,
has_kb_focus: false,
rect: Rect::nothing(),
}
}
pub fn union(self, other: Self) -> Self {
Self {
sense: self.sense.union(other.sense),
hovered: self.hovered || other.hovered,
clicked: self.clicked || other.clicked,
double_clicked: self.double_clicked || other.double_clicked,
active: self.active || other.active,
has_kb_focus: self.has_kb_focus || other.has_kb_focus,
rect: self.rect.union(other.rect),
}
}
}
pub struct GuiResponse {
pub sense: Sense,
pub hovered: bool,
pub clicked: bool,
pub double_clicked: bool,
pub active: bool,
pub has_kb_focus: bool,
pub rect: Rect,
pub ctx: Arc<Context>,
}
impl GuiResponse {
pub fn tooltip(&mut self, add_contents: impl FnOnce(&mut Ui)) -> &mut Self {
if self.hovered {
crate::containers::show_tooltip(&self.ctx, add_contents);
}
self
}
pub fn tooltip_text(&mut self, text: impl Into<String>) -> &mut Self {
self.tooltip(|popup| {
popup.add(crate::widgets::Label::new(text));
})
}
}
impl Into<InteractInfo> for GuiResponse {
fn into(self) -> InteractInfo {
InteractInfo {
sense: self.sense,
hovered: self.hovered,
clicked: self.clicked,
double_clicked: self.double_clicked,
active: self.active,
has_kb_focus: self.has_kb_focus,
rect: self.rect,
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct Sense {
pub click: bool,
pub drag: bool,
}
impl Sense {
pub fn nothing() -> Self {
Self {
click: false,
drag: false,
}
}
pub fn click() -> Self {
Self {
click: true,
drag: false,
}
}
pub fn drag() -> Self {
Self {
click: false,
drag: true,
}
}
pub fn click_and_drag() -> Self {
Self {
click: true,
drag: true,
}
}
#[must_use]
pub fn union(self, other: Self) -> Self {
Self {
click: self.click | other.click,
drag: self.drag | other.drag,
}
}
}