124 lines
3.5 KiB
Rust
124 lines
3.5 KiB
Rust
use crate::ui::UIWidget;
|
|
use maud::{Markup, Render, html};
|
|
|
|
pub enum Cursor {
|
|
Auto,
|
|
Default,
|
|
Pointer,
|
|
Wait,
|
|
Text,
|
|
Move,
|
|
Help,
|
|
NotAllowed,
|
|
None,
|
|
ContextMenu,
|
|
Progress,
|
|
Cell,
|
|
Crosshair,
|
|
VerticalText,
|
|
Alias,
|
|
Copy,
|
|
NoDrop,
|
|
Grab,
|
|
Grabbing,
|
|
AllScroll,
|
|
ColResize,
|
|
RowResize,
|
|
NorthResize,
|
|
EastResize,
|
|
SouthResize,
|
|
WestResize,
|
|
NorthEastResize,
|
|
NorthWestResize,
|
|
SouthEastResize,
|
|
SouthWestResize,
|
|
EastWestResize,
|
|
NorthSouthResize,
|
|
NorthEastSouthWestResize,
|
|
NorthWestSouthEastResize,
|
|
ZoomIn,
|
|
ZoomOut,
|
|
}
|
|
|
|
impl Cursor {
|
|
pub fn on<T: UIWidget + 'static>(self, inner: T) -> CursorWidget {
|
|
CursorWidget(self, Box::new(inner))
|
|
}
|
|
}
|
|
|
|
pub struct CursorWidget(Cursor, Box<dyn UIWidget>);
|
|
|
|
impl Render for CursorWidget {
|
|
fn render(&self) -> Markup {
|
|
self.render_with_class("")
|
|
}
|
|
}
|
|
|
|
impl UIWidget for CursorWidget {
|
|
fn can_inherit(&self) -> bool {
|
|
true
|
|
}
|
|
|
|
fn base_class(&self) -> Vec<String> {
|
|
let class = match self.0 {
|
|
Cursor::Auto => "cursor-auto",
|
|
Cursor::Default => "cursor-default",
|
|
Cursor::Pointer => "cursor-pointer",
|
|
Cursor::Wait => "cursor-wait",
|
|
Cursor::Text => "cursor-text",
|
|
Cursor::Move => "cursor-move",
|
|
Cursor::Help => "cursor-help",
|
|
Cursor::NotAllowed => "cursor-not-allowed",
|
|
Cursor::None => "cursor-none",
|
|
Cursor::ContextMenu => "cursor-context-menu",
|
|
Cursor::Progress => "cursor-progress",
|
|
Cursor::Cell => "cursor-cell",
|
|
Cursor::Crosshair => "cursor-crosshair",
|
|
Cursor::VerticalText => "cursor-vertical-text",
|
|
Cursor::Alias => "cursor-alias",
|
|
Cursor::Copy => "cursor-copy",
|
|
Cursor::NoDrop => "cursor-no-drop",
|
|
Cursor::Grab => "cursor-grab",
|
|
Cursor::Grabbing => "cursor-grabbing",
|
|
Cursor::AllScroll => "cursor-all-scroll",
|
|
Cursor::ColResize => "cursor-col-resize",
|
|
Cursor::RowResize => "cursor-row-resize",
|
|
Cursor::NorthResize => "cursor-n-resize",
|
|
Cursor::EastResize => "cursor-e-resize",
|
|
Cursor::SouthResize => "cursor-s-resize",
|
|
Cursor::WestResize => "cursor-w-resize",
|
|
Cursor::NorthEastResize => "cursor-ne-resize",
|
|
Cursor::NorthWestResize => "cursor-nw-resize",
|
|
Cursor::SouthEastResize => "cursor-se-resize",
|
|
Cursor::SouthWestResize => "cursor-sw-resize",
|
|
Cursor::EastWestResize => "cursor-ew-resize",
|
|
Cursor::NorthSouthResize => "cursor-ns-resize",
|
|
Cursor::NorthEastSouthWestResize => "cursor-nesw-resize",
|
|
Cursor::NorthWestSouthEastResize => "cursor-nwse-resize",
|
|
Cursor::ZoomIn => "cursor-zoom-in",
|
|
Cursor::ZoomOut => "cursor-zoom-out",
|
|
};
|
|
|
|
vec![class.to_string()]
|
|
}
|
|
|
|
fn extended_class(&self) -> Vec<String> {
|
|
let mut c = self.base_class();
|
|
c.extend_from_slice(&self.1.extended_class());
|
|
c
|
|
}
|
|
|
|
fn render_with_class(&self, class: &str) -> Markup {
|
|
let inner = &self.1;
|
|
|
|
if inner.can_inherit() {
|
|
inner.render_with_class(&format!("{} {class}", self.base_class().join(" ")))
|
|
} else {
|
|
html! {
|
|
div class=(format!("{} {class}", self.base_class().join(" "))) {
|
|
(inner)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|