Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug_ui: Improve EditText #18519

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions core/src/debug_ui/display_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ pub struct DisplayObjectWindow {
hovered_debug_rect: Option<DisplayObjectHandle>,
hovered_bounds: Option<Rectangle<Twips>>,
search: String,

/// A buffer for editing EditText
html_text: String,
}

impl Default for DisplayObjectWindow {
Expand All @@ -89,6 +92,7 @@ impl Default for DisplayObjectWindow {
hovered_debug_rect: None,
hovered_bounds: None,
search: Default::default(),
html_text: Default::default(),
}
}
}
Expand Down Expand Up @@ -335,6 +339,10 @@ impl DisplayObjectWindow {
});
ui.end_row();

ui.label("Font Type");
ui.label(format!("{:?}", object.font_type()));
ui.end_row();

ui.label("Editable");
ui.horizontal(|ui| {
let mut editable = object.is_editable();
Expand Down Expand Up @@ -395,6 +403,26 @@ impl DisplayObjectWindow {
});
ui.end_row();

ui.label("Always Show Selection");
ui.horizontal(|ui| {
let mut always_show_selection = object.always_show_selection();
ui.checkbox(&mut always_show_selection, "Enabled");
if always_show_selection != object.always_show_selection() {
object.set_always_show_selection(context, always_show_selection);
}
});
ui.end_row();

ui.label("Condense White");
ui.horizontal(|ui| {
let mut condense_white = object.condense_white();
ui.checkbox(&mut condense_white, "Enabled");
if condense_white != object.condense_white() {
object.set_condense_white(context, condense_white);
}
});
ui.end_row();

ui.label("Autosize");
ui.horizontal(|ui| {
let mut autosize = object.autosize();
Expand Down Expand Up @@ -485,6 +513,14 @@ impl DisplayObjectWindow {
}
});
ui.end_row();

ui.label("Actions");
ui.vertical(|ui| {
if ui.button("Relayout").clicked() {
object.relayout(context);
}
});
ui.end_row();
});

CollapsingHeader::new("Span List")
Expand Down Expand Up @@ -522,6 +558,26 @@ impl DisplayObjectWindow {
}
});
});

let html_text_response = CollapsingHeader::new("HTML Text")
.id_salt(ui.id().with("html-text"))
.show(ui, |ui| {
ui.add_sized(
ui.available_size(),
TextEdit::multiline(&mut self.html_text),
);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if ui.button("Set").clicked() {
object.set_html_text(&WString::from_utf8(&self.html_text), context);
}
if ui.button("Reset").clicked() {
self.html_text = object.html_text().to_string();
}
});
});
if html_text_response.fully_closed() {
self.html_text = object.html_text().to_string();
}
}

pub fn show_avm2_button<'gc>(
Expand Down
26 changes: 16 additions & 10 deletions core/src/display_object/edit_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ impl EditTextData<'_> {
Twips::ZERO
}
}

fn font_type(&self) -> FontType {
if !self.flags.contains(EditTextFlag::USE_OUTLINES) {
FontType::Device
} else if self.is_tlf {
FontType::EmbeddedCFF
} else {
FontType::Embedded
}
}
}

impl<'gc> EditText<'gc> {
Expand Down Expand Up @@ -612,6 +622,10 @@ impl<'gc> EditText<'gc> {
self.relayout(context);
}

pub fn font_type(self) -> FontType {
self.0.read().font_type()
}

pub fn is_html(self) -> bool {
self.0.read().flags.contains(EditTextFlag::HTML)
}
Expand Down Expand Up @@ -762,7 +776,7 @@ impl<'gc> EditText<'gc> {
/// the text, and no higher-level representation. Specifically, CSS should
/// have already been calculated and applied to HTML trees lowered into the
/// text-span representation.
fn relayout(self, context: &mut UpdateContext<'gc>) {
pub fn relayout(self, context: &mut UpdateContext<'gc>) {
let mut edit_text = self.0.write(context.gc_context);
let autosize = edit_text.autosize;
let is_word_wrap = edit_text.flags.contains(EditTextFlag::WORD_WRAP);
Expand All @@ -784,21 +798,13 @@ impl<'gc> EditText<'gc> {
edit_text.bounds.width() - padding
};

let font_type = if !edit_text.flags.contains(EditTextFlag::USE_OUTLINES) {
FontType::Device
} else if edit_text.is_tlf {
FontType::EmbeddedCFF
} else {
FontType::Embedded
};

let new_layout = html::lower_from_text_spans(
&edit_text.text_spans,
context,
movie,
content_width,
is_word_wrap,
font_type,
edit_text.font_type(),
);

edit_text.layout = new_layout;
Expand Down