From 8cd17c0e628ecb821df3656b9794f8508f31646a Mon Sep 17 00:00:00 2001 From: crumblingstatue Date: Sat, 27 Jul 2024 22:12:06 +0200 Subject: [PATCH] [Draft] [debug ui] Make some object properties editable --- core/src/debug_ui/avm1.rs | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/core/src/debug_ui/avm1.rs b/core/src/debug_ui/avm1.rs index eb45a003204d..b341d288feba 100644 --- a/core/src/debug_ui/avm1.rs +++ b/core/src/debug_ui/avm1.rs @@ -8,6 +8,7 @@ use egui::{Grid, Id, TextEdit, Ui, Window}; #[derive(Debug, Default)] pub struct Avm1ObjectWindow { hovered_debug_rect: Option, + key_filter_string: String, } impl Avm1ObjectWindow { @@ -39,18 +40,34 @@ impl Avm1ObjectWindow { .show(ui, |ui| { let mut keys = object.get_keys(&mut activation, true); keys.sort(); + ui.add( + egui::TextEdit::singleline(&mut self.key_filter_string) + .hint_text("🔍 Filter"), + ); + ui.end_row(); + keys.retain(|key| { + self.key_filter_string.is_empty() + || key + .to_string() + .to_ascii_lowercase() + .contains(&self.key_filter_string.to_ascii_lowercase()) + }); for key in keys { let value = object.get(key, &mut activation); ui.label(key.to_string()); - show_avm1_value( + if let Some(new) = show_avm1_value( ui, &mut activation, value, messages, &mut self.hovered_debug_rect, - ); + ) { + if let Err(e) = object.set(key, new, &mut activation) { + tracing::error!("Failed to set key {key}: {e}"); + } + } ui.end_row(); } }); @@ -77,7 +94,7 @@ pub fn show_avm1_value<'gc>( value: Result, Error<'gc>>, messages: &mut Vec, hover: &mut Option, -) { +) -> Option> { match value { Ok(Value::Undefined) => { ui.label("Undefined"); @@ -85,11 +102,15 @@ pub fn show_avm1_value<'gc>( Ok(Value::Null) => { ui.label("Null"); } - Ok(Value::Bool(value)) => { - ui.label(value.to_string()); + Ok(Value::Bool(mut value)) => { + if ui.checkbox(&mut value, "").clicked() { + return Some(Value::Bool(value)); + } } - Ok(Value::Number(value)) => { - ui.label(value.to_string()); + Ok(Value::Number(mut value)) => { + if ui.add(egui::DragValue::new(&mut value)).changed() { + return Some(Value::Number(value)); + } } Ok(Value::String(value)) => { TextEdit::singleline(&mut value.to_string()).show(ui); @@ -118,4 +139,5 @@ pub fn show_avm1_value<'gc>( ui.colored_label(ui.style().visuals.error_fg_color, e.to_string()); } } + None }