ux-dx 0.2.1

3D Graphics Primitives for Angular Rust
Documentation
//! Object Inspector using Immediate UI

#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]

use crate::ui::immediate::Ui;

mod default;
mod slider;

pub use default::*;
pub use slider::*;

/// Options for rendering a value as a struct (i.e. draw all of its subfields)
#[derive(Debug, Default)]
pub struct InspectArgsStruct {
    pub header: Option<bool>,
    pub indent_children: Option<bool>,
}

impl From<InspectArgsDefault> for InspectArgsStruct {
    fn from(default_args: InspectArgsDefault) -> Self {
        Self {
            header: default_args.header,
            indent_children: default_args.indent_children,
        }
    }
}

/// Renders a struct (i.e. draw all of its subfields). 
/// 
/// Most traits are implemented by hand-written code, but this trait
/// is normally generated by putting `#[derive(Inspect)]` on a struct
pub trait InspectRenderStruct<T> {
    fn render(data: &[&T], label: &'static str, ui: &mut Ui, args: &InspectArgsStruct);
    fn render_mut(
        data: &mut [&mut T],
        label: &'static str,
        ui: &mut Ui,
        args: &InspectArgsStruct,
    ) -> bool;
}

/// Utility fn that, given a list of references, returns Some(T) if they are the same, otherwise None
pub fn same_or_none<T: PartialEq + Clone>(data: &[&T]) -> Option<T> {
    if data.is_empty() {
        return None;
    }

    let first = data[0].clone();
    for d in data {
        if **d != first {
            return None;
        }
    }

    Some(first)
}

/// Utility fn that, given a list of references, returns Some(T) if they are the same, otherwise None
fn same_or_none_mut<T: PartialEq + Clone>(data: &mut [&mut T]) -> Option<T> {
    if data.is_empty() {
        return None;
    }

    let first = data[0].clone();
    for d in data {
        if **d != first {
            return None;
        }
    }

    Some(first)
}