bones_framework/render/ui/
widgets.rs

1//! Egui widgets.
2
3mod bordered_button;
4mod bordered_frame;
5
6pub use bordered_button::*;
7pub use bordered_frame::*;
8
9use crate::prelude::*;
10
11/// Metadata describing a border image.
12///
13/// A border image is a 9-patch style image that can be applied to buttons and panels.
14#[derive(HasSchema, Clone, Debug)]
15#[repr(C)]
16pub struct BorderImageMeta {
17    /// The image for the border.
18    pub image: Handle<Image>,
19    /// The size of the border image in pixels.
20    pub image_size: UVec2,
21    /// The size of the border on each side.
22    pub border_size: MarginMeta,
23    /// The scale to render the border image at.
24    ///
25    /// This is useful for pixel-art borders you want to scale up to make more visible.
26    pub scale: f32,
27}
28
29impl Default for BorderImageMeta {
30    fn default() -> Self {
31        Self {
32            image: Default::default(),
33            image_size: Default::default(),
34            border_size: Default::default(),
35            scale: 1.0,
36        }
37    }
38}
39
40/// Metadata describing a themed button.
41#[derive(HasSchema, Clone, Debug, Default)]
42#[repr(C)]
43pub struct ButtonThemeMeta {
44    /// The font family, size, and color to use for the button.
45    pub font: FontMeta,
46    /// The amount of space to pad around the internal edges of the button.
47    pub padding: MarginMeta,
48    /// The border images to use for different button states.
49    pub borders: ButtonBordersMeta,
50}
51
52/// The border images to use for a [`ButtonThemeMeta`] when the button is in different states.
53#[derive(HasSchema, Clone, Debug, Default)]
54#[repr(C)]
55pub struct ButtonBordersMeta {
56    /// The default button state.
57    pub default: BorderImageMeta,
58    /// When the button is hovered for focused on.
59    pub focused: BorderImageMeta,
60    /// When the button is clicked on.
61    pub clicked: BorderImageMeta,
62}
63
64/// A margin specification.
65#[derive(HasSchema, Default, serde::Deserialize, Clone, Copy, Debug)]
66#[repr(C)]
67pub struct MarginMeta {
68    /// The top margin.
69    pub top: f32,
70    /// The bottom margin.
71    pub bottom: f32,
72    /// The left margin.
73    pub left: f32,
74    /// The right margin.
75    pub right: f32,
76}
77
78impl From<MarginMeta> for egui::style::Margin {
79    fn from(m: MarginMeta) -> Self {
80        Self {
81            left: m.left,
82            right: m.right,
83            top: m.top,
84            bottom: m.bottom,
85        }
86    }
87}