use std::panic::Location;
use super::geometry::Sides;
use super::node::El;
use super::semantics::{Kind, Source};
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct HoverAlpha {
pub rest: f32,
pub peak: f32,
}
impl El {
pub fn new(kind: Kind) -> Self {
Self {
kind,
..Default::default()
}
}
pub fn key(mut self, k: impl Into<String>) -> Self {
self.key = Some(k.into());
self
}
pub fn block_pointer(mut self) -> Self {
self.block_pointer = true;
self
}
pub fn hit_overflow(mut self, outset: impl Into<Sides>) -> Self {
self.hit_overflow = outset.into();
self
}
pub fn focusable(mut self) -> Self {
self.focusable = true;
self
}
pub fn always_show_focus_ring(mut self) -> Self {
self.always_show_focus_ring = true;
self
}
pub fn selectable(mut self) -> Self {
self.selectable = true;
self
}
pub fn selection_source(mut self, source: crate::selection::SelectionSource) -> Self {
self.selection_source = Some(source);
self
}
pub fn capture_keys(mut self) -> Self {
self.capture_keys = true;
self.focusable = true;
self
}
pub fn alpha_follows_focused_ancestor(mut self) -> Self {
self.alpha_follows_focused_ancestor = true;
self
}
pub fn blink_when_focused(mut self) -> Self {
self.blink_when_focused = true;
self
}
pub fn state_follows_interactive_ancestor(mut self) -> Self {
self.state_follows_interactive_ancestor = true;
self
}
pub fn hover_alpha(mut self, rest: f32, peak: f32) -> Self {
self.hover_alpha = Some(HoverAlpha {
rest: rest.clamp(0.0, 1.0),
peak: peak.clamp(0.0, 1.0),
});
self
}
pub fn at(mut self, file: &'static str, line: u32) -> Self {
self.source = Source {
file,
line,
from_library: false,
};
self
}
pub fn at_loc(mut self, loc: &'static Location<'static>) -> Self {
self.source = Source::from_caller(loc);
self
}
pub fn from_library(mut self) -> Self {
self.source.from_library = true;
self
}
}