mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-16 01:43:21 +00:00
feat!(viewport): width and height are now optional args in New()
This commit is contained in:
+1
-1
@@ -132,7 +132,7 @@ type Option func(*Model)
|
||||
func New(opts ...Option) Model {
|
||||
m := Model{
|
||||
cursor: 0,
|
||||
viewport: viewport.New(0, 20), //nolint:mnd
|
||||
viewport: viewport.New(viewport.WithHeight(20)), //nolint:mnd
|
||||
|
||||
KeyMap: DefaultKeyMap(),
|
||||
Help: help.New(),
|
||||
|
||||
@@ -286,7 +286,7 @@ type Model struct {
|
||||
|
||||
// New creates a new model with default settings.
|
||||
func New() Model {
|
||||
vp := viewport.New(0, 0)
|
||||
vp := viewport.New()
|
||||
vp.KeyMap = viewport.KeyMap{}
|
||||
cur := cursor.New()
|
||||
|
||||
|
||||
+26
-3
@@ -9,11 +9,34 @@ import (
|
||||
"github.com/charmbracelet/lipgloss/v2"
|
||||
)
|
||||
|
||||
// Option is a configuration option that works in conjunction with [New]. For
|
||||
// example:
|
||||
//
|
||||
// timer := New(WithWidth(10, WithHeight(5)))
|
||||
type Option func(*Model)
|
||||
|
||||
// WithWidth is an initialization option that sets the width of the
|
||||
// viewport. Pass as an argument to [New].
|
||||
func WithWidth(w int) Option {
|
||||
return func(m *Model) {
|
||||
m.Width = w
|
||||
}
|
||||
}
|
||||
|
||||
// WithHeight is an initialization option that sets the height of the
|
||||
// viewport. Pass as an argument to [New].
|
||||
func WithHeight(h int) Option {
|
||||
return func(m *Model) {
|
||||
m.Height = h
|
||||
}
|
||||
}
|
||||
|
||||
// New returns a new model with the given width and height as well as default
|
||||
// key mappings.
|
||||
func New(width, height int) (m Model) {
|
||||
m.Width = width
|
||||
m.Height = height
|
||||
func New(opts ...Option) (m Model) {
|
||||
for _, opt := range opts {
|
||||
opt(&m)
|
||||
}
|
||||
m.setInitialValues()
|
||||
return m
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user