pub mod context;
pub mod proxy;
pub mod composite;
pub mod tile;
pub mod align;
pub mod margin;
pub mod size;
pub mod layer;
pub mod label;
pub mod button;
pub mod slider;
pub mod checkbox;
pub mod switch;
pub mod dial;
pub mod text_box;
pub mod menu;
pub mod list;
pub mod grid;
pub mod floating;
pub mod status_bar;
pub mod thumbwheel;
pub mod scroll;
pub mod tabs;
pub mod tooltip;
pub mod progress;
use std::sync::{Arc, Weak};
use std::any::Any;
use crate::support::point::{Point, Axis};
use crate::view::{MouseButton, KeyInfo, TextInfo, DropInfo, CursorTracking};
pub const FULL_EXTENT: f32 = 1e30;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ViewLimits {
pub min: Point,
pub max: Point,
}
impl ViewLimits {
pub const fn new(min: Point, max: Point) -> Self {
Self { min, max }
}
pub const fn full() -> Self {
Self {
min: Point::new(0.0, 0.0),
max: Point::new(FULL_EXTENT, FULL_EXTENT),
}
}
pub const fn fixed(width: f32, height: f32) -> Self {
Self {
min: Point::new(width, height),
max: Point::new(width, height),
}
}
pub const fn min_size(width: f32, height: f32) -> Self {
Self {
min: Point::new(width, height),
max: Point::new(FULL_EXTENT, FULL_EXTENT),
}
}
pub fn min_for(&self, axis: Axis) -> f32 {
self.min[axis]
}
pub fn max_for(&self, axis: Axis) -> f32 {
self.max[axis]
}
}
impl Default for ViewLimits {
fn default() -> Self {
Self::full()
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ViewStretch {
pub x: f32,
pub y: f32,
}
impl ViewStretch {
pub const fn new(x: f32, y: f32) -> Self {
Self { x, y }
}
pub const fn uniform(value: f32) -> Self {
Self { x: value, y: value }
}
pub fn for_axis(&self, axis: Axis) -> f32 {
match axis {
Axis::X => self.x,
Axis::Y => self.y,
}
}
}
impl Default for ViewStretch {
fn default() -> Self {
Self { x: 1.0, y: 1.0 }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FocusRequest {
FromTop,
FromBottom,
RestorePrevious,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Tracking {
None,
Begin,
While,
End,
}
pub trait Element: Send + Sync + Any {
fn limits(&self, ctx: &BasicContext) -> ViewLimits {
ViewLimits::full()
}
fn stretch(&self) -> ViewStretch {
ViewStretch::default()
}
fn span(&self) -> u32 {
1
}
fn hit_test(&self, ctx: &Context, p: Point, leaf: bool, control: bool) -> Option<&dyn Element> {
None
}
fn contains(&self, ctx: &Context, p: Point) -> bool {
ctx.bounds.contains(p)
}
fn draw(&self, ctx: &Context) {}
fn layout(&mut self, ctx: &Context) {}
fn refresh(&self, ctx: &Context, outward: i32) {}
fn wants_control(&self) -> bool {
false
}
fn click(&mut self, ctx: &Context, btn: MouseButton) -> bool {
false
}
fn handle_click(&self, _ctx: &Context, _btn: MouseButton) -> bool {
false
}
fn drag(&mut self, ctx: &Context, btn: MouseButton) {}
fn handle_drag(&self, _ctx: &Context, _btn: MouseButton) {}
fn key(&mut self, ctx: &Context, k: KeyInfo) -> bool {
false
}
fn handle_key(&self, _ctx: &Context, _k: KeyInfo) -> bool {
false
}
fn text(&mut self, ctx: &Context, info: TextInfo) -> bool {
false
}
fn handle_text(&self, _ctx: &Context, _info: TextInfo) -> bool {
false
}
fn cursor(&mut self, ctx: &Context, p: Point, status: CursorTracking) -> bool {
false
}
fn scroll(&mut self, ctx: &Context, dir: Point, p: Point) -> bool {
false
}
fn handle_scroll(&self, _ctx: &Context, _dir: Point, _p: Point) -> bool {
false
}
fn enable(&mut self, state: bool) {}
fn is_enabled(&self) -> bool {
true
}
fn wants_focus(&self) -> bool {
false
}
fn begin_focus(&mut self, req: FocusRequest) {}
fn end_focus(&mut self) -> bool {
true
}
fn focus(&self) -> Option<&dyn Element> {
None
}
fn focus_mut(&mut self) -> Option<&mut dyn Element> {
None
}
fn clear_focus(&self) {}
fn track_drop(&mut self, ctx: &Context, info: &DropInfo, status: CursorTracking) {}
fn drop(&mut self, ctx: &Context, info: &DropInfo) -> bool {
false
}
fn class_name(&self) -> &'static str {
std::any::type_name::<Self>()
}
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
}
pub type ElementPtr = Arc<dyn Element>;
pub type WeakElementPtr = Weak<dyn Element>;
pub fn share<E: Element + 'static>(element: E) -> ElementPtr {
Arc::new(element)
}
#[derive(Debug, Clone, Copy, Default)]
pub struct Empty;
impl Element for Empty {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
pub fn empty() -> Empty {
Empty
}
pub use context::{BasicContext, Context};
pub use proxy::{Proxy, ProxyBase};
pub use composite::{Composite, CompositeBase, Storage};