#![allow(dead_code)]
use crate::loader::{
DropdownAction, PressAction, RadioAction, SliderAction, TextBoxAction, ToggleAction,
};
use crate::styles::StyleId;
pub struct Button {
pub id: String,
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
pub text: String,
pub style: StyleId,
pub tooltip: Option<String>,
pub action: PressAction,
pub disabled: bool,
pub nav_default: bool,
}
pub struct ScrollList {
pub id: String,
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
pub pad_left: f32,
pub pad_right: f32,
pub pad_top: f32,
pub pad_bottom: f32,
pub gap: f32,
pub style: Option<StyleId>,
pub horizontal: bool,
pub full_span: bool,
pub items: Vec<UiItem>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BarEdge {
Top,
Bottom,
Left,
Right,
Free,
}
pub struct Bar {
pub id: String,
pub edge: BarEdge,
pub thickness: f32,
pub pad: f32,
pub gap: f32,
pub style: Option<StyleId>,
pub top_inset: f32,
pub bottom_inset: f32,
pub items: Vec<UiItem>,
pub manual: bool,
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
}
pub struct Popout {
pub id: String,
pub closed_x: f32,
pub closed_y: f32,
pub open_x: f32,
pub open_y: f32,
pub width: f32,
pub height: f32,
pub toggle_id: String,
pub style: Option<StyleId>,
pub edge: Option<crate::items::PopoutEdge>,
pub shadow: bool,
pub horizontal: bool,
pub gap: f32,
pub full_span: bool,
pub home_toggles: bool,
pub items: Vec<UiItem>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PopoutEdge {
Left,
Right,
Top,
Bottom,
}
pub struct Toggle {
pub id: String,
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
pub text: String,
pub tooltip: Option<String>,
pub default_checked: bool,
pub disabled: bool,
pub style_off: StyleId,
pub style_on: StyleId,
pub action: ToggleAction,
}
pub struct FreeLabel {
pub id: String,
pub x: f32,
pub y: f32,
pub text: String,
pub size: f32,
pub color: crate::draw::Color,
pub width: f32,
}
pub struct Divider {
pub id: String,
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
pub style: StyleId,
pub full_span: bool,
}
pub struct Image {
pub id: String,
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
pub texture: crate::textures::TextureId,
pub shader: crate::draw::ShaderId,
}
pub struct ProgressBar {
pub id: String,
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
pub value: f32,
pub style_track: StyleId,
pub style_fill: StyleId,
}
pub struct Actor {
pub id: String,
pub origin_x: f32,
pub origin_y: f32,
pub width: f32,
pub height: f32,
pub style: Option<StyleId>,
pub gif: Option<crate::textures::TextureId>,
pub gif_shader: crate::draw::ShaderId,
pub z_front: bool,
pub return_on_end: bool,
pub behaviours: Vec<Behaviour>,
pub trail_capacity: f32,
}
pub struct Behaviour {
pub trigger: Trigger,
pub action: Action,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Trigger {
Always,
OnHoverSelf,
OnPressSelf,
OnClickSelf,
OnClickAnywhere,
}
#[derive(Debug, Clone)]
pub enum Action {
FollowCursor { speed: f32, trail: f32 },
MoveTo { x: f32, y: f32, speed: f32 },
SwapGif {
texture: crate::textures::TextureId,
shader: crate::draw::ShaderId,
},
}
pub struct Toast {
pub id: String,
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
pub message: String,
pub duration: f32,
pub shape: Option<StyleId>,
}
pub struct TabPage {
pub label: String,
pub items: Vec<UiItem>,
}
pub struct Tab {
pub id: String,
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
pub pad_left: f32,
pub pad_right: f32,
pub pad_top: f32,
pub pad_bottom: f32,
pub gap: f32,
pub style: Option<StyleId>,
pub pages: Vec<TabPage>,
pub full_span: bool,
}
pub enum UiItem {
Slider(Slider),
Button(Button),
ScrollList(ScrollList),
Bar(Bar),
Popout(Popout),
Toggle(Toggle),
TextBox(TextBox),
Label(FreeLabel),
Divider(Divider),
Image(Image),
ProgressBar(ProgressBar),
ScrollPane(ScrollPane),
Dropdown(Dropdown),
RadioGroup(RadioGroup),
Actor(Actor),
Toast(Toast),
Tab(Tab),
Spacer,
}
impl UiItem {
pub fn id(&self) -> &str {
match self {
Self::Slider(x) => &x.id,
Self::Button(x) => &x.id,
Self::ScrollList(x) => &x.id,
Self::Bar(x) => &x.id,
Self::Popout(x) => &x.id,
Self::Toggle(x) => &x.id,
Self::TextBox(x) => &x.id,
Self::ProgressBar(x) => &x.id,
Self::ScrollPane(x) => &x.id,
Self::Dropdown(x) => &x.id,
Self::RadioGroup(x) => &x.id,
Self::Actor(x) => &x.id,
Self::Toast(x) => &x.id,
Self::Tab(x) => &x.id,
Self::Label(_) | Self::Divider(_) | Self::Image(_) | Self::Spacer => "",
}
}
}
pub struct Slider {
pub id: String,
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
pub min: f32,
pub max: f32,
pub default_value: f32,
pub step: Option<f32>,
pub tooltip: Option<String>,
pub style_track: StyleId,
pub style_thumb: StyleId,
pub action: SliderAction,
}
pub struct TextBox {
pub id: String,
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
pub default_text: String,
pub placeholder: String,
pub max_len: Option<usize>,
pub tooltip: Option<String>,
pub style_idle: StyleId,
pub style_focus: StyleId,
pub on_change: TextBoxAction,
pub on_submit: TextBoxAction,
pub password: bool,
pub multiline: bool,
pub font_size: Option<f32>,
}
pub struct ScrollPane {
pub id: String,
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
pub pad_left: f32,
pub pad_right: f32,
pub pad_top: f32,
pub pad_bottom: f32,
pub gap: f32,
pub style: Option<StyleId>,
pub horizontal: bool,
pub full_span: bool,
pub manual: bool,
pub items: Vec<UiItem>,
}
pub struct Dropdown {
pub id: String,
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
pub default_selected: usize,
pub options: Vec<String>,
pub style: StyleId,
pub style_list: Option<StyleId>,
pub action: DropdownAction,
pub items: Vec<Button>,
}
pub struct RadioGroup {
pub id: String,
pub default_selected: usize,
pub options: Vec<String>,
pub style_idle: StyleId,
pub style_selected: StyleId,
pub action: RadioAction,
pub items: Vec<Button>,
pub x: f32,
pub y: f32,
}