Skip to content

Commit

Permalink
text: Render caret using lines
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kjarosh authored and Dinnerbone committed Jul 3, 2024
1 parent 772518d commit 5aaff96
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions core/src/display_object/edit_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,15 +1008,17 @@ impl<'gc> EditText<'gc> {
height: Twips,
color: Color,
) {
let cursor_width = Twips::from_pixels(1.0);
let caret = context.transform_stack.transform().matrix
* Matrix::create_box(
cursor_width.to_pixels() as f32,
let mut caret = context.transform_stack.transform().matrix
* Matrix::create_box_with_rotation(
1.0,
height.to_pixels() as f32,
x - cursor_width,
std::f32::consts::FRAC_PI_2,
x,
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.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5aaff96

Please sign in to comment.