debug_ui: Add option to draw layout boxes for EditText

This commit is contained in:
Kamil Jarosz 2024-06-19 18:41:07 +02:00 committed by Nathan Adams
parent e4a37efddf
commit 687e049dc1
2 changed files with 38 additions and 0 deletions

View File

@ -460,6 +460,16 @@ impl DisplayObjectWindow {
ui.weak("None"); ui.weak("None");
} }
ui.end_row(); ui.end_row();
ui.label("Draw Layout Boxes");
ui.horizontal(|ui| {
let mut draw_layout_boxes = object.draw_layout_boxes();
ui.checkbox(&mut draw_layout_boxes, "Enabled");
if draw_layout_boxes != object.draw_layout_boxes() {
object.set_draw_layout_boxes(context, draw_layout_boxes);
}
});
ui.end_row();
}); });
CollapsingHeader::new("Span List") CollapsingHeader::new("Span List")

View File

@ -659,6 +659,20 @@ impl<'gc> EditText<'gc> {
self.0.write(gc_context).is_tlf = is_tlf; self.0.write(gc_context).is_tlf = is_tlf;
} }
pub fn draw_layout_boxes(self) -> bool {
self.0
.read()
.flags
.contains(EditTextFlag::DRAW_LAYOUT_BOXES)
}
pub fn set_draw_layout_boxes(self, context: &mut UpdateContext<'_, 'gc>, value: bool) {
self.0
.write(context.gc())
.flags
.set(EditTextFlag::DRAW_LAYOUT_BOXES, value);
}
pub fn replace_text( pub fn replace_text(
self, self,
from: usize, from: usize,
@ -2275,7 +2289,20 @@ impl<'gc> TDisplayObject<'gc> for EditText<'gc> {
} }
} }
} else { } else {
let draw_boxes = edit_text.flags.contains(EditTextFlag::DRAW_LAYOUT_BOXES);
if draw_boxes {
context.draw_rect_outline(
Color::GREEN,
edit_text.intrinsic_bounds.into(),
Twips::ONE,
);
}
for layout_box in edit_text.layout.iter() { for layout_box in edit_text.layout.iter() {
if draw_boxes {
context.draw_rect_outline(Color::RED, layout_box.bounds().into(), Twips::ONE);
}
self.render_layout_box(context, layout_box); self.render_layout_box(context, layout_box);
} }
} }
@ -2525,6 +2552,7 @@ bitflags::bitflags! {
struct EditTextFlag: u16 { struct EditTextFlag: u16 {
const FIRING_VARIABLE_BINDING = 1 << 0; const FIRING_VARIABLE_BINDING = 1 << 0;
const HAS_BACKGROUND = 1 << 1; const HAS_BACKGROUND = 1 << 1;
const DRAW_LAYOUT_BOXES = 1 << 2;
// The following bits need to match `swf::EditTextFlag`. // The following bits need to match `swf::EditTextFlag`.
const READ_ONLY = 1 << 3; const READ_ONLY = 1 << 3;