Skip to content

Commit

Permalink
Use WString instead of String to avoid lossy utf8 conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
crumblingstatue committed Aug 2, 2024
1 parent 19338eb commit 6483e3b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions core/src/debug_ui/avm1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ use crate::debug_ui::handle::{AVM1ObjectHandle, DisplayObjectHandle};
use crate::debug_ui::Message;
use crate::string::AvmString;
use egui::{Grid, Id, TextBuffer, TextEdit, Ui, Window};
use ruffle_wstr::WString;

#[derive(Debug, Default)]
pub struct Avm1ObjectWindow {
hovered_debug_rect: Option<DisplayObjectHandle>,
key_filter_string: String,
edited_key: Option<String>,
edited_key: Option<WString>,
value_edit_buf: String,
/// True if the active text edit should be focused (after clicking 'edit', etc.)
focus_text_edit: bool,
Expand Down Expand Up @@ -143,7 +144,7 @@ impl Avm1ObjectWindow {
if self
.edited_key
.as_ref()
.is_some_and(|edit_key| *edit_key == key.to_utf8_lossy())
.is_some_and(|edit_key| *edit_key == key.as_wstr())
{
ui.horizontal(|ui| {
let re = ui
Expand Down Expand Up @@ -175,7 +176,7 @@ impl Avm1ObjectWindow {
let num_str = num.to_string();
ui.label(&num_str);
if ui.edit_button().clicked() {
self.edited_key = Some(key.to_utf8_lossy().into_owned());
self.edited_key = Some(key.as_wstr().to_owned());
self.value_edit_buf = num_str;
self.focus_text_edit = true;
}
Expand All @@ -194,7 +195,7 @@ impl Avm1ObjectWindow {
if self
.edited_key
.as_ref()
.is_some_and(|edit_key| *edit_key == key.to_utf8_lossy())
.is_some_and(|edit_key| *edit_key == key.as_wstr())
{
let re = ui.add(TextEdit::singleline(&mut self.value_edit_buf).desired_width(96.0));
if self.focus_text_edit {
Expand All @@ -212,7 +213,7 @@ impl Avm1ObjectWindow {
ui.label(string.to_utf8_lossy());
if ui.edit_button().clicked() {
self.value_edit_buf = string.to_string();
self.edited_key = Some(key.to_string());
self.edited_key = Some(key.as_wstr().to_owned());
self.focus_text_edit = true;
}
}
Expand Down

0 comments on commit 6483e3b

Please sign in to comment.