Improve invalidation logic
This commit is contained in:
parent
77a0f68758
commit
55e8453302
3 changed files with 26 additions and 12 deletions
|
@ -11,6 +11,8 @@ type AccountTab struct {
|
||||||
Config *config.AccountConfig
|
Config *config.AccountConfig
|
||||||
Worker *worker.Worker
|
Worker *worker.Worker
|
||||||
Parent *UIState
|
Parent *UIState
|
||||||
|
|
||||||
|
counter int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAccountTab(conf *config.AccountConfig, work *worker.Worker) *AccountTab {
|
func NewAccountTab(conf *config.AccountConfig, work *worker.Worker) *AccountTab {
|
||||||
|
@ -24,10 +26,6 @@ func (acc *AccountTab) Name() string {
|
||||||
return acc.Config.Name
|
return acc.Config.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (acc *AccountTab) Invalid() bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (acc *AccountTab) SetParent(parent *UIState) {
|
func (acc *AccountTab) SetParent(parent *UIState) {
|
||||||
acc.Parent = parent
|
acc.Parent = parent
|
||||||
}
|
}
|
||||||
|
@ -37,5 +35,10 @@ func (acc *AccountTab) Render(at Geometry) {
|
||||||
Fg: tb.ColorDefault,
|
Fg: tb.ColorDefault,
|
||||||
Bg: tb.ColorDefault,
|
Bg: tb.ColorDefault,
|
||||||
}
|
}
|
||||||
TPrintf(&at, cell, "%s", acc.Name())
|
TPrintf(&at, cell, "%s %d", acc.Name(), acc.counter)
|
||||||
|
acc.counter++
|
||||||
|
if acc.counter%10000 == 0 {
|
||||||
|
acc.counter = 0
|
||||||
|
}
|
||||||
|
acc.Parent.InvalidateFrom(acc)
|
||||||
}
|
}
|
||||||
|
|
11
ui/types.go
11
ui/types.go
|
@ -7,14 +7,18 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Valid = 0
|
Valid = 0
|
||||||
InvalidateTabs = 1 << iota
|
InvalidateTabList = 1 << iota
|
||||||
|
InvalidateTabView
|
||||||
InvalidateSidebar
|
InvalidateSidebar
|
||||||
InvalidateStatusBar
|
InvalidateStatusBar
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
InvalidateAll = InvalidateTabs | InvalidateSidebar | InvalidateStatusBar
|
InvalidateAll = InvalidateTabList |
|
||||||
|
InvalidateTabView |
|
||||||
|
InvalidateSidebar |
|
||||||
|
InvalidateStatusBar
|
||||||
)
|
)
|
||||||
|
|
||||||
type Geometry struct {
|
type Geometry struct {
|
||||||
|
@ -26,7 +30,6 @@ type Geometry struct {
|
||||||
|
|
||||||
type AercTab interface {
|
type AercTab interface {
|
||||||
Name() string
|
Name() string
|
||||||
Invalid() bool
|
|
||||||
Render(at Geometry)
|
Render(at Geometry)
|
||||||
SetParent(parent *UIState)
|
SetParent(parent *UIState)
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ func (state *UIState) Close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (state *UIState) AddTab(tab AercTab) {
|
func (state *UIState) AddTab(tab AercTab) {
|
||||||
|
tab.SetParent(state)
|
||||||
state.Tabs = append(state.Tabs, tab)
|
state.Tabs = append(state.Tabs, tab)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +39,12 @@ func (state *UIState) Invalidate(what uint) {
|
||||||
state.InvalidPanes |= what
|
state.InvalidPanes |= what
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (state *UIState) InvalidateFrom(tab AercTab) {
|
||||||
|
if state.Tabs[state.SelectedTab] == tab {
|
||||||
|
state.Invalidate(InvalidateTabView)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (state *UIState) calcGeometries() {
|
func (state *UIState) calcGeometries() {
|
||||||
width, height := tb.Size()
|
width, height := tb.Size()
|
||||||
// TODO: more
|
// TODO: more
|
||||||
|
@ -65,16 +72,17 @@ func (state *UIState) Tick() bool {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if state.InvalidPanes != 0 {
|
if state.InvalidPanes != 0 {
|
||||||
if state.InvalidPanes&InvalidateAll == InvalidateAll {
|
invalid := state.InvalidPanes
|
||||||
|
state.InvalidPanes = 0
|
||||||
|
if invalid&InvalidateAll == InvalidateAll {
|
||||||
tb.Clear(tb.ColorDefault, tb.ColorDefault)
|
tb.Clear(tb.ColorDefault, tb.ColorDefault)
|
||||||
state.calcGeometries()
|
state.calcGeometries()
|
||||||
}
|
}
|
||||||
if state.InvalidPanes&InvalidateTabs != 0 {
|
if invalid&InvalidateTabView != 0 {
|
||||||
tab := state.Tabs[state.SelectedTab]
|
tab := state.Tabs[state.SelectedTab]
|
||||||
tab.Render(state.Panes.TabView)
|
tab.Render(state.Panes.TabView)
|
||||||
}
|
}
|
||||||
tb.Flush()
|
tb.Flush()
|
||||||
state.InvalidPanes = 0
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
Loading…
Reference in a new issue