use std::{ hash::Hash, sync::{Arc, Mutex}, }; use crate::{widgets::*, *}; // ---------------------------------------------------------------------------- // TODO: rename GuiResponse pub struct GuiResponse { /// The mouse is hovering above this pub hovered: bool, /// The mouse went got pressed on this thing this frame pub clicked: bool, /// The mouse is interacting with this thing (e.g. dragging it) pub active: bool, /// The region of the screen we are talking about pub rect: Rect, /// Used for showing a popup (if any) pub data: Arc, } impl GuiResponse { /// Show some stuff if the item was hovered pub fn tooltip(&mut self, add_contents: F) -> &mut Self where F: FnOnce(&mut Region), { if self.hovered { if let Some(mouse_pos) = self.data.input().mouse_pos { let window_pos = mouse_pos + vec2(16.0, 16.0); show_popup(&self.data, window_pos, add_contents); } } self } /// Show this text if the item was hovered pub fn tooltip_text>(&mut self, text: S) -> &mut Self { self.tooltip(|popup| { popup.add(Label::new(text)); }) } } // ---------------------------------------------------------------------------- #[derive(Clone, Copy, Debug, PartialEq)] pub enum Direction { Horizontal, Vertical, } impl Default for Direction { fn default() -> Direction { Direction::Vertical } } #[derive(Clone, Copy, Debug, PartialEq)] pub enum Align { /// Left/Top Min, /// Note: requires a bounded/known available_width. Center, /// Right/Bottom /// Note: requires a bounded/known available_width. Max, } impl Default for Align { fn default() -> Align { Align::Min } } // ---------------------------------------------------------------------------- // TODO: newtype pub type Id = u64; pub fn make_id(source: &H) -> Id { use std::hash::Hasher; let mut hasher = std::collections::hash_map::DefaultHasher::new(); source.hash(&mut hasher); hasher.finish() } // ---------------------------------------------------------------------------- // TODO: give a better name. Context? /// Contains the input, style and output of all GUI commands. pub struct Data { /// The default style for new regions pub(crate) style: Mutex