From c2f13b5d5a7b8ad6c4d2208f12a588940f05d791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Sat, 31 Dec 2022 17:18:53 -0500 Subject: [PATCH] Refactored List style --- config/config.go | 61 +++++++++++++++++++++++++++++++++++------ ui/theme/theme.go | 60 ++++++++++++++++++++++++++++------------ ui/views/posts/posts.go | 27 ++++++++++-------- 3 files changed, 110 insertions(+), 38 deletions(-) diff --git a/config/config.go b/config/config.go index e5f1bb1..08bba85 100644 --- a/config/config.go +++ b/config/config.go @@ -52,8 +52,14 @@ type Config struct { } PostsList struct { - List ThemeItemConfig - Item ThemeItemConfig + List struct { + Focused ThemeItemConfig + Blurred ThemeItemConfig + } + Item struct { + Focused ThemeItemConfig + Blurred ThemeItemConfig + } } Post struct { @@ -84,19 +90,58 @@ func Load() (Config, error) { viper.SetDefault("Debug", "true") viper.SetDefault("Log", path.Join(cacheDir, "gobbs.log")) - // PostsList List - viper.SetDefault("Theme.PostsList.List.Margin", + // PostsList List:Focused + viper.SetDefault("Theme.PostsList.List.Focused.Margin", []int{0, 0, 0, 0}) - viper.SetDefault("Theme.PostsList.List.Padding", + viper.SetDefault("Theme.PostsList.List.Focused.Padding", []int{1, 1, 1, 1}) - viper.SetDefault("Theme.PostsList.List.Border.Border", + viper.SetDefault("Theme.PostsList.List.Focused.Border.Border", lipgloss.RoundedBorder()) - viper.SetDefault("Theme.PostsList.List.Border.Sides", + viper.SetDefault("Theme.PostsList.List.Focused.Border.Sides", []bool{true, true, true, true}, ) - viper.SetDefault("Theme.PostsList.List.Border.Foreground", + viper.SetDefault("Theme.PostsList.List.Focused.Border.Foreground", lipgloss.AdaptiveColor{Light: "#333333", Dark: "#cccccc"}) + // PostsList List:Blurred + viper.SetDefault("Theme.PostsList.List.Blurred.Margin", + []int{0, 0, 0, 0}) + viper.SetDefault("Theme.PostsList.List.Blurred.Padding", + []int{1, 1, 1, 1}) + viper.SetDefault("Theme.PostsList.List.Blurred.Border.Border", + lipgloss.RoundedBorder()) + viper.SetDefault("Theme.PostsList.List.Blurred.Border.Sides", + []bool{true, true, true, true}, + ) + viper.SetDefault("Theme.PostsList.List.Blurred.Border.Foreground", + lipgloss.AdaptiveColor{Light: "#cccccc", Dark: "#333333"}) + + // PostsList Item:Focused + viper.SetDefault("Theme.PostsList.Item.Focused.Margin", + []int{0, 0, 0, 0}) + viper.SetDefault("Theme.PostsList.Item.Focused.Padding", + []int{1, 1, 1, 1}) + viper.SetDefault("Theme.PostsList.Item.Focused.Border.Border", + lipgloss.RoundedBorder()) + viper.SetDefault("Theme.PostsList.Item.Focused.Border.Sides", + []bool{true, true, true, true}, + ) + viper.SetDefault("Theme.PostsList.Item.Focused.Border.Foreground", + lipgloss.AdaptiveColor{Light: "#333333", Dark: "#cccccc"}) + + // PostsList Item:Blurred + viper.SetDefault("Theme.PostsList.Item.Blurred.Margin", + []int{0, 0, 0, 0}) + viper.SetDefault("Theme.PostsList.Item.Blurred.Padding", + []int{1, 1, 1, 1}) + viper.SetDefault("Theme.PostsList.Item.Blurred.Border.Border", + lipgloss.RoundedBorder()) + viper.SetDefault("Theme.PostsList.Item.Blurred.Border.Sides", + []bool{true, true, true, true}, + ) + viper.SetDefault("Theme.PostsList.Item.Blurred.Border.Foreground", + lipgloss.AdaptiveColor{Light: "#cccccc", Dark: "#333333"}) + // DialogBox Window viper.SetDefault("Theme.DialogBox.Window.Margin", []int{0, 0, 0, 0}) diff --git a/ui/theme/theme.go b/ui/theme/theme.go index 35bebaf..25f86fe 100644 --- a/ui/theme/theme.go +++ b/ui/theme/theme.go @@ -13,8 +13,14 @@ type Theme struct { } PostsList struct { - List lipgloss.Style - Item lipgloss.Style + List struct { + Focused lipgloss.Style + Blurred lipgloss.Style + } + Item struct { + Focused lipgloss.Style + Blurred lipgloss.Style + } } Post struct { @@ -38,23 +44,41 @@ func New(cfg *config.Config) (*Theme) { // BorderBottom(false) // - t.PostsList.List = lipgloss.NewStyle(). - Margin(cfg.Theme.PostsList.List.Margin...). - Padding(cfg.Theme.PostsList.List.Padding...). - Border(cfg.Theme.PostsList.List.Border.Border, cfg.Theme.PostsList.List.Border.Sides...). - BorderForeground(cfg.Theme.PostsList.List.Border.Foreground). - BorderBackground(cfg.Theme.PostsList.List.Border.Background). - Foreground(cfg.Theme.PostsList.List.Foreground). - Background(cfg.Theme.PostsList.List.Background) + t.PostsList.List.Focused = lipgloss.NewStyle(). + Margin(cfg.Theme.PostsList.List.Focused.Margin...). + Padding(cfg.Theme.PostsList.List.Focused.Padding...). + Border(cfg.Theme.PostsList.List.Focused.Border.Border, cfg.Theme.PostsList.List.Focused.Border.Sides...). + BorderForeground(cfg.Theme.PostsList.List.Focused.Border.Foreground). + BorderBackground(cfg.Theme.PostsList.List.Focused.Border.Background). + Foreground(cfg.Theme.PostsList.List.Focused.Foreground). + Background(cfg.Theme.PostsList.List.Focused.Background) - t.PostsList.Item = lipgloss.NewStyle(). - Margin(cfg.Theme.PostsList.Item.Margin...). - Padding(cfg.Theme.PostsList.Item.Padding...). - Border(cfg.Theme.PostsList.Item.Border.Border, cfg.Theme.PostsList.Item.Border.Sides...). - BorderForeground(cfg.Theme.PostsList.Item.Border.Foreground). - BorderBackground(cfg.Theme.PostsList.Item.Border.Background). - Foreground(cfg.Theme.PostsList.Item.Foreground). - Background(cfg.Theme.PostsList.Item.Background) + t.PostsList.List.Blurred = lipgloss.NewStyle(). + Margin(cfg.Theme.PostsList.List.Blurred.Margin...). + Padding(cfg.Theme.PostsList.List.Blurred.Padding...). + Border(cfg.Theme.PostsList.List.Blurred.Border.Border, cfg.Theme.PostsList.List.Blurred.Border.Sides...). + BorderForeground(cfg.Theme.PostsList.List.Blurred.Border.Foreground). + BorderBackground(cfg.Theme.PostsList.List.Blurred.Border.Background). + Foreground(cfg.Theme.PostsList.List.Blurred.Foreground). + Background(cfg.Theme.PostsList.List.Blurred.Background) + + t.PostsList.Item.Focused = lipgloss.NewStyle(). + Margin(cfg.Theme.PostsList.Item.Focused.Margin...). + Padding(cfg.Theme.PostsList.Item.Focused.Padding...). + Border(cfg.Theme.PostsList.Item.Focused.Border.Border, cfg.Theme.PostsList.Item.Focused.Border.Sides...). + BorderForeground(cfg.Theme.PostsList.Item.Focused.Border.Foreground). + BorderBackground(cfg.Theme.PostsList.Item.Focused.Border.Background). + Foreground(cfg.Theme.PostsList.Item.Focused.Foreground). + Background(cfg.Theme.PostsList.Item.Focused.Background) + + t.PostsList.Item.Blurred = lipgloss.NewStyle(). + Margin(cfg.Theme.PostsList.Item.Blurred.Margin...). + Padding(cfg.Theme.PostsList.Item.Blurred.Padding...). + Border(cfg.Theme.PostsList.Item.Blurred.Border.Border, cfg.Theme.PostsList.Item.Blurred.Border.Sides...). + BorderForeground(cfg.Theme.PostsList.Item.Blurred.Border.Foreground). + BorderBackground(cfg.Theme.PostsList.Item.Blurred.Border.Background). + Foreground(cfg.Theme.PostsList.Item.Blurred.Foreground). + Background(cfg.Theme.PostsList.Item.Blurred.Background) t.DialogBox.Window = lipgloss.NewStyle(). Margin(cfg.Theme.DialogBox.Window.Margin...). diff --git a/ui/views/posts/posts.go b/ui/views/posts/posts.go index c6d2c88..d77cde1 100644 --- a/ui/views/posts/posts.go +++ b/ui/views/posts/posts.go @@ -110,8 +110,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { viewportWidth := m.ctx.Content[0] - 9 viewportHeight := m.ctx.Content[1] - 10 - m.ctx.Theme.PostsList.List.Width(listWidth) - m.ctx.Theme.PostsList.List.Height(listHeight) + m.ctx.Theme.PostsList.List.Focused.Width(listWidth) + m.ctx.Theme.PostsList.List.Blurred.Width(listWidth) + m.ctx.Theme.PostsList.List.Focused.Height(listHeight) + m.ctx.Theme.PostsList.List.Blurred.Height(listHeight) m.list.SetSize( listWidth-2, listHeight-2, @@ -138,17 +140,12 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd - if m.viewportOpen == false { - // m.ctx.Theme.PostsList.List.BorderForeground(lipgloss.Color("#FFFFFF")) - // viewportStyle.BorderForeground(lipgloss.Color("#874BFD")) - m.list, cmd = m.list.Update(msg) - cmds = append(cmds, cmd) - } else if m.viewportOpen == true { - // m.ctx.Theme.PostsList.List.BorderForeground(lipgloss.Color("#874BFD")) - // viewportStyle.BorderForeground(lipgloss.Color("#FFFFFF")) + if m.viewportOpen { m.viewport, cmd = m.viewport.Update(msg) - cmds = append(cmds, cmd) + } else if m.viewportOpen == true { + m.list, cmd = m.list.Update(msg) } + cmds = append(cmds, cmd) return m, tea.Batch(cmds...) } @@ -156,9 +153,15 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { func (m Model) View() string { var view strings.Builder = strings.Builder{} + var l string = "" + if m.viewportOpen { + l = m.ctx.Theme.PostsList.List.Blurred.Render(m.list.View()) + } else { + l = m.ctx.Theme.PostsList.List.Focused.Render(m.list.View()) + } view.WriteString(lipgloss.JoinHorizontal( lipgloss.Top, - m.ctx.Theme.PostsList.List.Render(m.list.View()), + l, )) if m.viewportOpen {