aboutsummaryrefslogtreecommitdiff
path: root/xA/xA.go
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2024-11-09 12:32:51 +0100
committerPřemysl Eric Janouch <p@janouch.name>2024-11-09 17:20:20 +0100
commit76597e3dfd1fbb829ef4e517f256a550d811fa1c (patch)
tree9161db3d580f085af3cdc08a2b7b1071cb772438 /xA/xA.go
parent9278e0038366aab29f7c7352f606073756d5b750 (diff)
downloadxK-76597e3dfd1fbb829ef4e517f256a550d811fa1c.tar.gz
xK-76597e3dfd1fbb829ef4e517f256a550d811fa1c.tar.xz
xK-76597e3dfd1fbb829ef4e517f256a550d811fa1c.zip
WIP: xA: add buffer list
Diffstat (limited to 'xA/xA.go')
-rw-r--r--xA/xA.go57
1 files changed, 53 insertions, 4 deletions
diff --git a/xA/xA.go b/xA/xA.go
index 147ee74..6459236 100644
--- a/xA/xA.go
+++ b/xA/xA.go
@@ -15,6 +15,7 @@ import (
"net"
"os"
"slices"
+ "strings"
"sync"
"time"
@@ -104,7 +105,12 @@ func (t *customTheme) Icon(i fyne.ThemeIconName) fyne.Resource {
}
func (t *customTheme) Size(s fyne.ThemeSizeName) float32 {
- return theme.DefaultTheme().Size(s)
+ switch s {
+ case theme.SizeNameInnerPadding:
+ return 2
+ default:
+ return theme.DefaultTheme().Size(s)
+ }
}
// --- Relay state -------------------------------------------------------------
@@ -186,6 +192,7 @@ var (
wWindow fyne.Window
wTopic *widget.RichText
+ wBufferList *widget.List
wRichText *widget.RichText
wRichScroll *container.Scroll
wPrompt *widget.Label
@@ -329,7 +336,12 @@ func refreshTopic(topic []bufferLineItem) {
}
func refreshBufferList() {
- // TODO(p): First off, add a buffer list, second, refresh it.
+ // TODO(p): See if this is enough, or even doing anything.
+ // - In particular, within RelayEventDataBufferRemove handling.
+ wBufferList.Refresh()
+ for i := range buffers {
+ wBufferList.RefreshItem(widget.ListItemID(i))
+ }
}
func refreshPrompt() {
@@ -776,10 +788,18 @@ func relayProcessMessage(m *RelayEventMessage) {
old.historyAt = len(old.history)
}
- // TODO(p): Port the rest as well.
+ // TODO(p): Hide the log if visible.
+ b.highlighted = false
+ for i := range buffers {
+ if buffers[i].bufferName == bufferCurrent {
+ wBufferList.Select(widget.ListItemID(i))
+ break
+ }
+ }
refreshIcon()
refreshTopic(b.topic)
+ refreshBufferList()
refreshBuffer(b)
refreshPrompt()
refreshStatus()
@@ -919,6 +939,34 @@ func main() {
wWindow = a.NewWindow(projectName)
// TODO(p): Consider using data bindings.
+ wBufferList = widget.NewList(func() int { return len(buffers) },
+ func() fyne.CanvasObject {
+ return widget.NewLabel(strings.Repeat(" ", 16))
+ },
+ func(id widget.ListItemID, item fyne.CanvasObject) {
+ label, b := item.(*widget.Label), &buffers[int(id)]
+ label.TextStyle.Italic = b.bufferName == bufferCurrent
+ label.TextStyle.Bold = false
+ text := b.bufferName
+ if b.bufferName != bufferCurrent && b.newMessages != 0 {
+ label.TextStyle.Bold = true
+ text += fmt.Sprintf(" (%d)", b.newMessages)
+ }
+ label.Importance = widget.MediumImportance
+ if b.highlighted {
+ label.Importance = widget.HighImportance
+ }
+ label.SetText(text)
+ })
+ wBufferList.HideSeparators = true
+ wBufferList.OnSelected = func(id widget.ListItemID) {
+ // TODO(p): See if we can deselect it now without consequences.
+ request := buffers[int(id)].bufferName
+ if request != bufferCurrent {
+ bufferActivate(request)
+ }
+ }
+
wTopic = widget.NewRichText()
wTopic.Truncation = fyne.TextTruncateEllipsis
wRichText = widget.NewRichText()
@@ -930,11 +978,12 @@ func main() {
"", fyne.TextAlignTrailing, fyne.TextStyle{})
wEntry = widget.NewMultiLineEntry()
bottom := container.NewVBox(
+ widget.NewSeparator(),
container.NewBorder(nil, nil, wPrompt, wStatus),
wEntry,
)
wWindow.SetContent(container.NewBorder(
- wTopic, bottom, nil, nil, wRichScroll))
+ wTopic, bottom, wBufferList, nil, wRichScroll))
go relayRun()