Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def cursorForX(x: Int): Either[Side, Int] = {
- var lastX = 0
- if(x < 0)
- return Left(Side.Before)
- for(pos <- 1 to textLength) {
- val thisX = style.font.metrics.charsWidth(text, 0, pos)
- if(x <= thisX)
- return if(x < lastX+(thisX-lastX)/2) Right(pos-1) else Right(pos)
- lastX = thisX
- }
- return Left(Side.After)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement