Skip to content

Commit

Permalink
[Draft] [debug ui] Make some object properties editable
Browse files Browse the repository at this point in the history
  • Loading branch information
crumblingstatue committed Jul 27, 2024
1 parent ad4a65e commit 8cd17c0
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions core/src/debug_ui/avm1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use egui::{Grid, Id, TextEdit, Ui, Window};
#[derive(Debug, Default)]
pub struct Avm1ObjectWindow {
hovered_debug_rect: Option<DisplayObjectHandle>,
key_filter_string: String,
}

impl Avm1ObjectWindow {
Expand Down Expand Up @@ -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();
}
});
Expand All @@ -77,19 +94,23 @@ pub fn show_avm1_value<'gc>(
value: Result<Value<'gc>, Error<'gc>>,
messages: &mut Vec<Message>,
hover: &mut Option<DisplayObjectHandle>,
) {
) -> Option<Value<'gc>> {
match value {
Ok(Value::Undefined) => {
ui.label("Undefined");
}
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);
Expand Down Expand Up @@ -118,4 +139,5 @@ pub fn show_avm1_value<'gc>(
ui.colored_label(ui.style().visuals.error_fg_color, e.to_string());
}
}
None
}

0 comments on commit 8cd17c0

Please sign in to comment.