mirror of
https://github.com/mrusme/neonmodem.git
synced 2024-12-04 14:46:37 -05:00
Implemented UI caching
This commit is contained in:
parent
0714431811
commit
6775d6df17
27
ui/ui.go
27
ui/ui.go
@ -48,6 +48,9 @@ type Model struct {
|
|||||||
currentView int
|
currentView int
|
||||||
wm *windowmanager.WM
|
wm *windowmanager.WM
|
||||||
ctx *ctx.Ctx
|
ctx *ctx.Ctx
|
||||||
|
|
||||||
|
viewcache string
|
||||||
|
renderOnlyFocused bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewModel(c *ctx.Ctx) Model {
|
func NewModel(c *ctx.Ctx) Model {
|
||||||
@ -56,6 +59,9 @@ func NewModel(c *ctx.Ctx) Model {
|
|||||||
currentView: 0,
|
currentView: 0,
|
||||||
wm: windowmanager.New(c),
|
wm: windowmanager.New(c),
|
||||||
ctx: c,
|
ctx: c,
|
||||||
|
|
||||||
|
viewcache: "",
|
||||||
|
renderOnlyFocused: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
m.header = header.NewModel(m.ctx)
|
m.header = header.NewModel(m.ctx)
|
||||||
@ -121,6 +127,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
)
|
)
|
||||||
case postcreate.WIN_ID:
|
case postcreate.WIN_ID:
|
||||||
m.ctx.Logger.Debugln("received WinOpen")
|
m.ctx.Logger.Debugln("received WinOpen")
|
||||||
|
m.viewcache = m.buildView(false)
|
||||||
|
m.renderOnlyFocused = true
|
||||||
ccmds = m.wm.Open(
|
ccmds = m.wm.Open(
|
||||||
msg.Target,
|
msg.Target,
|
||||||
postcreate.NewModel(m.ctx),
|
postcreate.NewModel(m.ctx),
|
||||||
@ -129,6 +137,12 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
m.ctx.Logger.Debugf("got back ccmds: %v\n", ccmds)
|
m.ctx.Logger.Debugf("got back ccmds: %v\n", ccmds)
|
||||||
|
case cmd.WinClose:
|
||||||
|
switch msg.Target {
|
||||||
|
case postcreate.WIN_ID:
|
||||||
|
m.ctx.Logger.Debugln("received WinClose")
|
||||||
|
m.renderOnlyFocused = false
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
if msg.Call < cmd.ViewFocus {
|
if msg.Call < cmd.ViewFocus {
|
||||||
m.ctx.Logger.Debugf("updating all with cmd: %v\n", msg)
|
m.ctx.Logger.Debugf("updating all with cmd: %v\n", msg)
|
||||||
@ -158,11 +172,22 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m Model) View() string {
|
func (m Model) View() string {
|
||||||
|
return m.buildView(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m Model) buildView(cached bool) string {
|
||||||
s := strings.Builder{}
|
s := strings.Builder{}
|
||||||
|
var tmp string = ""
|
||||||
|
|
||||||
|
if m.viewcache != "" && m.renderOnlyFocused {
|
||||||
|
tmp = m.viewcache
|
||||||
|
} else {
|
||||||
s.WriteString(m.header.View() + "\n")
|
s.WriteString(m.header.View() + "\n")
|
||||||
s.WriteString(m.views[m.currentView].View())
|
s.WriteString(m.views[m.currentView].View())
|
||||||
|
tmp = s.String()
|
||||||
|
}
|
||||||
|
|
||||||
return m.wm.View(s.String())
|
return m.wm.View(tmp, m.renderOnlyFocused)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Model) setSizes(winWidth int, winHeight int) {
|
func (m Model) setSizes(winWidth int, winHeight int) {
|
||||||
|
@ -196,10 +196,18 @@ func (wm *WM) ResizeAll(w int, h int) []tea.Cmd {
|
|||||||
return tcmds
|
return tcmds
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wm *WM) View(view string) string {
|
func (wm *WM) View(view string, onlyFocused bool) string {
|
||||||
var v string = view
|
var v string = view
|
||||||
|
var j int = 0
|
||||||
|
|
||||||
for i := 0; i < len(wm.stack); i++ {
|
if onlyFocused {
|
||||||
|
j = len(wm.stack) - 1
|
||||||
|
if j < 0 {
|
||||||
|
j = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := j; i < len(wm.stack); i++ {
|
||||||
v = helpers.PlaceOverlay(
|
v = helpers.PlaceOverlay(
|
||||||
wm.stack[i].XYWH[0],
|
wm.stack[i].XYWH[0],
|
||||||
wm.stack[i].XYWH[1]+(wm.ctx.Screen[1]-wm.ctx.Content[1]),
|
wm.stack[i].XYWH[1]+(wm.ctx.Screen[1]-wm.ctx.Content[1]),
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/mrusme/gobbs/models/reply"
|
"github.com/mrusme/gobbs/models/reply"
|
||||||
"github.com/mrusme/gobbs/ui/cmd"
|
"github.com/mrusme/gobbs/ui/cmd"
|
||||||
"github.com/mrusme/gobbs/ui/ctx"
|
"github.com/mrusme/gobbs/ui/ctx"
|
||||||
|
"github.com/mrusme/gobbs/ui/helpers"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -151,6 +152,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
if msg.Target == WIN_ID ||
|
if msg.Target == WIN_ID ||
|
||||||
msg.Target == "*" {
|
msg.Target == "*" {
|
||||||
m.focused = true
|
m.focused = true
|
||||||
|
m.viewcache = m.buildView(false)
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
case cmd.WinBlur:
|
case cmd.WinBlur:
|
||||||
@ -166,8 +168,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
case cursor.BlinkMsg:
|
case cursor.BlinkMsg:
|
||||||
m.ctx.Logger.Debugf("textarea is focused: %v\n", m.textarea.Focused())
|
m.ctx.Logger.Debugf("textarea is focused: %v\n", m.textarea.Focused())
|
||||||
|
|
||||||
default:
|
// default:
|
||||||
m.ctx.Logger.Debugf("received unhandled msg: %v\n", msg)
|
// m.ctx.Logger.Debugf("received unhandled msg: %v\n", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
var tcmd tea.Cmd
|
var tcmd tea.Cmd
|
||||||
@ -198,17 +200,17 @@ func (m Model) View() string {
|
|||||||
func (m Model) buildView(cached bool) string {
|
func (m Model) buildView(cached bool) string {
|
||||||
var view strings.Builder = strings.Builder{}
|
var view strings.Builder = strings.Builder{}
|
||||||
|
|
||||||
// if cached && m.viewcache != "" {
|
if cached && m.viewcache != "" {
|
||||||
// m.ctx.Logger.Debugln("Cached View()")
|
m.ctx.Logger.Debugln("Cached View()")
|
||||||
//
|
|
||||||
// m.textarea.SetWidth(m.viewcacheTextareaXY[2])
|
m.textarea.SetWidth(m.viewcacheTextareaXY[2])
|
||||||
// m.textarea.SetHeight(m.viewcacheTextareaXY[3])
|
m.textarea.SetHeight(m.viewcacheTextareaXY[3])
|
||||||
//
|
|
||||||
// return helpers.PlaceOverlay(
|
return helpers.PlaceOverlay(
|
||||||
// m.viewcacheTextareaXY[0], m.viewcacheTextareaXY[1],
|
m.viewcacheTextareaXY[0], m.viewcacheTextareaXY[1],
|
||||||
// m.textarea.View(), m.viewcache,
|
m.textarea.View(), m.viewcache,
|
||||||
// false)
|
false)
|
||||||
// }
|
}
|
||||||
|
|
||||||
title := "Reply"
|
title := "Reply"
|
||||||
if m.replyToIdx != 0 {
|
if m.replyToIdx != 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user