Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/typography/textboxes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type TextBox* = ref object
vAlign*: VAlignMode
hAling*: HAlignMode
scrollable*: bool
wasScrolled*: bool
editable*: bool
scroll*: Vec2 # Scroll position.
font*: Font
Expand Down Expand Up @@ -195,7 +196,7 @@ proc removeSelection(textBox: TextBox) =

proc adjustScroll*(textBox: TextBox) =
## Adjust scroll to make sure cursor is in the window.
if textBox.scrollable:
if textBox.scrollable and not textBox.wasScrolled:
let
r = textBox.cursorRect
# is pos.y inside the window?
Expand Down Expand Up @@ -464,6 +465,7 @@ proc mouseAction*(
shift = false
) =
## Click on this with a mouse.
textBox.wasScrolled = false
textBox.mousePos = mousePos + textBox.scroll
# Pick where to place the cursor.
let pos = textBox.layout.pickGlyphAt(textBox.mousePos)
Expand Down Expand Up @@ -528,6 +530,7 @@ proc resize*(textBox: TextBox, size: Vec2) =

proc scrollBy*(textBox: TextBox, amount: float) =
## Scroll text box with a scroll wheel.
textBox.wasScrolled = true
textBox.scroll.y += amount
# Make sure it does not scroll off the top.
textBox.scroll.y = max(0, textBox.scroll.y)
Expand All @@ -538,4 +541,4 @@ proc scrollBy*(textBox: TextBox, amount: float) =
)
# Check if there is not enough text to scroll.
if textBox.innerHeight < textBox.height:
textBox.scroll.y = 0
textBox.scroll.y = 0