Add sidebar and search box layout
Introduce a `sidebarContent` field to the `model` and update the `View` function to render a sidebar alongside the text input, creating a basic two-pane layout.
This commit is contained in:
24
main.go
24
main.go
@@ -10,9 +10,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type model struct {
|
type model struct {
|
||||||
textInput textinput.Model
|
textInput textinput.Model
|
||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
|
sidebarContent string
|
||||||
}
|
}
|
||||||
|
|
||||||
func initialModel() model {
|
func initialModel() model {
|
||||||
@@ -23,7 +24,8 @@ func initialModel() model {
|
|||||||
ti.Prompt = ""
|
ti.Prompt = ""
|
||||||
ti.Focus()
|
ti.Focus()
|
||||||
return model{
|
return model{
|
||||||
textInput: ti,
|
textInput: ti,
|
||||||
|
sidebarContent: "Library\n\nPlaylist 1\nPlaylist 2\nFavorites",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,12 +53,22 @@ func (m model) View() string {
|
|||||||
if m.width == 0 {
|
if m.width == 0 {
|
||||||
return "loading..."
|
return "loading..."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create search box
|
||||||
|
searchBox := lipgloss.NewStyle().BorderStyle(lipgloss.ThickBorder()).Padding(0, 1).Render(m.textInput.View())
|
||||||
|
|
||||||
|
// Create sidebar
|
||||||
|
sidebar := lipgloss.NewStyle().BorderStyle(lipgloss.NormalBorder()).Padding(1, 2).Render(m.sidebarContent)
|
||||||
|
|
||||||
|
// Combine search and sidebar vertically
|
||||||
|
content := lipgloss.JoinVertical(lipgloss.Left, searchBox, "\n", sidebar)
|
||||||
|
|
||||||
return lipgloss.Place(
|
return lipgloss.Place(
|
||||||
m.width,
|
m.width,
|
||||||
m.height,
|
m.height,
|
||||||
lipgloss.Center,
|
lipgloss.Center,
|
||||||
0,
|
lipgloss.Center,
|
||||||
lipgloss.NewStyle().BorderStyle(lipgloss.ThickBorder()).Padding(0, 1).Render(m.textInput.View()),
|
content,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user