mirror of
https://github.com/rivo/tview.git
synced 2025-04-24 13:48:56 +08:00
Merge bcf768ac59acd5a382ffdf31f32244bbe4b2271c into c76f7879f592d17e9e68a1d795a85faae6cb7414
This commit is contained in:
commit
f0c4a96b0e
@ -97,6 +97,14 @@ type Application struct {
|
||||
// be forwarded).
|
||||
inputCapture func(event *tcell.EventKey) *tcell.EventKey
|
||||
|
||||
// An optional callback function which is invoked before the application's
|
||||
// focus changes.
|
||||
beforeFocus func(p Primitive) bool
|
||||
|
||||
// An optional callback function which is invoked after the application's
|
||||
// focus changes.
|
||||
afterFocus func(p Primitive)
|
||||
|
||||
// An optional callback function which is invoked just before the root
|
||||
// primitive is drawn.
|
||||
beforeDraw func(screen tcell.Screen) bool
|
||||
@ -812,14 +820,34 @@ func (a *Application) ResizeToFullScreen(p Primitive) *Application {
|
||||
// called on the new primitive.
|
||||
func (a *Application) SetFocus(p Primitive) *Application {
|
||||
a.Lock()
|
||||
|
||||
if a.beforeFocus != nil {
|
||||
a.Unlock()
|
||||
ok := a.beforeFocus(p)
|
||||
if !ok {
|
||||
return a
|
||||
}
|
||||
a.Lock()
|
||||
}
|
||||
|
||||
if a.focus != nil {
|
||||
a.focus.Blur()
|
||||
}
|
||||
|
||||
a.focus = p
|
||||
|
||||
if a.screen != nil {
|
||||
a.screen.HideCursor()
|
||||
}
|
||||
a.Unlock()
|
||||
|
||||
if a.afterFocus != nil {
|
||||
a.Unlock()
|
||||
|
||||
a.afterFocus(p)
|
||||
} else {
|
||||
a.Unlock()
|
||||
}
|
||||
|
||||
if p != nil {
|
||||
p.Focus(func(p Primitive) {
|
||||
a.SetFocus(p)
|
||||
@ -837,6 +865,30 @@ func (a *Application) GetFocus() Primitive {
|
||||
return a.focus
|
||||
}
|
||||
|
||||
// SetBeforeFocusFunc installs a callback function which is invoked before the
|
||||
// application's focus changes. Return false to maintain the current focus.
|
||||
//
|
||||
// Provide nil to uninstall the callback function.
|
||||
func (a *Application) SetBeforeFocusFunc(handler func(p Primitive) bool) *Application {
|
||||
a.Lock()
|
||||
defer a.Unlock()
|
||||
|
||||
a.beforeFocus = handler
|
||||
return a
|
||||
}
|
||||
|
||||
// SetAfterFocusFunc installs a callback function which is invoked after the
|
||||
// application's focus changes.
|
||||
//
|
||||
// Provide nil to uninstall the callback function.
|
||||
func (a *Application) SetAfterFocusFunc(handler func(p Primitive)) *Application {
|
||||
a.Lock()
|
||||
defer a.Unlock()
|
||||
|
||||
a.afterFocus = handler
|
||||
return a
|
||||
}
|
||||
|
||||
// QueueUpdate is used to synchronize access to primitives from non-main
|
||||
// goroutines. The provided function will be executed as part of the event loop
|
||||
// and thus will not cause race conditions with other such update functions or
|
||||
|
Loading…
x
Reference in New Issue
Block a user