Skip to main content

jag_ui/elements/
mod.rs

1//! Core UI elements.
2//!
3//! All elements implement the [`Element`] trait which combines rendering,
4//! layout (via [`Rect`]), and event handling (via [`EventHandler`]).
5
6pub mod alert;
7pub mod badge;
8pub mod button;
9pub mod card;
10pub mod checkbox;
11pub mod container;
12pub mod date_picker;
13pub mod image_element;
14pub mod input_box;
15pub mod link;
16pub mod modal;
17pub mod radio;
18pub mod select;
19pub mod slider;
20pub mod table;
21pub mod text;
22pub mod text_align;
23pub mod text_area;
24pub mod toggle_switch;
25
26pub use alert::{Alert, AlertSeverity};
27pub use badge::Badge;
28pub use button::{Button, ButtonLabelAlign};
29pub use card::Card;
30pub use checkbox::Checkbox;
31pub use container::Container;
32pub use date_picker::DatePicker;
33pub use image_element::{ImageElement, ImageFit};
34pub use input_box::InputBox;
35pub use link::Link;
36pub use modal::{Modal, ModalButton, ModalClickResult};
37pub use radio::Radio;
38pub use select::Select;
39pub use slider::Slider;
40pub use table::Table;
41pub use text::Text;
42pub use text_align::TextAlign;
43pub use text_area::TextArea;
44pub use toggle_switch::ToggleSwitch;
45
46use jag_draw::Rect;
47use jag_surface::Canvas;
48
49use crate::event::EventHandler;
50use crate::focus::FocusId;
51
52/// Trait implemented by all renderable UI elements.
53///
54/// Designed for object safety so that external crates (e.g., a future
55/// `jag-media`) can implement it for their own element types.
56pub trait Element: EventHandler {
57    /// The bounding rectangle of this element in logical coordinates.
58    fn rect(&self) -> Rect;
59
60    /// Update the bounding rectangle (typically called by the layout engine).
61    fn set_rect(&mut self, rect: Rect);
62
63    /// Paint this element onto `canvas` at the given z-index.
64    fn render(&self, canvas: &mut Canvas, z: i32);
65
66    /// The focus identifier for this element, if it is focusable.
67    fn focus_id(&self) -> Option<FocusId>;
68}