mirror of
https://github.com/danbulant/cushy
synced 2026-06-11 18:40:36 +00:00
Fixing various mouse selection bugs
Realized that I was skipping invisible glyphs during construction of MeasuredText. Once those were in, most of the issues vanished. A few small tweaks and now it works surprisingly well.
This commit is contained in:
parent
d7d0d6eb56
commit
d7d06e41fa
2 changed files with 22 additions and 13 deletions
14
Cargo.lock
generated
14
Cargo.lock
generated
|
|
@ -524,9 +524,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "derive-where"
|
||||
version = "1.2.6"
|
||||
version = "1.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48d9b1fc2a6d7e19c89e706a3769e31ee862ac7a4c810c7c0ff3910e1a42a4ce"
|
||||
checksum = "62d671cc41a825ebabc75757b62d3d168c577f9149b2d49ece1dad1f72119d25"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
@ -1062,7 +1062,7 @@ checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
|
|||
[[package]]
|
||||
name = "kludgine"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/khonsulabs/kludgine#2fffa618dda72fae415b2d25faf9dfe461662246"
|
||||
source = "git+https://github.com/khonsulabs/kludgine#6dc4c1c7901ca8a76148d6efe2b52961352efdc1"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"alot",
|
||||
|
|
@ -3115,18 +3115,18 @@ checksum = "dd15f8e0dbb966fd9245e7498c7e9e5055d9e5c8b676b95bd67091cd11a1e697"
|
|||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.7.30"
|
||||
version = "0.7.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "306dca4455518f1f31635ec308b6b3e4eb1b11758cefafc782827d0aa7acb5c7"
|
||||
checksum = "1c4061bedbb353041c12f413700357bec76df2c7e2ca8e4df8bac24c6bf68e3d"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.7.30"
|
||||
version = "0.7.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be912bf68235a88fbefd1b73415cb218405958d1655b2ece9035a19920bdf6ba"
|
||||
checksum = "b3c129550b3e6de3fd0ba67ba5c81818f9805e58b8d7fee80a3a59d2c9fc601a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use kludgine::app::winit::keyboard::{Key, NamedKey};
|
|||
use kludgine::app::winit::window::{CursorIcon, ImePurpose};
|
||||
use kludgine::figures::units::{Lp, Px, UPx};
|
||||
use kludgine::figures::{
|
||||
FloatConversion, IntoSigned, IntoUnsigned, Point, Rect, ScreenScale, Size,
|
||||
Abs, FloatConversion, IntoSigned, IntoUnsigned, Point, Rect, ScreenScale, Size,
|
||||
};
|
||||
use kludgine::shapes::{Shape, StrokeOptions};
|
||||
use kludgine::text::{MeasuredText, Text, TextOrigin};
|
||||
|
|
@ -840,12 +840,15 @@ where
|
|||
.line_height
|
||||
.saturating_mul(Px::new(i32::try_from(current_line).unwrap_or(i32::MAX)));
|
||||
}
|
||||
let rect = glyph.rect();
|
||||
let mut rect = glyph.rect();
|
||||
if !glyph.visible() {
|
||||
rect.size.height = cache.measured.line_height;
|
||||
}
|
||||
let relative = location - Point::new(rect.origin.x, current_line_y);
|
||||
if relative.x >= 0
|
||||
&& relative.y >= 0
|
||||
&& relative.x < rect.size.width
|
||||
&& relative.y < cache.measured.line_height
|
||||
&& relative.x <= rect.size.width
|
||||
&& relative.y <= cache.measured.line_height
|
||||
{
|
||||
return if relative.x > rect.size.width / 2 {
|
||||
if glyph.info.start + 1 < cache.bytes {
|
||||
|
|
@ -869,10 +872,15 @@ where
|
|||
|
||||
// Make relative be relative to the center of the glyph for a nearest search.
|
||||
let relative = relative + rect.size / 2;
|
||||
|
||||
let line_height = cache.measured.line_height.get();
|
||||
let xy = relative
|
||||
.x
|
||||
.get()
|
||||
.saturating_mul(current_line_y.get().saturating_pow(2))
|
||||
.saturating_mul(
|
||||
((relative.y.get() + line_height - 1) / line_height * line_height)
|
||||
.saturating_pow(2),
|
||||
)
|
||||
.saturating_abs();
|
||||
let cursor = Cursor {
|
||||
offset: if relative.x < 0 || relative.y < 0 {
|
||||
|
|
@ -898,7 +906,8 @@ where
|
|||
// so that it's easier to inspect and detect when there's
|
||||
// whitespace. For now, this is just a hack that helps get *some*
|
||||
// selection at the end of the input for trailing whitespace.
|
||||
if relative.x < 0 && index < cache.measured.glyphs.len() {
|
||||
if relative.x.abs() < cache.measured.line_height && index < cache.measured.glyphs.len()
|
||||
{
|
||||
return closest;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue