From 561ae1940e49c8cd36b7a62d854a3c9838902389 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Thu, 28 Nov 2024 18:36:13 +0200 Subject: Added focus to network list --- internal/client/ui/core/core.go | 42 +++++++++++++++++----- internal/client/ui/core/networklist/networklist.go | 19 ++++++++-- 2 files changed, 51 insertions(+), 10 deletions(-) (limited to 'internal') diff --git a/internal/client/ui/core/core.go b/internal/client/ui/core/core.go index 98158b3..140d5f3 100644 --- a/internal/client/ui/core/core.go +++ b/internal/client/ui/core/core.go @@ -18,6 +18,7 @@ import ( "github.com/kyren223/eko/internal/client/ui/core/state" "github.com/kyren223/eko/internal/client/ui/loadscreen" "github.com/kyren223/eko/internal/packet" + "github.com/kyren223/eko/pkg/assert" "github.com/kyren223/eko/pkg/snowflake" ) @@ -29,23 +30,31 @@ var ( timerInterval = 50 * time.Millisecond ) +const ( + FocusNetworkList = iota + FocusFrequencies + FocusChat + FocusUsers + FocusMax +) + type Model struct { name string privKey ed25519.PrivateKey + id snowflake.ID - networkList networklist.Model - loading loadscreen.Model - timer timer.Model - timeout time.Duration - connected bool - - id snowflake.ID + loading loadscreen.Model + timer timer.Model + timeout time.Duration + connected bool networkCreationPopup *networkcreation.Model + networkList networklist.Model + focus int } func New(privKey ed25519.PrivateKey, name string) Model { - return Model{ + m := Model{ name: name, privKey: privKey, networkList: networklist.New(), @@ -53,7 +62,11 @@ func New(privKey ed25519.PrivateKey, name string) Model { timer: newTimer(initialTimeout), timeout: initialTimeout, connected: false, + focus: FocusNetworkList, } + m.move(0) // Update focus + + return m } func (m Model) Init() tea.Cmd { @@ -202,3 +215,16 @@ func (m *Model) updateLoadScreenContent() { func newTimer(timeout time.Duration) timer.Model { return timer.NewWithInterval(timeout.Truncate(time.Second)+(time.Second/2), timerInterval) } + +func (m *Model) move(direction int) { + focus := m.focus + direction + m.focus = max(0, min(FocusMax-1, focus)) + + m.networkList.Blur() + switch m.focus { + case FocusNetworkList: + m.networkList.Focus() + default: + assert.Never("missing switch statement field in move", "focus", m.focus) + } +} diff --git a/internal/client/ui/core/networklist/networklist.go b/internal/client/ui/core/networklist/networklist.go index 7b191e8..92c0094 100644 --- a/internal/client/ui/core/networklist/networklist.go +++ b/internal/client/ui/core/networklist/networklist.go @@ -23,10 +23,14 @@ func IconStyle(fg, bg lipgloss.Color) lipgloss.Style { return partialIconStyle.Foreground(fg).Background(bg) } -type Model struct{} +type Model struct{ + focus bool +} func New() Model { - return Model{} + return Model{ + focus: false, + } } func (m Model) Init() tea.Cmd { @@ -53,6 +57,9 @@ func (m Model) View() string { result := builder.String() sep := lipgloss.NewStyle().Border(lipgloss.ThickBorder(), false, true, false, false).Height(ui.Height).Width(0) + if m.focus { + sep = sep.BorderForeground(colors.Focus) + } result = lipgloss.JoinHorizontal(lipgloss.Top, result, sep.Render("")) return result @@ -61,3 +68,11 @@ func (m Model) View() string { func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { return m, nil } + +func (m *Model) Focus() { + m.focus = true +} + +func (m *Model) Blur() { + m.focus = false +} -- cgit v1.3.1