Skip to content

Commit

Permalink
debug_ui: Add option to draw layout boxes for EditText
Browse files Browse the repository at this point in the history
  • Loading branch information
kjarosh authored and Dinnerbone committed Jun 19, 2024
1 parent e4a37ef commit 687e049
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/src/debug_ui/display_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,16 @@ impl DisplayObjectWindow {
ui.weak("None");
}
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")
Expand Down
28 changes: 28 additions & 0 deletions core/src/display_object/edit_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,20 @@ impl<'gc> EditText<'gc> {
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(
self,
from: usize,
Expand Down Expand Up @@ -2275,7 +2289,20 @@ impl<'gc> TDisplayObject<'gc> for EditText<'gc> {
}
}
} 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() {
if draw_boxes {
context.draw_rect_outline(Color::RED, layout_box.bounds().into(), Twips::ONE);
}

self.render_layout_box(context, layout_box);
}
}
Expand Down Expand Up @@ -2525,6 +2552,7 @@ bitflags::bitflags! {
struct EditTextFlag: u16 {
const FIRING_VARIABLE_BINDING = 1 << 0;
const HAS_BACKGROUND = 1 << 1;
const DRAW_LAYOUT_BOXES = 1 << 2;

// The following bits need to match `swf::EditTextFlag`.
const READ_ONLY = 1 << 3;
Expand Down

0 comments on commit 687e049

Please sign in to comment.