Skip to content

Commit

Permalink
rename SetFocus to SetFocusQuiet and SetFocusEvent to SetFocus; the e…
Browse files Browse the repository at this point in the history
…vent version is more common, so quiet should be the one with a suffix
  • Loading branch information
kkoreilly committed Nov 25, 2024
1 parent b1f9dae commit 9b575b3
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 58 deletions.
30 changes: 15 additions & 15 deletions core/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ func (em *Events) handleFocusEvent(e events.Event) {
if DebugSettings.FocusTrace {
fmt.Println(em.scene, "StartFocus:", em.startFocus)
}
em.setFocusEvent(em.startFocus)
em.setFocus(em.startFocus)
case em.prevFocus != nil:
if DebugSettings.FocusTrace {
fmt.Println(em.scene, "PrevFocus:", em.prevFocus)
}
em.setFocusEvent(em.prevFocus)
em.setFocus(em.prevFocus)
em.prevFocus = nil
}
}
Expand Down Expand Up @@ -881,14 +881,14 @@ func (em *Events) focusClear() bool {
}
em.prevFocus = em.focus
}
return em.setFocusEvent(nil)
return em.setFocus(nil)
}

// setFocus sets focus to given item, and returns true if focus changed.
// setFocusQuiet sets focus to given item, and returns true if focus changed.
// If item is nil, then nothing has focus.
// This does NOT send the events.Focus event to the widget.
// See [SetFocusEvent] for version that does send event.
func (em *Events) setFocus(w Widget) bool {
// This does NOT send the [events.Focus] event to the widget.
// See [Events.setFocus] for version that does send an event.
func (em *Events) setFocusQuiet(w Widget) bool {
if DebugSettings.FocusTrace {
fmt.Println(em.scene, "SetFocus:", w)
}
Expand All @@ -905,11 +905,11 @@ func (em *Events) setFocus(w Widget) bool {
return got
}

// setFocusEvent sets focus to given item, and returns true if focus changed.
// setFocus sets focus to given item, and returns true if focus changed.
// If item is nil, then nothing has focus.
// This sends the [events.Focus] event to the widget.
// See [SetFocus] for a version that does not.
func (em *Events) setFocusEvent(w Widget) bool {
// See [Events.setFocusQuiet] for a version that does not.
func (em *Events) setFocus(w Widget) bool {
if DebugSettings.FocusTrace {
fmt.Println(em.scene, "SetFocusEvent:", w)
}
Expand Down Expand Up @@ -975,7 +975,7 @@ func (em *Events) FocusNextFrom(from Widget) bool {
wb := w.AsWidget()
return wb.IsVisible() && !wb.StateIs(states.Disabled) && wb.AbilityIs(abilities.Focusable)
})
em.setFocusEvent(next)
em.setFocus(next)
return next != nil
}

Expand All @@ -991,7 +991,7 @@ func (em *Events) focusOnOrNext(foc Widget) bool {
return false
}
if wb.AbilityIs(abilities.Focusable) {
em.setFocusEvent(foc)
em.setFocus(foc)
return true
}
return em.FocusNextFrom(foc)
Expand All @@ -1009,7 +1009,7 @@ func (em *Events) focusOnOrPrev(foc Widget) bool {
return false
}
if wb.AbilityIs(abilities.Focusable) {
em.setFocusEvent(foc)
em.setFocus(foc)
return true
}
return em.focusPrevFrom(foc)
Expand All @@ -1031,7 +1031,7 @@ func (em *Events) focusPrevFrom(from Widget) bool {
wb := w.AsWidget()
return wb.IsVisible() && !wb.StateIs(states.Disabled) && wb.AbilityIs(abilities.Focusable)
})
em.setFocusEvent(prev)
em.setFocus(prev)
return prev != nil
}

Expand Down Expand Up @@ -1072,7 +1072,7 @@ func (em *Events) activateStartFocus() bool {
em.focusFirst()
} else {
// fmt.Println("start focus on:", sf)
em.setFocusEvent(sf)
em.setFocus(sf)
}
return true
}
Expand Down
2 changes: 1 addition & 1 deletion core/filepicker.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (fp *FilePicker) Init() {
case keymap.Search:
e.SetHandled()
sf := fp.selectField
sf.SetFocusEvent()
sf.SetFocus()
}
})

