use crate::{
DisplayInfo, RustConstructorId, RustConstructorResource,
basic_front::{CustomRectConfig, ImageConfig, TextConfig},
};
#[cfg(feature = "bevy")]
use egui_bevy::PointerButton;
#[cfg(feature = "standard")]
use egui_standard::PointerButton;
use std::any::Any;
#[derive(Clone, Debug, PartialEq)]
pub enum BackgroundType {
Image(ImageConfig),
CustomRect(CustomRectConfig),
}
impl Default for BackgroundType {
fn default() -> Self {
BackgroundType::CustomRect(CustomRectConfig::default())
}
}
#[derive(Clone, Debug, Default, PartialEq)]
pub struct Background {
pub background_type: BackgroundType,
pub auto_update: bool,
pub use_background_tags: bool,
pub tags: Vec<[String; 2]>,
}
impl RustConstructorResource for Background {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn display_display_info(&self) -> Option<DisplayInfo> {
None
}
fn modify_display_info(&mut self, _display_info: DisplayInfo) {}
fn display_tags(&self) -> Vec<[String; 2]> {
self.tags.clone()
}
fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
if replace {
self.tags = tags.to_owned();
} else {
for tag in tags {
if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
self.tags.remove(index);
};
}
self.tags.extend(tags.iter().cloned());
};
}
}
impl Background {
#[inline]
pub fn background_type(mut self, background_type: &BackgroundType) -> Self {
self.background_type = background_type.clone();
self
}
#[inline]
pub fn auto_update(mut self, auto_update: bool) -> Self {
self.auto_update = auto_update;
self
}
#[inline]
pub fn use_background_tags(mut self, use_background_tags: bool) -> Self {
self.use_background_tags = use_background_tags;
self
}
#[inline]
pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
if replace {
self.tags = tags.to_owned();
} else {
for tag in tags {
if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
self.tags.remove(index);
};
}
self.tags.extend(tags.iter().cloned());
};
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub enum ScrollLengthMethod {
Fixed(f32),
AutoFit(f32),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum ClickAim {
Move,
TopResize,
BottomResize,
LeftResize,
RightResize,
LeftTopResize,
RightTopResize,
LeftBottomResize,
RightBottomResize,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ScrollBarDisplayMethod {
Always(BackgroundType, [f32; 2], f32),
OnlyScroll(BackgroundType, [f32; 2], f32),
Hidden,
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub enum PanelMargin {
Vertical([f32; 4], bool),
Horizontal([f32; 4], bool),
None([f32; 4], bool),
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub struct PanelLayout {
pub panel_margin: PanelMargin,
pub panel_location: PanelLocation,
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub enum PanelLocation {
Absolute([f32; 2]),
Relative([[f32; 2]; 2]),
}
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub enum CustomPanelLayout {
Type(String, PanelLayout),
Id(RustConstructorId, PanelLayout),
}
#[derive(Debug, Default, Clone, PartialEq, PartialOrd)]
pub struct PanelStorage {
pub id: RustConstructorId,
pub ignore_render_layer: bool,
pub hidden: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ResourcePanel {
pub resizable: [bool; 4],
pub background: BackgroundType,
pub min_size: [f32; 2],
pub max_size: Option<[f32; 2]>,
pub movable: [bool; 2],
pub scroll_length_method: [Option<ScrollLengthMethod>; 2],
pub scroll_sensitivity: f32,
pub scroll_bar_display_method: ScrollBarDisplayMethod,
pub overall_layout: PanelLayout,
pub custom_layout: Vec<CustomPanelLayout>,
pub hidden: bool,
pub reverse_scroll_direction: [bool; 2],
pub inner_margin: [f32; 4],
pub raise_on_focus: bool,
pub scroll_length: [f32; 2],
pub scroll_progress: [f32; 2],
pub last_frame_mouse_status: Option<([f32; 2], ClickAim, [f32; 2])>,
pub scrolled: [bool; 2],
pub scroll_bar_alpha: [u8; 2],
pub resource_storage: Vec<PanelStorage>,
pub tags: Vec<[String; 2]>,
}
impl RustConstructorResource for ResourcePanel {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn display_display_info(&self) -> Option<DisplayInfo> {
None
}
fn modify_display_info(&mut self, _display_info: DisplayInfo) {}
fn display_tags(&self) -> Vec<[String; 2]> {
self.tags.clone()
}
fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
if replace {
self.tags = tags.to_owned();
} else {
for tag in tags {
if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
self.tags.remove(index);
};
}
self.tags.extend(tags.iter().cloned());
};
}
}
impl Default for ResourcePanel {
fn default() -> Self {
Self {
resizable: [true, true, true, true],
background: BackgroundType::default(),
min_size: [10_f32, 10_f32],
max_size: None,
movable: [true, true],
scroll_length_method: [None, None],
scroll_sensitivity: 0_f32,
scroll_bar_display_method: ScrollBarDisplayMethod::OnlyScroll(
BackgroundType::default(),
[4_f32, 2_f32],
4_f32,
),
overall_layout: (PanelLayout {
panel_margin: PanelMargin::Vertical([0_f32, 0_f32, 0_f32, 0_f32], false),
panel_location: PanelLocation::Absolute([0_f32, 0_f32]),
}),
custom_layout: Vec::new(),
hidden: false,
reverse_scroll_direction: [false, false],
inner_margin: [6_f32, 6_f32, 6_f32, 6_f32],
raise_on_focus: true,
scroll_length: [0_f32, 0_f32],
scroll_progress: [0_f32, 0_f32],
last_frame_mouse_status: None,
scrolled: [false, false],
scroll_bar_alpha: [0, 0],
resource_storage: Vec::new(),
tags: Vec::new(),
}
}
}
impl ResourcePanel {
#[inline]
pub fn resizable(mut self, top: bool, bottom: bool, left: bool, right: bool) -> Self {
self.resizable = [top, bottom, left, right];
self
}
#[inline]
pub fn background(mut self, background: &BackgroundType) -> Self {
self.background = background.clone();
self
}
#[inline]
pub fn min_size(mut self, width: f32, height: f32) -> Self {
self.min_size = [width, height];
self
}
#[inline]
pub fn max_size(mut self, max_size: Option<[f32; 2]>) -> Self {
self.max_size = max_size;
self
}
#[inline]
pub fn movable(mut self, horizontal: bool, vertical: bool) -> Self {
self.movable = [horizontal, vertical];
self
}
#[inline]
pub fn scroll_length_method(
mut self,
horizontal: Option<ScrollLengthMethod>,
vertical: Option<ScrollLengthMethod>,
) -> Self {
self.scroll_length_method = [horizontal, vertical];
self
}
#[inline]
pub fn scroll_sensitivity(mut self, scroll_sensitivity: f32) -> Self {
self.scroll_sensitivity = scroll_sensitivity;
self
}
#[inline]
pub fn scroll_bar_display_method(
mut self,
scroll_bar_display_method: ScrollBarDisplayMethod,
) -> Self {
self.scroll_bar_display_method = scroll_bar_display_method;
self
}
#[inline]
pub fn overall_layout(mut self, overall_layout: PanelLayout) -> Self {
self.overall_layout = overall_layout;
self
}
#[inline]
pub fn push_custom_layout(mut self, custom_layout: CustomPanelLayout) -> Self {
self.custom_layout.push(custom_layout);
self
}
#[inline]
pub fn custom_layout(mut self, custom_layout: &[CustomPanelLayout]) -> Self {
self.custom_layout = custom_layout.to_owned();
self
}
#[inline]
pub fn hidden(mut self, hidden: bool) -> Self {
self.hidden = hidden;
self
}
#[inline]
pub fn reverse_scroll_direction(mut self, horizontal: bool, vertical: bool) -> Self {
self.reverse_scroll_direction = [horizontal, vertical];
self
}
#[inline]
pub fn inner_margin(mut self, top: f32, bottom: f32, left: f32, right: f32) -> Self {
self.inner_margin = [top, bottom, left, right];
self
}
#[inline]
pub fn raise_on_focus(mut self, raise_on_focus: bool) -> Self {
self.raise_on_focus = raise_on_focus;
self
}
#[inline]
pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
if replace {
self.tags = tags.to_owned();
} else {
for tag in tags {
if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
self.tags.remove(index);
};
}
self.tags.extend(tags.iter().cloned());
};
self
}
}
#[derive(Clone, Debug, Default, PartialEq)]
pub struct SwitchAppearanceConfig {
pub background_config: BackgroundType,
pub text_config: TextConfig,
pub hint_text_config: TextConfig,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SwitchClickConfig {
pub click_method: PointerButton,
pub action: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SwitchData {
pub switched: bool,
pub last_frame_clicked: Option<usize>,
pub state: usize,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Switch {
pub appearance: Vec<SwitchAppearanceConfig>,
pub background_type: BackgroundType,
pub text_config: TextConfig,
pub hint_text_config: TextConfig,
pub enable_animation: [bool; 2],
pub state_amount: u32,
pub click_method: Vec<SwitchClickConfig>,
pub radio_group: String,
pub enable: bool,
pub state: usize,
pub last_frame_hovered: bool,
pub last_frame_clicked: Option<usize>,
pub switched: bool,
pub use_switch_tags: bool,
pub tags: Vec<[String; 2]>,
}
impl RustConstructorResource for Switch {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
fn display_display_info(&self) -> Option<DisplayInfo> {
None
}
fn modify_display_info(&mut self, _display_info: DisplayInfo) {}
fn display_tags(&self) -> Vec<[String; 2]> {
self.tags.clone()
}
fn modify_tags(&mut self, tags: &[[String; 2]], replace: bool) {
if replace {
self.tags = tags.to_owned();
} else {
for tag in tags {
if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
self.tags.remove(index);
};
}
self.tags.extend(tags.iter().cloned());
};
}
}
impl Default for Switch {
fn default() -> Self {
Self {
appearance: vec![],
background_type: BackgroundType::default(),
text_config: TextConfig::default(),
hint_text_config: TextConfig::default(),
enable_animation: [false, false],
state_amount: 0,
click_method: vec![],
radio_group: String::new(),
enable: true,
state: 0,
last_frame_hovered: false,
last_frame_clicked: None,
switched: false,
use_switch_tags: false,
tags: Vec::new(),
}
}
}
impl Switch {
#[inline]
pub fn appearance(mut self, appearance: &[SwitchAppearanceConfig]) -> Self {
self.appearance = appearance.to_owned();
self
}
#[inline]
pub fn background_type(mut self, background_type: &BackgroundType) -> Self {
self.background_type = background_type.clone();
self
}
#[inline]
pub fn text_config(mut self, text_config: &TextConfig) -> Self {
self.text_config = text_config.clone();
self
}
#[inline]
pub fn hint_text_config(mut self, hint_text_config: &TextConfig) -> Self {
self.hint_text_config = hint_text_config.clone();
self
}
#[inline]
pub fn enable_animation(mut self, enable_hover: bool, enable_click: bool) -> Self {
self.enable_animation = [enable_hover, enable_click];
self
}
#[inline]
pub fn state_amount(mut self, state_amount: u32) -> Self {
self.state_amount = state_amount;
self
}
#[inline]
pub fn click_method(mut self, click_method: Vec<SwitchClickConfig>) -> Self {
self.click_method = click_method;
self
}
#[inline]
pub fn radio_group(mut self, radio_group: &str) -> Self {
self.radio_group = radio_group.to_string();
self
}
#[inline]
pub fn enable(mut self, enable: bool) -> Self {
self.enable = enable;
self
}
#[inline]
pub fn state(mut self, state: usize) -> Self {
self.state = state;
self
}
#[inline]
pub fn use_switch_tags(mut self, use_switch_tags: bool) -> Self {
self.use_switch_tags = use_switch_tags;
self
}
#[inline]
pub fn tags(mut self, tags: &[[String; 2]], replace: bool) -> Self {
if replace {
self.tags = tags.to_owned();
} else {
for tag in tags {
if let Some(index) = self.tags.iter().position(|x| x[0] == tag[0]) {
self.tags.remove(index);
};
}
self.tags.extend(tags.iter().cloned());
};
self
}
}