Skip to content

Commit

Permalink
fix: use pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
wezzle committed Sep 6, 2024
1 parent 980b4c6 commit a282c7c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
11 changes: 7 additions & 4 deletions model/main_model.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package model

import tea "github.com/charmbracelet/bubbletea"
import (
tea "github.com/charmbracelet/bubbletea"
)

func NewMainModel() MainModel {
m := MainModel{}
m.TableModel = NewTableModel(&m)
t := NewTableModel(&m)
m.TableModel = &t
m.activeModel = m.TableModel
return m
}

type MainModel struct {
TableModel Table
UnitModel Unit
TableModel *Table
UnitModel *Unit

activeModel tea.Model
}
Expand Down
8 changes: 4 additions & 4 deletions model/table_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ type Table struct {
mainModel *MainModel
}

func (m Table) Init() tea.Cmd {
func (m *Table) Init() tea.Cmd {
return nil
}

func (m Table) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m *Table) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
sortStringColumn := -1
sortIntColumn := 0
sortIntColumn := -1
reverse := false
switch msg := msg.(type) {
case tea.KeyMsg:
Expand Down Expand Up @@ -191,6 +191,6 @@ func (m Table) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, cmd
}

func (m Table) View() string {
func (m *Table) View() string {
return baseStyle.Render(m.Table.View()) + "\n " + m.Table.HelpView() + "\n"
}
16 changes: 8 additions & 8 deletions model/unit_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var (
}
)

func NewUnitModel(ref util.UnitRef, mainModel *MainModel) Unit {
func NewUnitModel(ref util.UnitRef, mainModel *MainModel) *Unit {
m := Unit{}
m.ref = ref
m.mainModel = mainModel
Expand All @@ -55,7 +55,7 @@ func NewUnitModel(ref util.UnitRef, mainModel *MainModel) Unit {
m.sightRange = progress.New(progress.WithSolidFill("#C6C8C9"), progress.WithoutPercentage())
m.speed = progress.New(progress.WithSolidFill("#1175AE"), progress.WithoutPercentage())

return m
return &m
}

type Unit struct {
Expand All @@ -76,11 +76,11 @@ type Unit struct {
speed progress.Model
}

func (m Unit) Init() tea.Cmd {
func (m *Unit) Init() tea.Cmd {
return nil
}

func (m Unit) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m *Unit) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
switch msg := msg.(type) {
case tea.KeyMsg:
Expand All @@ -93,7 +93,7 @@ func (m Unit) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, cmd
}

func (m Unit) RenderBar(labelWidth int, label string, progress string, maxValueWidth int, value string) string {
func (m *Unit) RenderBar(labelWidth int, label string, progress string, maxValueWidth int, value string) string {
v := value
for range maxValueWidth - len(value) {
v = " " + v
Expand All @@ -106,15 +106,15 @@ func (m Unit) RenderBar(labelWidth int, label string, progress string, maxValueW
return padding.Render(lipgloss.JoinHorizontal(lipgloss.Top, bar...))
}

func (m Unit) PercentageWithBase(value int, base float64) float64 {
func (m *Unit) PercentageWithBase(value int, base float64) float64 {
return m.PercentageWithBaseF(float64(value), base)
}

func (m Unit) PercentageWithBaseF(value float64, base float64) float64 {
func (m *Unit) PercentageWithBaseF(value float64, base float64) float64 {
return min(value/base, 100.0) / 100
}

func (m Unit) View() string {
func (m *Unit) View() string {
var sections []string

var titleRow []string
Expand Down

0 comments on commit a282c7c

Please sign in to comment.