mirror of
https://github.com/Maks1mS/bubbles.git
synced 2024-12-25 07:04:37 +03:00
Viewport New() is now optional to ease the upgrade process
This commit is contained in:
parent
add13c8028
commit
9401ebbb83
@ -9,16 +9,13 @@ import (
|
|||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewModel returns a new model with the given width and height as well as
|
// New returns a new model with the given width and height as well as default
|
||||||
// default keymappings.
|
// keymappings.
|
||||||
func NewModel(width, height int) Model {
|
func New(width, height int) (m Model) {
|
||||||
return Model{
|
m.Width = width
|
||||||
Width: width,
|
m.Height = height
|
||||||
Height: height,
|
m.setInitialValues()
|
||||||
KeyMap: DefaultKeyMap(),
|
return m
|
||||||
MouseWheelEnabled: true,
|
|
||||||
MouseWheelDelta: 3,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Model is the Bubble Tea model for this viewport element.
|
// Model is the Bubble Tea model for this viewport element.
|
||||||
@ -55,7 +52,15 @@ type Model struct {
|
|||||||
// which is usually via the alternate screen buffer.
|
// which is usually via the alternate screen buffer.
|
||||||
HighPerformanceRendering bool
|
HighPerformanceRendering bool
|
||||||
|
|
||||||
lines []string
|
initialized bool
|
||||||
|
lines []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Model) setInitialValues() {
|
||||||
|
m.KeyMap = DefaultKeyMap()
|
||||||
|
m.MouseWheelEnabled = true
|
||||||
|
m.MouseWheelDelta = 3
|
||||||
|
m.initialized = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init exists to satisfy the tea.Model interface for composability purposes.
|
// Init exists to satisfy the tea.Model interface for composability purposes.
|
||||||
@ -263,6 +268,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
|||||||
// Author's note: this method has been broken out to make it easier to
|
// Author's note: this method has been broken out to make it easier to
|
||||||
// potentially transition Update to satisfy tea.Model.
|
// potentially transition Update to satisfy tea.Model.
|
||||||
func (m Model) updateAsModel(msg tea.Msg) (Model, tea.Cmd) {
|
func (m Model) updateAsModel(msg tea.Msg) (Model, tea.Cmd) {
|
||||||
|
if !m.initialized {
|
||||||
|
m.setInitialValues()
|
||||||
|
}
|
||||||
|
|
||||||
var cmd tea.Cmd
|
var cmd tea.Cmd
|
||||||
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
|
Loading…
Reference in New Issue
Block a user