1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-12-04 14:46:37 -05:00

Refactored List style

This commit is contained in:
マリウス 2022-12-31 17:18:53 -05:00
parent 54e8f53b77
commit c2f13b5d5a
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
3 changed files with 110 additions and 38 deletions

View File

@ -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})

View File

@ -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...).

View File

@ -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 {