Skip to content

Commit

Permalink
Apply scale factor to caret and selection positions
Browse files Browse the repository at this point in the history
  • Loading branch information
geom3trik authored and robbert-vdh committed Mar 21, 2022
1 parent 5ca2246 commit 13f554d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions core/src/views/textbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,18 @@ impl TextboxData {
}
}

let scale_factor = cx.style.dpi_factor as f32;

//Draw selection
let select_width = (caretx - selectx).abs();
if selectx > caretx {
self.selection_entity.set_left(cx, Pixels(caretx.floor() - posx - 1.0));
self.selection_entity
.set_left(cx, Pixels((caretx.floor() - posx - 1.0) / scale_factor));
} else if caretx > selectx {
self.selection_entity.set_left(cx, Pixels(selectx.floor() - posx - 1.0));
self.selection_entity
.set_left(cx, Pixels((selectx.floor() - posx - 1.0) / scale_factor));
}

let scale_factor = cx.style.dpi_factor as f32;

self.selection_entity.set_width(cx, Pixels(select_width / scale_factor));
self.selection_entity
.set_height(cx, Pixels(font_metrics.height() / scale_factor));
Expand All @@ -261,7 +263,7 @@ impl TextboxData {

let caret_left = (caretx.floor() - posx - 1.0).max(0.0);

self.caret_entity.set_left(cx, Pixels(caret_left));
self.caret_entity.set_left(cx, Pixels(caret_left / scale_factor));
self.caret_entity.set_top(cx, Stretch(1.0));
self.caret_entity.set_bottom(cx, Stretch(1.0));
self.caret_entity.set_height(cx, Pixels(font_metrics.height() / scale_factor));
Expand Down

0 comments on commit 13f554d

Please sign in to comment.