From ca75748dff369a6507883e544c663914aeab075f Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Sun, 6 Jun 2021 20:35:05 -0700 Subject: [PATCH] Update Application.Draw to accept one or more primitives to draw instead of the whole screen --- CHANGELOG | 1 + application.go | 29 ++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index cdfa792..d761022 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ 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 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 de2cec5..2d23995 100644 --- a/application.go +++ b/application.go @@ -611,12 +611,31 @@ func (a *Application) Suspend(f func()) bool { return true } -// Draw refreshes the screen (during the next update cycle). It calls the Draw() -// function of the application's root primitive and then syncs the screen -// buffer. -func (a *Application) Draw() { +// Draw draws the provided primitives on the screen, or when no primitives are +// provided, draws the application's root primitive (i.e. the entire screen). +// +// When one or more primitives are supplied, the Draw functions of the +// primitives are called. Handlers set via BeforeDrawFunc and AfterDrawFunc are +// not called. +// +// When no primitives are provided, the Draw function of the application's root +// primitive is called. This results in drawing the entire screen. Handlers set +// via BeforeDrawFunc and AfterDrawFunc are also called. +func (a *Application) Draw(p ...Primitive) { a.QueueUpdate(func() { - 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() }) }