1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2025-02-02 15:07:59 -05:00

Refactored DialogBox, implemented Focused/Blurred

This commit is contained in:
マリウス 2023-01-01 01:42:42 -05:00
parent c119cd9f73
commit 6f6e1c5fad
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
3 changed files with 75 additions and 26 deletions
config
ui
theme
views/posts

@ -46,8 +46,14 @@ type Config struct {
Theme struct { Theme struct {
DialogBox struct { DialogBox struct {
Window ThemeItemConfig Window struct {
Titlebar ThemeItemConfig Focused ThemeItemConfig
Blurred ThemeItemConfig
}
Titlebar struct {
Focused ThemeItemConfig
Blurred ThemeItemConfig
}
Bottombar ThemeItemConfig Bottombar ThemeItemConfig
} }
@ -223,29 +229,52 @@ func SetDefaults(cacheDir string) {
viper.SetDefault("Theme.PostsList.ItemDetail.Selected.Foreground", viper.SetDefault("Theme.PostsList.ItemDetail.Selected.Foreground",
lipgloss.AdaptiveColor{Light: "#000000", Dark: "#FFFFFF"}) lipgloss.AdaptiveColor{Light: "#000000", Dark: "#FFFFFF"})
// DialogBox Window // DialogBox Window:Focused
viper.SetDefault("Theme.DialogBox.Window.Margin", viper.SetDefault("Theme.DialogBox.Window.Focused.Margin",
[]int{0, 0, 0, 0}) []int{0, 0, 0, 0})
viper.SetDefault("Theme.DialogBox.Window.Padding", viper.SetDefault("Theme.DialogBox.Window.Focused.Padding",
[]int{0, 0, 0, 0}) []int{0, 0, 0, 0})
viper.SetDefault("Theme.DialogBox.Window.Border.Border", viper.SetDefault("Theme.DialogBox.Window.Focused.Border.Border",
lipgloss.ThickBorder()) lipgloss.ThickBorder())
viper.SetDefault("Theme.DialogBox.Window.Border.Sides", viper.SetDefault("Theme.DialogBox.Window.Focused.Border.Sides",
[]bool{false, true, true, true}, []bool{false, true, true, true},
) )
viper.SetDefault("Theme.DialogBox.Window.Border.Foreground", viper.SetDefault("Theme.DialogBox.Window.Focused.Border.Foreground",
lipgloss.AdaptiveColor{Light: "#00ffff", Dark: "#00ffff"}) lipgloss.AdaptiveColor{Light: "#00ffff", Dark: "#00ffff"})
// DialogBox Titlebar // DialogBox Window:Blurred
viper.SetDefault("Theme.DialogBox.Titlebar.Margin", viper.SetDefault("Theme.DialogBox.Window.Blurred.Margin",
[]int{0, 0, 0, 0})
viper.SetDefault("Theme.DialogBox.Window.Blurred.Padding",
[]int{0, 0, 0, 0})
viper.SetDefault("Theme.DialogBox.Window.Blurred.Border.Border",
lipgloss.ThickBorder())
viper.SetDefault("Theme.DialogBox.Window.Blurred.Border.Sides",
[]bool{false, true, true, true},
)
viper.SetDefault("Theme.DialogBox.Window.Blurred.Border.Foreground",
lipgloss.AdaptiveColor{Light: "#cccccc", Dark: "#333333"})
// DialogBox Titlebar:Focused
viper.SetDefault("Theme.DialogBox.Titlebar.Focused.Margin",
[]int{0, 0, 1, 0}) []int{0, 0, 1, 0})
viper.SetDefault("Theme.DialogBox.Titlebar.Padding", viper.SetDefault("Theme.DialogBox.Titlebar.Focused.Padding",
[]int{0, 1, 0, 1}) []int{0, 1, 0, 1})
viper.SetDefault("Theme.DialogBox.Titlebar.Foreground", viper.SetDefault("Theme.DialogBox.Titlebar.Focused.Foreground",
lipgloss.AdaptiveColor{Light: "#ffffff", Dark: "#000000"}) lipgloss.AdaptiveColor{Light: "#ffffff", Dark: "#000000"})
viper.SetDefault("Theme.DialogBox.Titlebar.Background", viper.SetDefault("Theme.DialogBox.Titlebar.Focused.Background",
lipgloss.AdaptiveColor{Light: "#00cccc", Dark: "#00cccc"}) lipgloss.AdaptiveColor{Light: "#00cccc", Dark: "#00cccc"})
// DialogBox Titlebar:Blurred
viper.SetDefault("Theme.DialogBox.Titlebar.Blurred.Margin",
[]int{0, 0, 1, 0})
viper.SetDefault("Theme.DialogBox.Titlebar.Blurred.Padding",
[]int{0, 1, 0, 1})
viper.SetDefault("Theme.DialogBox.Titlebar.Blurred.Foreground",
lipgloss.AdaptiveColor{Light: "#ffffff", Dark: "#000000"})
viper.SetDefault("Theme.DialogBox.Titlebar.Blurred.Background",
lipgloss.AdaptiveColor{Light: "#cccccc", Dark: "#333333"})
// DialogBox Bottombar // DialogBox Bottombar
viper.SetDefault("Theme.DialogBox.Bottombar.Margin", viper.SetDefault("Theme.DialogBox.Bottombar.Margin",
[]int{1, 0, 0, 0}) []int{1, 0, 0, 0})

@ -7,8 +7,14 @@ import (
type Theme struct { type Theme struct {
DialogBox struct { DialogBox struct {
Window lipgloss.Style Window struct {
Titlebar lipgloss.Style Focused lipgloss.Style
Blurred lipgloss.Style
}
Titlebar struct {
Focused lipgloss.Style
Blurred lipgloss.Style
}
Bottombar lipgloss.Style Bottombar lipgloss.Style
} }
@ -50,8 +56,10 @@ func New(cfg *config.Config) (*Theme) {
t.PostsList.ItemDetail.Focused = t.fromConfig(&cfg.Theme.PostsList.ItemDetail.Focused) t.PostsList.ItemDetail.Focused = t.fromConfig(&cfg.Theme.PostsList.ItemDetail.Focused)
t.PostsList.ItemDetail.Blurred = t.fromConfig(&cfg.Theme.PostsList.ItemDetail.Blurred) t.PostsList.ItemDetail.Blurred = t.fromConfig(&cfg.Theme.PostsList.ItemDetail.Blurred)
t.PostsList.ItemDetail.Selected = t.fromConfig(&cfg.Theme.PostsList.ItemDetail.Selected) t.PostsList.ItemDetail.Selected = t.fromConfig(&cfg.Theme.PostsList.ItemDetail.Selected)
t.DialogBox.Window = t.fromConfig(&cfg.Theme.DialogBox.Window) t.DialogBox.Window.Focused = t.fromConfig(&cfg.Theme.DialogBox.Window.Focused)
t.DialogBox.Titlebar = t.fromConfig(&cfg.Theme.DialogBox.Titlebar) t.DialogBox.Window.Blurred = t.fromConfig(&cfg.Theme.DialogBox.Window.Blurred)
t.DialogBox.Titlebar.Focused = t.fromConfig(&cfg.Theme.DialogBox.Titlebar.Focused)
t.DialogBox.Titlebar.Blurred = t.fromConfig(&cfg.Theme.DialogBox.Titlebar.Blurred)
t.DialogBox.Bottombar = t.fromConfig(&cfg.Theme.DialogBox.Bottombar) t.DialogBox.Bottombar = t.fromConfig(&cfg.Theme.DialogBox.Bottombar)
t.Post.Author = t.fromConfig(&cfg.Theme.Post.Author) t.Post.Author = t.fromConfig(&cfg.Theme.Post.Author)
t.Post.Subject = t.fromConfig(&cfg.Theme.Post.Subject) t.Post.Subject = t.fromConfig(&cfg.Theme.Post.Subject)

@ -199,8 +199,13 @@ func (m Model) View() string {
)) ))
if m.focused == "post" || m.focused == "reply" { if m.focused == "post" || m.focused == "reply" {
titlebar := m.ctx.Theme.DialogBox.Titlebar. var style lipgloss.Style
Align(lipgloss.Center). if m.focused == "post" {
style = m.ctx.Theme.DialogBox.Titlebar.Focused
} else {
style = m.ctx.Theme.DialogBox.Titlebar.Blurred
}
titlebar := style.Align(lipgloss.Center).
Width(m.viewport.Width + 4). Width(m.viewport.Width + 4).
Render("Post") Render("Post")
@ -215,16 +220,23 @@ func (m Model) View() string {
bottombar, bottombar,
) )
tmp := helpers.PlaceOverlay(3, 2, var tmp string
m.ctx.Theme.DialogBox.Window.Render(ui), if m.focused == "post" {
view.String(), true) tmp = helpers.PlaceOverlay(3, 2,
m.ctx.Theme.DialogBox.Window.Focused.Render(ui),
view.String(), true)
} else {
tmp = helpers.PlaceOverlay(3, 2,
m.ctx.Theme.DialogBox.Window.Blurred.Render(ui),
view.String(), true)
}
view = strings.Builder{} view = strings.Builder{}
view.WriteString(tmp) view.WriteString(tmp)
} }
if m.focused == "reply" { if m.focused == "reply" {
titlebar := m.ctx.Theme.DialogBox.Titlebar. titlebar := m.ctx.Theme.DialogBox.Titlebar.Focused.
Align(lipgloss.Center). Align(lipgloss.Center).
Width(m.viewport.Width - 2). Width(m.viewport.Width - 2).
Render("Reply") Render("Reply")
@ -234,7 +246,7 @@ func (m Model) View() string {
bottombar := m.ctx.Theme.DialogBox.Bottombar. bottombar := m.ctx.Theme.DialogBox.Bottombar.
Width(m.viewport.Width - 2). Width(m.viewport.Width - 2).
Render("ctrl+r reply · esc close") Render("ctrl+enter reply · esc close")
replyWindow := lipgloss.JoinVertical( replyWindow := lipgloss.JoinVertical(
lipgloss.Center, lipgloss.Center,
@ -244,7 +256,7 @@ func (m Model) View() string {
) )
tmp := helpers.PlaceOverlay(5, m.ctx.Screen[1]-21, tmp := helpers.PlaceOverlay(5, m.ctx.Screen[1]-21,
m.ctx.Theme.DialogBox.Window.Render(replyWindow), m.ctx.Theme.DialogBox.Window.Focused.Render(replyWindow),
view.String(), true) view.String(), true)
view = strings.Builder{} view = strings.Builder{}
@ -352,7 +364,7 @@ func (m *Model) renderReplies(
lipgloss.NewStyle(). lipgloss.NewStyle().
Foreground(m.ctx.Theme.Reply.Author.GetBackground()). Foreground(m.ctx.Theme.Reply.Author.GetBackground()).
Render(fmt.Sprintf("writes in reply to %s:", inReplyTo)), Render(fmt.Sprintf("writes in reply to %s:", inReplyTo)),
strings.Repeat(" ", (m.viewport.Width-len(author)-len(inReplyTo)-26)), strings.Repeat(" ", (m.viewport.Width-len(author)-len(inReplyTo)-28)),
lipgloss.NewStyle(). lipgloss.NewStyle().
Foreground(lipgloss.Color("#777777")). Foreground(lipgloss.Color("#777777")).
Render(fmt.Sprintf("#%d", idx)), Render(fmt.Sprintf("#%d", idx)),