MCPcopy Create free account
hub / github.com/cogentcore/core / setCursorFromPixel

Method setCursorFromPixel

core/textfield.go:1609–1627  ·  view source on GitHub ↗

setCursorFromPixel finds cursor location from given scene-relative pixel location, and sets current cursor to it, updating selection too.

(pt image.Point, selMode events.SelectModes)

Source from the content-addressed store, hash-verified

1607// setCursorFromPixel finds cursor location from given scene-relative
1608// pixel location, and sets current cursor to it, updating selection too.
1609func (tf *TextField) setCursorFromPixel(pt image.Point, selMode events.SelectModes) {
1610 oldPos := tf.cursorPos
1611 tf.cursorPos = tf.pixelToCursor(pt)
1612 if tf.selectMode || selMode != events.SelectOne {
1613 if !tf.selectMode && selMode != events.SelectOne {
1614 tf.selectStart = oldPos
1615 tf.selectMode = true
1616 }
1617 if !tf.StateIs(states.Sliding) && selMode == events.SelectOne { // && tf.CursorPos >= tf.SelectStart && tf.CursorPos < tf.SelectEnd {
1618 tf.selectReset()
1619 } else {
1620 tf.selectRegionUpdate(tf.cursorPos)
1621 }
1622 tf.selectUpdate()
1623 } else if tf.hasSelection() {
1624 tf.selectReset()
1625 }
1626 tf.NeedsRender()
1627}
1628
1629func (tf *TextField) handleKeyEvents() {
1630 tf.OnKeyChord(func(e events.Event) {

Callers 1

InitMethod · 0.95

Calls 7

pixelToCursorMethod · 0.95
selectResetMethod · 0.95
selectRegionUpdateMethod · 0.95
selectUpdateMethod · 0.95
hasSelectionMethod · 0.95
StateIsMethod · 0.80
NeedsRenderMethod · 0.80

Tested by

no test coverage detected