Skip to content

Commit

Permalink
feat: allow to set the height of the item
Browse files Browse the repository at this point in the history
The user might want to show more than 2 lines, and, right now, if they
try to do so, things break.

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed May 24, 2022
1 parent 2a8d463 commit 9e97b08
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion list/defaultitem.go
Expand Up @@ -86,6 +86,7 @@ type DefaultDelegate struct {
UpdateFunc func(tea.Msg, *Model) tea.Cmd
ShortHelpFunc func() []key.Binding
FullHelpFunc func() [][]key.Binding
height int
spacing int
}

Expand All @@ -94,14 +95,22 @@ func NewDefaultDelegate() DefaultDelegate {
return DefaultDelegate{
ShowDescription: true,
Styles: NewDefaultItemStyles(),
height: 2,
spacing: 1,
}
}

// SetHeight sets delegate's preferred height.
func (d *DefaultDelegate) SetHeight(i int) {
d.height = i
}

// Height returns the delegate's preferred height.
// This has effect only if ShowDescription is true,
// otherwise height is always 1.
func (d DefaultDelegate) Height() int {
if d.ShowDescription {
return 2 //nolint:gomnd
return d.height
}
return 1
}
Expand Down

0 comments on commit 9e97b08

Please sign in to comment.