#[derive(Clone, Debug, PartialEq)]
pub enum FieldKind {
Toggle,
Slider { min: f64, max: f64, step: f64 },
Dropdown { options: Vec<String> },
TextInput,
Button { action: String },
Custom { type_name: String },
}
#[derive(Clone, Debug, Default)]
pub struct ValidationRules {
pub range: Option<(f64, f64)>,
pub length: Option<(usize, usize)>,
pub pattern: Option<String>,
pub required: bool,
pub error_message: Option<String>,
}
#[derive(Clone, Debug)]
pub struct ConfirmationConfig {
pub title: String,
pub message: String,
pub confirm_text: String,
pub cancel_text: String,
pub is_dangerous: bool,
}
impl Default for ConfirmationConfig {
fn default() -> Self {
Self {
title: "Confirm Change".into(),
message: "Are you sure you want to change this setting?".into(),
confirm_text: "Confirm".into(),
cancel_text: "Cancel".into(),
is_dangerous: false,
}
}
}
#[derive(Clone, Debug)]
pub struct FieldMeta {
pub name: &'static str,
pub key: &'static str,
pub title: &'static str,
pub description: &'static str,
pub category: &'static str,
pub category_order: i32,
pub kind: FieldKind,
pub depends_on: Option<&'static str>,
pub is_persisted_only: bool,
pub no_reset: bool,
pub confirm_reset: Option<&'static str>,
pub validation: Option<ValidationRules>,
pub confirmation: Option<ConfirmationConfig>,
pub platforms: Vec<&'static str>,
}
impl Default for FieldMeta {
fn default() -> Self {
Self {
name: "",
key: "",
title: "",
description: "",
category: "",
category_order: 0,
kind: FieldKind::Toggle,
depends_on: None,
is_persisted_only: false,
no_reset: false,
confirm_reset: None,
validation: None,
confirmation: None,
platforms: Vec::new(),
}
}
}
impl FieldMeta {
pub fn is_visible_on_current_platform(&self) -> bool {
if self.platforms.is_empty() {
return true;
}
let current = current_platform_name();
for &p in &self.platforms {
if p == "all" {
return true;
}
if p == current {
return true;
}
if p == "desktop" && matches!(current, "windows" | "macos" | "linux") {
return true;
}
}
false
}
}
fn current_platform_name() -> &'static str {
#[cfg(target_os = "android")]
{
"android"
}
#[cfg(target_os = "ios")]
{
"ios"
}
#[cfg(target_os = "windows")]
{
"windows"
}
#[cfg(target_os = "macos")]
{
"macos"
}
#[cfg(target_os = "linux")]
{
"linux"
}
#[cfg(not(any(
target_os = "android",
target_os = "ios",
target_os = "windows",
target_os = "macos",
target_os = "linux"
)))]
{
"unknown"
}
}