use std::{any::Any, cell::RefCell, collections::HashMap};
use floem_winit::window::ResizeDirection;
use peniko::kurbo::{Point, Rect, Size, Vec2};
use crate::{id::ViewId, menu::Menu, view::View};
thread_local! {
pub(crate) static CENTRAL_UPDATE_MESSAGES: RefCell<Vec<(ViewId, UpdateMessage)>> = Default::default();
pub(crate) static UPDATE_MESSAGES: RefCell<HashMap<ViewId, Vec<UpdateMessage>>> = Default::default();
pub(crate) static CENTRAL_DEFERRED_UPDATE_MESSAGES: RefCell<Vec<(ViewId, Box<dyn Any>)>> = Default::default();
pub(crate) static DEFERRED_UPDATE_MESSAGES: RefCell<DeferredUpdateMessages> = Default::default();
pub(crate) static CURRENT_RUNNING_VIEW_HANDLE: RefCell<ViewId> = RefCell::new(ViewId::new());
}
type DeferredUpdateMessages = HashMap<ViewId, Vec<(ViewId, Box<dyn Any>)>>;
pub(crate) enum UpdateMessage {
Focus(ViewId),
ClearFocus(ViewId),
ClearAppFocus,
Active(ViewId),
ClearActive(ViewId),
WindowScale(f64),
Disabled {
id: ViewId,
is_disabled: bool,
},
RequestPaint,
State {
id: ViewId,
state: Box<dyn Any>,
},
KeyboardNavigable {
id: ViewId,
},
RemoveKeyboardNavigable {
id: ViewId,
},
Draggable {
id: ViewId,
},
ToggleWindowMaximized,
SetWindowMaximized(bool),
MinimizeWindow,
DragWindow,
DragResizeWindow(ResizeDirection),
SetWindowDelta(Vec2),
ShowContextMenu {
menu: Menu,
pos: Option<Point>,
},
WindowMenu {
menu: Menu,
},
SetWindowTitle {
title: String,
},
AddOverlay {
id: ViewId,
position: Point,
view: Box<dyn FnOnce() -> Box<dyn View>>,
},
RemoveOverlay {
id: ViewId,
},
Inspect,
ScrollTo {
id: ViewId,
rect: Option<Rect>,
},
FocusWindow,
SetImeAllowed {
allowed: bool,
},
SetImeCursorArea {
position: Point,
size: Size,
},
WindowVisible(bool),
ViewTransitionAnimComplete(ViewId),
}