diff options
author | Benjamin Chausse <benjamin@chausse.xyz> | 2024-12-28 00:46:18 -0500 |
---|---|---|
committer | Benjamin Chausse <benjamin@chausse.xyz> | 2024-12-28 00:46:18 -0500 |
commit | 101e23780e5f8bc97f5683f5901fbd31f56ce29e (patch) | |
tree | 59a67abf320f8b77440cc7597331796f8b4a57a9 /internal/picker/picker.go | |
parent | 914633df3e8da138bc2ac78f69fe340832e2283d (diff) |
First attempt at auto-resizecentral-ui
Diffstat (limited to 'internal/picker/picker.go')
-rw-r--r-- | internal/picker/picker.go | 21 |
1 files changed, 21 insertions, 0 deletions
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): |