ui stuff
This commit is contained in:
+61
-18
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
fs::write,
|
|
||||||
thread::{sleep, spawn},
|
thread::{sleep, spawn},
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
@@ -10,9 +9,9 @@ use std::{
|
|||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use connector::{Connector, UdpConnector};
|
use connector::{Connector, UdpConnector};
|
||||||
use egui::Ui;
|
use egui::{Layout, Ui};
|
||||||
use log::*;
|
use log::*;
|
||||||
use msg::{DsTlmSet, Msg, TargetMsg, TlmSetItem};
|
use msg::Msg;
|
||||||
use reflect::*;
|
use reflect::*;
|
||||||
use rfe::macros::Reflect;
|
use rfe::macros::Reflect;
|
||||||
use rfe::*;
|
use rfe::*;
|
||||||
@@ -82,14 +81,20 @@ impl Default for MyApp {
|
|||||||
|
|
||||||
fn build_command_ui_value_number(ui: &mut Ui, name: &str, cmd: &mut dyn Reflect) {
|
fn build_command_ui_value_number(ui: &mut Ui, name: &str, cmd: &mut dyn Reflect) {
|
||||||
let mut r = cmd.get_value().str();
|
let mut r = cmd.get_value().str();
|
||||||
ui.horizontal(|ui| {
|
ui.with_layout(
|
||||||
ui.label(name);
|
Layout::left_to_right(egui::Align::Min)
|
||||||
ui.text_edit_singleline(&mut r);
|
.with_main_wrap(true)
|
||||||
cmd.set_value(ReflectValue::Str(r));
|
.with_main_justify(false),
|
||||||
});
|
|ui| {
|
||||||
|
ui.label(name);
|
||||||
|
ui.text_edit_singleline(&mut r);
|
||||||
|
cmd.set_value(ReflectValue::Str(r));
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_command_ui(ui: &mut Ui, name: &str, cmd: &mut dyn Reflect) {
|
fn build_command_ui(ui: &mut Ui, name: &str, cmd: &mut dyn Reflect) {
|
||||||
|
// ui.separator();
|
||||||
match cmd.reflect_type() {
|
match cmd.reflect_type() {
|
||||||
ReflectType::Value => match cmd.get_value() {
|
ReflectType::Value => match cmd.get_value() {
|
||||||
ReflectValue::None => {}
|
ReflectValue::None => {}
|
||||||
@@ -101,18 +106,49 @@ fn build_command_ui(ui: &mut Ui, name: &str, cmd: &mut dyn Reflect) {
|
|||||||
ReflectValue::I16(_) => build_command_ui_value_number(ui, name, cmd),
|
ReflectValue::I16(_) => build_command_ui_value_number(ui, name, cmd),
|
||||||
ReflectValue::I32(_) => build_command_ui_value_number(ui, name, cmd),
|
ReflectValue::I32(_) => build_command_ui_value_number(ui, name, cmd),
|
||||||
ReflectValue::I64(_) => build_command_ui_value_number(ui, name, cmd),
|
ReflectValue::I64(_) => build_command_ui_value_number(ui, name, cmd),
|
||||||
ReflectValue::Vec(_vec) => {}
|
ReflectValue::Vec(_vec) => {
|
||||||
|
ui.with_layout(Layout::top_down(egui::Align::Min), |ui| {
|
||||||
|
ui.with_layout(
|
||||||
|
Layout::left_to_right(egui::Align::Min).with_main_wrap(true),
|
||||||
|
|ui| {
|
||||||
|
ui.label(name);
|
||||||
|
if ui.button("+").clicked() {
|
||||||
|
cmd.vec_add();
|
||||||
|
}
|
||||||
|
if ui.button("-").clicked() {
|
||||||
|
cmd.vec_remove();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if let Some(v) = cmd.as_vec() {
|
||||||
|
ui.with_layout(
|
||||||
|
Layout::left_to_right(egui::Align::Min).with_main_wrap(true),
|
||||||
|
|ui| {
|
||||||
|
for (i, cmd) in v.into_iter().enumerate() {
|
||||||
|
build_command_ui(ui, &format!("[{i}]"), cmd);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
ReflectValue::Str(_) => {}
|
ReflectValue::Str(_) => {}
|
||||||
ReflectValue::Bool(_) => {}
|
ReflectValue::Bool(_) => {}
|
||||||
},
|
},
|
||||||
ReflectType::Enumeration => {
|
ReflectType::Enumeration => {
|
||||||
// variants
|
// variants
|
||||||
|
ui.with_layout(
|
||||||
for (i, (name, _v)) in cmd.variants().into_iter().enumerate() {
|
Layout::left_to_right(egui::Align::Min)
|
||||||
if ui.button(name).clicked() {
|
.with_main_wrap(true)
|
||||||
cmd.convert_variant(i);
|
.with_main_justify(false),
|
||||||
}
|
|ui| {
|
||||||
}
|
for (i, (name, _v)) in cmd.variants().into_iter().enumerate() {
|
||||||
|
if ui.button(name).clicked() {
|
||||||
|
cmd.convert_variant(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// values
|
// values
|
||||||
if let Some((name, cmd)) = cmd.unwrap_variant() {
|
if let Some((name, cmd)) = cmd.unwrap_variant() {
|
||||||
@@ -120,9 +156,16 @@ fn build_command_ui(ui: &mut Ui, name: &str, cmd: &mut dyn Reflect) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ReflectType::Structure => {
|
ReflectType::Structure => {
|
||||||
for (name, cmd) in cmd.fields().into_iter() {
|
ui.with_layout(
|
||||||
build_command_ui(ui, name, cmd);
|
Layout::left_to_right(egui::Align::Min)
|
||||||
}
|
.with_main_wrap(true)
|
||||||
|
.with_main_justify(false),
|
||||||
|
|ui| {
|
||||||
|
for (name, cmd) in cmd.fields().into_iter() {
|
||||||
|
build_command_ui(ui, name, cmd);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-1
@@ -17,6 +17,8 @@ pub trait Reflect: std::fmt::Debug {
|
|||||||
fn convert_variant(&mut self, i: usize);
|
fn convert_variant(&mut self, i: usize);
|
||||||
fn unwrap_variant(&mut self) -> Option<(&str, &mut dyn Reflect)>;
|
fn unwrap_variant(&mut self) -> Option<(&str, &mut dyn Reflect)>;
|
||||||
fn as_vec(&mut self) -> Option<Vec<&mut dyn Reflect>>;
|
fn as_vec(&mut self) -> Option<Vec<&mut dyn Reflect>>;
|
||||||
|
fn vec_add(&mut self) {}
|
||||||
|
fn vec_remove(&mut self) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
@@ -584,7 +586,7 @@ impl Reflect for bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Reflect> Reflect for Vec<T> {
|
impl<T: Reflect + Default> Reflect for Vec<T> {
|
||||||
fn reflect_type(&self) -> ReflectType {
|
fn reflect_type(&self) -> ReflectType {
|
||||||
ReflectType::Value
|
ReflectType::Value
|
||||||
}
|
}
|
||||||
@@ -634,4 +636,14 @@ impl<T: Reflect> Reflect for Vec<T> {
|
|||||||
.collect(),
|
.collect(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn vec_add(&mut self) {
|
||||||
|
self.push(Default::default());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn vec_remove(&mut self) {
|
||||||
|
if self.len() > 0 {
|
||||||
|
self.remove(self.len() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user