use std::num::NonZeroU32;
use crate::string::{CowString, CowStringL};
use crate::{event, ThemeAction, ThemeApi};
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct WindowId(NonZeroU32);
impl WindowId {
#[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
pub fn new(n: NonZeroU32) -> WindowId {
WindowId(n)
}
}
#[must_use]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd)]
pub enum TkAction {
None,
Redraw,
RegionMoved,
Popup,
Reconfigure,
Close,
CloseAll,
}
impl std::ops::Add for TkAction {
type Output = Self;
#[inline]
fn add(self, rhs: TkAction) -> Self {
self.max(rhs)
}
}
impl std::ops::AddAssign for TkAction {
#[inline]
fn add_assign(&mut self, rhs: TkAction) {
*self = (*self).max(rhs);
}
}
#[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
pub trait TkWindow {
fn add_popup(&mut self, popup: kas::Popup) -> WindowId;
fn add_window(&mut self, widget: Box<dyn kas::Window>) -> WindowId;
fn close_window(&mut self, id: WindowId);
fn trigger_update(&mut self, handle: event::UpdateHandle, payload: u64);
fn get_clipboard(&mut self) -> Option<CowString>;
fn set_clipboard<'c>(&mut self, content: CowStringL<'c>);
fn adjust_theme(&mut self, f: &mut dyn FnMut(&mut dyn ThemeApi) -> ThemeAction);
fn set_cursor_icon(&mut self, icon: event::CursorIcon);
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn action_precedence() {
assert!(TkAction::None < TkAction::Redraw);
assert!(TkAction::Redraw < TkAction::Reconfigure);
assert!(TkAction::Reconfigure < TkAction::Close);
assert!(TkAction::Close < TkAction::CloseAll);
}
}