text: Render caret using lines

This patch makes the caret be drawn using lines.
This ensures that the width of the caret is always 1px.

Additionally, it improves caret positioning, so that it's closer to FP.
This commit is contained in:
Kamil Jarosz 2024-06-25 12:46:27 +02:00 committed by Nathan Adams
parent 772518d25a
commit 5aaff966aa
2 changed files with 8 additions and 6 deletions

View File

@ -1008,15 +1008,17 @@ impl<'gc> EditText<'gc> {
height: Twips, height: Twips,
color: Color, color: Color,
) { ) {
let cursor_width = Twips::from_pixels(1.0); let mut caret = context.transform_stack.transform().matrix
let caret = context.transform_stack.transform().matrix * Matrix::create_box_with_rotation(
* Matrix::create_box( 1.0,
cursor_width.to_pixels() as f32,
height.to_pixels() as f32, height.to_pixels() as f32,
x - cursor_width, std::f32::consts::FRAC_PI_2,
x,
Twips::ZERO, Twips::ZERO,
); );
context.commands.draw_rect(color, caret); let pixel_snapping = EditTextPixelSnapping::new(context.stage.quality());
pixel_snapping.apply(&mut caret);
context.commands.draw_line(color, caret);
} }
/// Attempts to bind this text field to a property of a display object. /// Attempts to bind this text field to a property of a display object.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 363 B

After

Width:  |  Height:  |  Size: 362 B