use egui::Ui;
use crate::widget::scalar_field_view::FieldPick;
#[derive(Clone, Copy, Debug, Default)]
pub struct ScenePositionInfo {
last: Option<FieldPick>,
}
impl ScenePositionInfo {
pub fn new() -> Self {
Self::default()
}
pub fn set(&mut self, pick: Option<FieldPick>) {
self.last = pick;
}
pub fn clear(&mut self) {
self.last = None;
}
pub fn last(&self) -> Option<FieldPick> {
self.last
}
pub fn ui(&self, ui: &mut Ui) {
let (x, y, z) = match self.last {
Some(p) => (g(p.position.x), g(p.position.y), g(p.position.z)),
None => (dash(), dash(), dash()),
};
let data = match self.last.and_then(|p| p.value) {
Some(v) => g(v),
None => dash(),
};
ui.horizontal(|ui| {
ui.label(format!("X: {x}"));
ui.separator();
ui.label(format!("Y: {y}"));
ui.separator();
ui.label(format!("Z: {z}"));
ui.separator();
ui.label(format!("Data: {data}"));
});
}
}
fn dash() -> String {
"-".to_string()
}
fn g(v: f32) -> String {
format!("{v}")
}