Expand Down
2 changes: 1 addition & 1 deletion core/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func (fr *Frame) focusOnName(e events.Event) bool {
if focel != nil {
em := fr.Events()
if em != nil {
em.setFocusEvent(focel.(Widget)) // this will also scroll by default!
em.setFocus(focel.(Widget)) // this will also scroll by default!
}
fr.focusNameLast = focel
return true
Expand Down
4 changes: 2 additions & 2 deletions core/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ func (lb *ListBase) MakeGrid(p *tree.Plan, maker func(p *tree.Plan)) {
s.Min.Y.Em(6)
})
oc := func(e events.Event) {
lb.SetFocusEvent()
lb.SetFocus()
row, _, isValid := w.indexFromPixel(e.Pos())
if isValid {
lb.updateSelectRow(row, e.SelectMode())
Expand Down Expand Up @@ -868,7 +868,7 @@ func (lb *ListBase) RowGrabFocus(row int) *WidgetBase {
return w
}
lb.InFocusGrab = true
w.SetFocusEvent()
w.SetFocus()
lb.InFocusGrab = false
return w
}
Expand Down
2 changes: 1 addition & 1 deletion core/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func (tb *Table) RowGrabFocus(row int) *WidgetBase {
for fli := 0; fli < tb.numVisibleFields; fli++ {
w := lg.Child(ridx + idxOff + fli).(Widget).AsWidget()
if w.CanFocus() {
w.SetFocusEvent()
w.SetFocus()
return w
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (tx *Text) Init() {
})
tx.OnDoubleClick(func(e events.Event) {
tx.SetSelected(true)
tx.SetFocus()
tx.SetFocusQuiet()
})
tx.OnFocusLost(func(e events.Event) {
tx.SetSelected(false)
Expand Down
10 changes: 5 additions & 5 deletions core/textfield.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (tf *TextField) Init() {
})
tf.On(events.MouseDown, func(e events.Event) {
if !tf.StateIs(states.Focused) {
tf.SetFocusEvent() // always grab, even if read only..
tf.SetFocus() // always grab, even if read only..
}
if tf.IsReadOnly() {
return
Expand All @@ -309,14 +309,14 @@ func (tf *TextField) Init() {
if tf.IsReadOnly() {
return
}
tf.SetFocusEvent()
tf.SetFocus()
})
tf.On(events.DoubleClick, func(e events.Event) {
if tf.IsReadOnly() {
return
}
if !tf.IsReadOnly() && !tf.StateIs(states.Focused) {
tf.SetFocusEvent()
tf.SetFocus()
}
e.SetHandled()
tf.selectWord()
Expand All @@ -326,7 +326,7 @@ func (tf *TextField) Init() {
return
}
if !tf.IsReadOnly() && !tf.StateIs(states.Focused) {
tf.SetFocusEvent()
tf.SetFocus()
}
e.SetHandled()
tf.selectAll()
Expand Down Expand Up @@ -547,7 +547,7 @@ func (tf *TextField) clear() {
tf.startPos = 0
tf.endPos = 0
tf.selectReset()
tf.SetFocusEvent() // this is essential for ensuring that the clear applies after focus is lost..
tf.SetFocus() // this is essential for ensuring that the clear applies after focus is lost..
tf.NeedsRender()
}

Expand Down
20 changes: 10 additions & 10 deletions core/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,20 +766,20 @@ func (tr *Tree) selectUpdate(mode events.SelectModes) bool {
if len(sl) > 1 {
tr.UnselectAll()
tr.Select()
tr.SetFocus()
tr.SetFocusQuiet()
sel = true
}
} else {
tr.UnselectAll()
tr.Select()
tr.SetFocus()
tr.SetFocusQuiet()
sel = true
}
case events.ExtendContinuous:
sl := tr.GetSelectedNodes()
if len(sl) == 0 {
tr.Select()
tr.SetFocus()
tr.SetFocusQuiet()
sel = true
} else {
minIndex := -1
Expand Down Expand Up @@ -814,7 +814,7 @@ func (tr *Tree) selectUpdate(mode events.SelectModes) bool {
tr.UnselectEvent()
} else {
tr.Select()
tr.SetFocus()
tr.SetFocusQuiet()
sel = true
}
case events.SelectQuiet:
Expand Down Expand Up @@ -903,7 +903,7 @@ func (tr *Tree) moveDown(selMode events.SelectModes) *Tree {
func (tr *Tree) moveDownEvent(selMode events.SelectModes) *Tree {
nn := tr.moveDown(selMode)
if nn != nil && nn != tr {
nn.SetFocus()
nn.SetFocusQuiet()
nn.ScrollToThis()
tr.sendSelectEvent()
}
Expand Down Expand Up @@ -963,7 +963,7 @@ func (tr *Tree) moveUp(selMode events.SelectModes) *Tree {
func (tr *Tree) moveUpEvent(selMode events.SelectModes) *Tree {
nn := tr.moveUp(selMode)
if nn != nil && nn != tr {
nn.SetFocus()
nn.SetFocusQuiet()
nn.ScrollToThis()
tr.sendSelectEvent()
}
Expand Down Expand Up @@ -996,7 +996,7 @@ func (tr *Tree) movePageUpEvent(selMode events.SelectModes) *Tree {
if selMode == events.SelectOne {
fnn.selectUpdate(selMode)
}
fnn.SetFocus()
fnn.SetFocusQuiet()
fnn.ScrollToThis()
tr.sendSelectEvent()
}
Expand Down Expand Up @@ -1027,7 +1027,7 @@ func (tr *Tree) movePageDownEvent(selMode events.SelectModes) *Tree {
if selMode == events.SelectOne {
fnn.selectUpdate(selMode)
}
fnn.SetFocus()
fnn.SetFocusQuiet()
fnn.ScrollToThis()
tr.sendSelectEvent()
}
Expand Down Expand Up @@ -1055,7 +1055,7 @@ func (tr *Tree) moveToLastChild(selMode events.SelectModes) *Tree {
// and emits select event for newly selected item
func (tr *Tree) moveHomeEvent(selMode events.SelectModes) *Tree {
tr.root.selectUpdate(selMode)
tr.root.SetFocus()
tr.root.SetFocusQuiet()
tr.root.ScrollToThis()
tr.root.sendSelectEvent()
return tr.root
Expand Down Expand Up @@ -1083,7 +1083,7 @@ func (tr *Tree) moveEndEvent(selMode events.SelectModes) *Tree {
if selMode == events.SelectOne {
fnn.selectUpdate(selMode)
}
fnn.SetFocus()
fnn.SetFocusQuiet()
fnn.ScrollToThis()
tr.sendSelectEvent()
}
Expand Down
33 changes: 16 additions & 17 deletions core/widgetevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (wb *WidgetBase) handleWidgetClick() {
wb.SetState(!wb.StateIs(states.Checked), states.Checked)
}
if wb.AbilityIs(abilities.Focusable) {
wb.SetFocus()
wb.SetFocusQuiet()
} else {
wb.focusClear()
}
Expand Down Expand Up @@ -469,13 +469,13 @@ func (wb *WidgetBase) HandleClickOnEnterSpace() {

//////// Focus

// SetFocus sets the keyboard input focus on this item or the first item within it
// that can be focused (if none, then just sets focus to this object).
// This does not send an [events.Focus] event, which typically results in
// the widget being styled as focused. See [WidgetBase.SetFocusEvent] for
// a version that does. Also see [WidgetBase.StartFocus] which must be
// called instead during initial construction prior to the initial scene render.
func (wb *WidgetBase) SetFocus() {
// SetFocusQuiet sets the keyboard input focus on this item or the first item
// within it that can be focused (if none, then just sets focus to this widget).
// This does NOT send an [events.Focus] event, so the widget will NOT appear focused;
// it will however receive keyboard input, at which point it will get visible focus.
// See [WidgetBase.SetFocus] for a version that sends an event. Also see
// [WidgetBase.StartFocus].
func (wb *WidgetBase) SetFocusQuiet() {
foc := wb.This.(Widget)
if !wb.AbilityIs(abilities.Focusable) {
foc = wb.focusableInThis()
Expand All @@ -485,17 +485,16 @@ func (wb *WidgetBase) SetFocus() {
}
em := wb.Events()
if em != nil {
em.setFocus(foc) // doesn't send event
em.setFocusQuiet(foc) // doesn't send event
}
}

// SetFocusEvent sets the keyboard input focus on this item or the first item within it
// that can be focused (if none, then just sets focus to this object).
// SetFocus sets the keyboard input focus on this item or the first item within it
// that can be focused (if none, then just sets focus to this widget).
// This sends an [events.Focus] event, which typically results in
// the widget being styled as focused. See [WidgetBase.SetFocus] for
// a version that does not. See also [WidgetBase.StartFocus] which must be
// called instead during initial construction prior to the initial scene render.
func (wb *WidgetBase) SetFocusEvent() {
// the widget being styled as focused. See [WidgetBase.SetFocusQuiet] for
// a version that does not. Also see [WidgetBase.StartFocus].
func (wb *WidgetBase) SetFocus() {
foc := wb.This.(Widget)
if !wb.AbilityIs(abilities.Focusable) {
foc = wb.focusableInThis()
Expand All @@ -505,7 +504,7 @@ func (wb *WidgetBase) SetFocusEvent() {
}
em := wb.Events()
if em != nil {
em.setFocusEvent(foc)
em.setFocus(foc)
}
}

Expand Down Expand Up @@ -548,7 +547,7 @@ func (wb *WidgetBase) focusClear() {

// StartFocus specifies that this widget should get focus when the [Scene] is shown,
// or when a major content managing widget (e.g., [Tabs], [Pages]) shows a
// tab/page/element that contains this widget. This is handled via an
// tab/page/element that contains this widget. This is implemented via an
// [events.Show] event.
func (wb *WidgetBase) StartFocus() {
em := wb.Events()
Expand Down
2 changes: 1 addition & 1 deletion tensor/tensorcore/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func (tb *Table) RowGrabFocus(row int) *core.WidgetBase {
for fli := 0; fli < tb.NCols; fli++ {
w := lg.Child(ridx + idxOff + fli).(core.Widget).AsWidget()
if w.CanFocus() {
w.SetFocusEvent()
w.SetFocus()
return w
}
}
Expand Down
2 changes: 1 addition & 1 deletion tensor/tensorcore/tensoreditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func (tb *TensorEditor) RowGrabFocus(row int) *core.WidgetBase {
for fli := 0; fli < tb.NCols; fli++ {
w := lg.Child(ridx + idxOff + fli).(core.Widget).AsWidget()
if w.CanFocus() {
w.SetFocusEvent()
w.SetFocus()
return w
}
}
Expand Down
6 changes: 3 additions & 3 deletions texteditor/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ func (ed *Editor) OpenLinkAt(pos lexer.Pos) (*paint.TextLink, bool) {
func (ed *Editor) handleMouse() {
ed.On(events.MouseDown, func(e events.Event) { // note: usual is Click..
if !ed.StateIs(states.Focused) {
ed.SetFocusEvent()
ed.SetFocus()
}
pt := ed.PointToRelPos(e.Pos())
newPos := ed.PixelToCursor(pt)
Expand Down Expand Up @@ -571,7 +571,7 @@ func (ed *Editor) handleMouse() {
})
ed.OnDoubleClick(func(e events.Event) {
if !ed.StateIs(states.Focused) {
ed.SetFocusEvent()
ed.SetFocus()
ed.Send(events.Focus, e) // sets focused flag
}
e.SetHandled()
Expand All @@ -582,7 +582,7 @@ func (ed *Editor) handleMouse() {
})
ed.On(events.TripleClick, func(e events.Event) {
if !ed.StateIs(states.Focused) {
ed.SetFocusEvent()
ed.SetFocus()
ed.Send(events.Focus, e) // sets focused flag
}
e.SetHandled()
Expand Down

0 comments on commit 9b575b3

Please sign in to comment.