Skip to content

Commit

Permalink
Snap the TextBox cursor to the pixel grid
Browse files Browse the repository at this point in the history
This snaps the cursor of the TextBox to the grid to ensure it's always
rendered as sharp as possible.
  • Loading branch information
CryZe authored and cmyr committed Jun 30, 2021
1 parent f50695d commit e2bb4fb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion druid/src/widget/textbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,12 +606,16 @@ impl<T: TextStorage + EditableText> Widget<T> for TextBox<T> {

let padding_offset = Vec2::new(textbox_insets.x0, textbox_insets.y0);

let cursor = if data.is_empty() {
let mut cursor = if data.is_empty() {
cursor_line + padding_offset
} else {
cursor_line + padding_offset - self.inner.offset()
};

// Snap the cursor to the pixel grid so it stays sharp.
cursor.p0.x = cursor.p0.x.trunc() + 0.5;
cursor.p1.x = cursor.p0.x;

ctx.with_save(|ctx| {
ctx.clip(clip_rect);
ctx.stroke(cursor, &cursor_color, 1.);
Expand Down

0 comments on commit e2bb4fb

Please sign in to comment.