From 652afb9875a8779e1e657f892971357c9e5fb2b6 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Sun, 6 Jun 2021 20:44:56 -0700 Subject: [PATCH] Update Application.QueueUpdateDraw to accept one or more primitives to draw instead of the whole screen --- CHANGELOG | 3 ++- application.go | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d761022..60c1ff0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,7 +6,8 @@ v1.5.6 (WIP) - Add DropDown.SetAlwaysDrawDropDownSymbol (DropDown symbols are now shown only when focused by default) - Add DropDown.SetDropDownOpenSymbolRune - Draw additional accents when rendering a list divider -- Update Application.Draw to accept one or more primitives to draw instead of the whole screen +- Update Application.Draw and Application.QueueUpdateDraw to accept one or more +primitives to draw instead of the whole screen - Update List, Table and TreeView to not handle Tab or Backtab - Allow specifying TabbedPanels switcher height - Change default colors (fields and buttons are now green) diff --git a/application.go b/application.go index 2d23995..63fd5fc 100644 --- a/application.go +++ b/application.go @@ -862,12 +862,26 @@ func (a *Application) QueueUpdate(f func()) { a.updates <- f } -// QueueUpdateDraw works like QueueUpdate() except it refreshes the screen -// immediately after executing f. -func (a *Application) QueueUpdateDraw(f func()) { +// QueueUpdateDraw works like QueueUpdate() except, when one or more primitives +// are provided, the primitives are drawn after the provided function returns. +// When no primitives are provided, the entire screen is drawn after the +// provided function returns. +func (a *Application) QueueUpdateDraw(f func(), p ...Primitive) { a.QueueUpdate(func() { f() - a.draw() + + if len(p) == 0 { + a.draw() + return + } + a.Lock() + if a.screen != nil { + for _, primitive := range p { + primitive.Draw(a.screen) + } + a.screen.Show() + } + a.Unlock() }) }