From 101e23780e5f8bc97f5683f5901fbd31f56ce29e Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Sat, 28 Dec 2024 00:46:18 -0500 Subject: First attempt at auto-resize --- internal/picker/picker.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'internal/picker/picker.go') diff --git a/internal/picker/picker.go b/internal/picker/picker.go index 1c39aaa..696bf2a 100644 --- a/internal/picker/picker.go +++ b/internal/picker/picker.go @@ -129,10 +129,31 @@ func (m Model) View() string { return strings.Join(sliderList, "\n") } +func (m Model) FixWidth(windowW int) (tea.Model, tea.Cmd) { + cmds := []tea.Cmd{} + currentW := ui.SliderMaxWidth + if (currentW + ui.BoxOffsetW) > windowW { + currentW -= (currentW + ui.BoxOffsetW) - windowW + } + if currentW < ui.SliderMinWidth { + currentW = ui.SliderMinWidth + } + for i, s := range m.sliders { + model, cmd := s.SetWidth(currentW) + cmds = append(cmds, cmd) + m.sliders[i] = model.(slider.Model) + } + return m, tea.Batch(cmds...) +} + func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { keys := newKeybinds() cmds := []tea.Cmd{} switch msg := msg.(type) { + case tea.WindowSizeMsg: + newModel, cmd := m.FixWidth(msg.Width) + cmds = append(cmds, cmd) + return newModel, tea.Batch(cmds...) case tea.KeyMsg: switch { case key.Matches(msg, keys.next): -- cgit v1.2.3