Skip to content

Commit

Permalink
more sizing, active border
Browse files Browse the repository at this point in the history
  • Loading branch information
treethought committed Jun 15, 2024
1 parent 7de44d3 commit c6938c7
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 38 deletions.
46 changes: 28 additions & 18 deletions ui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import (
// TODO provide to models
var renderer *lipgloss.Renderer = lipgloss.DefaultRenderer()

var activeColor = lipgloss.AdaptiveColor{Dark: "#874BFD", Light: "#874BFD"}

var (
mainStyle = lipgloss.NewStyle().Margin(0).Padding(0).Border(lipgloss.RoundedBorder()).BorderForeground(lipgloss.Color("#874BFD"))
mainStyle = lipgloss.NewStyle().Margin(0).Padding(0).Border(lipgloss.RoundedBorder())
)

func NewStyle() lipgloss.Style {
Expand Down Expand Up @@ -276,25 +278,28 @@ func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
_, statusHeight := lipgloss.Size(a.statusLine.View())

wx, wy := msg.Width, msg.Height-statusHeight
fx, fy := mainStyle.GetFrameSize()
wx = wx - fx
wy = wy - fy

sideMax := 30
sidePct := int(float64(wx) * 0.2)
sx := sidePct
if sideMax < sidePct {
sx = sideMax
}
a.sidebar.SetSize(sx, wy-4)
spx := min(80, wx-10)
spy := min(80, wy-10)

a.splash.SetSize(spx, spy)

sx := min(30, int(float64(wx)*0.2))
a.sidebar.SetSize(sx, wy-statusHeight)
sideWidth, _ := lipgloss.Size(a.sidebar.View())

pw := wx - sideWidth
py := wy - 10
a.publish.SetSize(pw, py)
a.splash.SetSize(pw, py)
a.quickSelect.SetSize(pw, py)
a.help.SetSize(pw, py)
mx := wx - sideWidth
mx = min(mx, int(float64(wx)*0.8))

fx, fy := mainStyle.GetFrameSize()
mx, my := wx-sideWidth-fx-4, wy-fy
my := min(wy, int(float64(wy)*0.9))

dialogX, dialogY := int(float64(mx)*0.8), int(float64(my)*0.8)
a.publish.SetSize(dialogX, dialogY)
a.quickSelect.SetSize(dialogX, dialogY)
a.help.SetSize(dialogX, dialogY)

childMsg := tea.WindowSizeMsg{
Width: mx,
Expand Down Expand Up @@ -375,7 +380,8 @@ func (a *App) View() string {
main := focus.View()
side := a.sidebar.View()
if a.splash.Active() {
main = a.splash.View()
main = lipgloss.Place(GetWidth(), GetHeight(), lipgloss.Center, lipgloss.Center, a.splash.View())
return main
}

if a.publish.Active() {
Expand All @@ -392,7 +398,11 @@ func (a *App) View() string {
main = a.help.View()
}

main = mainStyle.Render(main)
ss := mainStyle
if !a.sidebar.Active() {
ss = ss.BorderForeground(activeColor)
}
main = ss.Render(main)

return lipgloss.JoinVertical(lipgloss.Top,
lipgloss.JoinHorizontal(lipgloss.Center, side, main),
Expand Down
14 changes: 7 additions & 7 deletions ui/cast_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,29 +89,29 @@ func (m *CastView) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmds := []tea.Cmd{}

fx, fy := style.GetFrameSize()
w := min(msg.Width-fx, int(float64(GetWidth())*0.75))
h := min(msg.Height-fy, GetHeight()-4)

w, h := msg.Width-fx, msg.Height-fy
m.w, m.h = w, h

m.header.Width = w
m.header.Height = min(10, int(float64(h)*0.2))

hHeight := lipgloss.Height(m.header.View())

cx, cy := w, h-hHeight
cy := h - hHeight

m.vp.Width = cx
m.vp.Height = int(float64(cy) * 0.5)
m.vp.Width = w - fx
m.vp.Height = int(float64(cy) * 0.5) //- fy

m.img.SetSize(0, 0)

if m.hasImg {
m.img.SetSize(4, 4)
m.vp.Height = int(float64(cy) * 0.25)
}
m.replies.SetSize(msg.Width, int(float64(cy)*0.5))
m.replies.SetSize(w, int(float64(cy)*0.5))

m.pubReply.SetSize(msg.Width, msg.Height-10)
m.pubReply.SetSize(m.w, m.h)
return m, tea.Batch(cmds...)

case *ctxInfoMsg:
Expand Down
7 changes: 5 additions & 2 deletions ui/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,14 @@ func (m *FeedView) SetSize(w, h int) {

_, dy := lipgloss.Size(channelHeaderStyle.Render(m.descVp.View()))
fx, fy := feedStyle.GetFrameSize()
m.table.SetWidth(w - fx)
x := min(w-fx, int(float64(GetWidth())*0.75))
m.table.SetWidth(x)
m.table.SetHeight(h - fy - dy)

// m.table.SetWidth(w -fx)
m.setTableConfig()

lw := int(float64(w) * 0.2)
lw := int(float64(w) * 0.75)
m.loading.SetSize(lw, h)
}

Expand Down
13 changes: 3 additions & 10 deletions ui/quickselect.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,12 @@ func (m *QuickSelect) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, cmd
}

var dialogBoxStyle = NewStyle().
Border(lipgloss.RoundedBorder()).
BorderForeground(lipgloss.Color("#874BFD")).
Padding(1, 0).
BorderTop(true).
BorderLeft(true).
BorderRight(true).
BorderBottom(true)
var dialogBoxStyle = NewStyle()

func (m *QuickSelect) View() string {
dialog := lipgloss.Place(10, 10,
dialog := lipgloss.Place(m.h, m.h,
lipgloss.Center, lipgloss.Center,
dialogBoxStyle.Width(m.w).Height(m.h).Render(m.channelList.View()),
dialogBoxStyle.Render(m.channelList.View()),
lipgloss.WithWhitespaceChars("~~"),
lipgloss.WithWhitespaceForeground(subtle),
)
Expand Down
7 changes: 6 additions & 1 deletion ui/sidebar.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,14 @@ func (m *Sidebar) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, tea.Batch(cmds...)
}
func (m *Sidebar) View() string {
ss := navStyle
if m.account == nil {
return navStyle.Render(m.nav.View())
}
if m.active {
ss = navStyle.BorderForeground(activeColor)

}

accountStyle := NewStyle().
Border(lipgloss.RoundedBorder(), true, false, true).
Expand All @@ -208,7 +213,7 @@ func (m *Sidebar) View() string {
),
)

return navStyle.Render(
return ss.Render(
lipgloss.JoinVertical(lipgloss.Top,
m.nav.View(),
account,
Expand Down

0 comments on commit c6938c7

Please sign in to comment.