~whereswaldon/rosebud

c76466cf512d1797117ea5039c03dd39e64f2f34 — Chris Waldon 1 year, 3 months ago a19d9ed
deps,cmd/rosebud: add a tx editor to test it out

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
3 files changed, 51 insertions(+), 24 deletions(-)

M cmd/rosebud/main.go
M go.mod
M go.sum
M cmd/rosebud/main.go => cmd/rosebud/main.go +38 -19
@@ 24,8 24,12 @@ import (
	"git.sr.ht/~gioverse/skel/bus"
	"git.sr.ht/~gioverse/skel/future"
	"git.sr.ht/~gioverse/skel/window"
	"git.sr.ht/~whereswaldon/rosebud/appwidget"
	"git.sr.ht/~whereswaldon/rosebud/appwidget/apptheme"
	"git.sr.ht/~whereswaldon/rosebud/theme"
	"github.com/howeyc/ledger"
	"github.com/lithammer/fuzzysearch/fuzzy"
	"golang.org/x/exp/maps"
)

func main() {


@@ 50,7 54,7 @@ const (
func loop(w *app.Window, conn bus.Connection) error {
	var ops op.Ops
	ui := UI{
		Theme:    material.NewTheme(gofont.Collection()),
		Theme:    apptheme.NewTheme(gofont.Collection()),
		Explorer: explorer.NewExplorer(w),
		Conn:     conn,
	}


@@ 83,7 87,7 @@ type UI struct {
	Explorer *explorer.Explorer
	Conn     bus.Connection

	Theme         *material.Theme
	Theme         *apptheme.Theme
	Txs           []*ledger.Transaction
	Balances      []*ledger.Account
	OutFilePath   string


@@ 94,7 98,8 @@ type UI struct {
	TxList      widget.List
	BalanceList widget.List
	AccountRegistry
	Tree *AccountTreeNode
	Tree     *AccountTreeNode
	TxEditor appwidget.TxEditor
}

type AccountState struct {


@@ 135,7 140,7 @@ func (ui *UI) Layout(gtx C) D {
		ui.requestFiles()
		ui.Stage = LoadingFiles
	case LoadingFiles:
		return layout.Center.Layout(gtx, material.Loader(ui.Theme).Layout)
		return layout.Center.Layout(gtx, material.Loader(ui.Theme.Th).Layout)
	case Ready:
		return ui.layout(gtx)
	}


@@ 246,7 251,7 @@ func (ui *UI) layout(gtx C) D {

func (u *UI) layoutBalancesPanel(gtx C) D {
	u.BalanceList.Axis = layout.Vertical
	list := material.List(u.Theme, &u.BalanceList)
	list := material.List(u.Theme.Th, &u.BalanceList)
	return list.Layout(gtx, 1, func(gtx C, index int) D {
		return u.layoutAccountTree(gtx, u.Tree)
	})


@@ 257,7 262,7 @@ func (u *UI) layoutAccountTree(gtx C, at *AccountTreeNode) D {
		return D{}
	}
	ds := u.AccountRegistry.Get(at.Account)
	d := component.SimpleDiscloser(u.Theme, &ds.DiscloserState)
	d := component.SimpleDiscloser(u.Theme.Th, &ds.DiscloserState)
	if len(at.Children) > 0 {
		var children []layout.FlexChild
		for i := range at.Children {


@@ 266,7 271,7 @@ func (u *UI) layoutAccountTree(gtx C, at *AccountTreeNode) D {
				return u.layoutAccountTreeNode(gtx, child)
			}))
		}
		return d.Layout(gtx, material.Body1(u.Theme, "Journal").Layout,
		return d.Layout(gtx, material.Body1(u.Theme.Th, "Journal").Layout,
			func(gtx C) D {
				return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
					children...)


@@ 277,7 282,7 @@ func (u *UI) layoutAccountTree(gtx C, at *AccountTreeNode) D {

func (u *UI) layoutAccountTreeNode(gtx C, at *AccountTreeNode) D {
	ds := u.AccountRegistry.Get(at.Account)
	d := component.SimpleDiscloser(u.Theme, &ds.DiscloserState)
	d := component.SimpleDiscloser(u.Theme.Th, &ds.DiscloserState)
	balance := at.Account
	parts := strings.Split(balance.Name, ":")
	balance.Name = parts[len(parts)-1]


@@ 294,38 299,52 @@ func (u *UI) layoutAccountTreeNode(gtx C, at *AccountTreeNode) D {
			if ds.Hovered() {
				macro := op.Record(gtx.Ops)
				layout.E.Layout(gtx, func(gtx C) D {
					return component.Surface(u.Theme).Layout(gtx, func(gtx C) D {
						return layout.UniformInset(unit.Dp(2)).Layout(gtx, material.Body2(u.Theme, "Residue: "+at.Residue.FloatString(2)).Layout)
					return component.Surface(u.Theme.Th).Layout(gtx, func(gtx C) D {
						return layout.UniformInset(unit.Dp(2)).Layout(gtx, material.Body2(u.Theme.Th, "Residue: "+at.Residue.FloatString(2)).Layout)
					})
				})
				op.Defer(gtx.Ops, macro.Stop())
			}
			return ds.Clickable.Layout(gtx, theme.Account(u.Theme, balance).Layout)
			return ds.Clickable.Layout(gtx, theme.Account(u.Theme.Th, balance).Layout)
		},
			func(gtx C) D {
				return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
					children...)
			})
	}
	return d.DetailInset().Layout(gtx, theme.Account(u.Theme, balance).Layout)
	return d.DetailInset().Layout(gtx, theme.Account(u.Theme.Th, balance).Layout)
}

func (u *UI) layoutTransactions(gtx C) D {
	u.TxList.Axis = layout.Vertical
	list := material.List(u.Theme, &u.TxList)
	return list.Layout(gtx, len(u.Txs), func(gtx C, index int) D {
		tx := u.Txs[index]
		return theme.Transaction(u.Theme, tx).Layout(gtx)
	})
	list := material.List(u.Theme.Th, &u.TxList)
	return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
		layout.Rigid(func(gtx C) D {
			for _, e := range u.TxEditor.Events() {
				switch e := e.(type) {
				case appwidget.SuggestionRequestEvent[string]:
					suggestions := fuzzy.FindFold(e.Text, maps.Keys(u.AccountRegistry.elements))
					u.TxEditor.SetSuggestions(suggestions)
				}
			}
			return apptheme.TxEditor(u.Theme, &u.TxEditor, "Account name").Layout(gtx)
		}),
		layout.Flexed(1, func(gtx C) D {
			return list.Layout(gtx, len(u.Txs), func(gtx C, index int) D {
				tx := u.Txs[index]
				return theme.Transaction(u.Theme.Th, tx).Layout(gtx)
			})
		}),
	)
}

func (u *UI) layoutTopBar(gtx C) D {
	surf := component.Surface(u.Theme)
	surf := component.Surface(u.Theme.Th)
	surf.CornerRadius = unit.Dp(0)
	return surf.Layout(gtx, func(gtx C) D {
		return layout.Flex{Alignment: layout.Middle}.Layout(gtx,
			layout.Rigid(func(gtx C) D {
				return LayoutLogo(gtx, u.Theme)
				return LayoutLogo(gtx, u.Theme.Th)
			}),
			layout.Flexed(1, func(gtx C) D {
				return D{

M go.mod => go.mod +5 -1
@@ 7,6 7,8 @@ require (
	gioui.org/x v0.0.0-20221121204253-9da08d942944
	git.sr.ht/~gioverse/skel v0.0.0-20220916150537-2f38f089e413
	github.com/howeyc/ledger v0.3.5
	github.com/lithammer/fuzzysearch v1.1.5
	golang.org/x/exp v0.0.0-20221114191408-850992195362
)

require (


@@ 21,6 23,8 @@ require (
	github.com/marcmak/calc v0.0.0-20150509200512-5bbbfc3b3149 // indirect
	golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91 // indirect
	golang.org/x/image v0.0.0-20220722155232-062f8c9fd539 // indirect
	golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 // indirect
	golang.org/x/sys v0.1.0 // indirect
	golang.org/x/text v0.3.7 // indirect
)

replace gioui.org => git.sr.ht/~whereswaldon/gio v0.0.0-20221026194450-4331d4bad0ee

M go.sum => go.sum +8 -4
@@ 1,6 1,4 @@
eliasnaur.com/font v0.0.0-20220124212145-832bb8fc08c3 h1:djFprmHZgrSepsHAIRMp5UJn3PzsoTg9drI+BDmif5Q=
gioui.org v0.0.0-20221122135904-dee53b364560 h1:e4V8TAk0tBCjrISs3yUAOyzTTMwBmzlrKb0yhEI4YzU=
gioui.org v0.0.0-20221122135904-dee53b364560/go.mod h1:GN091SCcGAfHfQiSOetXx7Abdy+8nmONj0ZN63Xxf7w=
gioui.org/cpu v0.0.0-20210808092351-bfe733dd3334/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ=
gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 h1:AGDDxsJE1RpcXTAxPG2B4jrwVUJGFDjINIPi1jtO6pc=
gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2/go.mod h1:A8M0Cn5o+vY5LTMlnRoK3O5kG+rH0kWfJjeKd9QpBmQ=


@@ 10,6 8,8 @@ gioui.org/x v0.0.0-20221121204253-9da08d942944 h1:1qB+TI3FwPFWzyqF6LzW4jhC3Vc+Lb
gioui.org/x v0.0.0-20221121204253-9da08d942944/go.mod h1:uhVlN625ysZfFEbEdxt+wgyCGW2sh5p6SYs9dr+w+u4=
git.sr.ht/~gioverse/skel v0.0.0-20220916150537-2f38f089e413 h1:rqEp9NqS0icb0xxSWpUe11sHf0bhwobxd+O6Wei6wGc=
git.sr.ht/~gioverse/skel v0.0.0-20220916150537-2f38f089e413/go.mod h1:DtJGzJPf/ONJskXDaxORcVjIFpKWN7mBq0R8j7c4BQM=
git.sr.ht/~whereswaldon/gio v0.0.0-20221026194450-4331d4bad0ee h1:8XlfYeHKNtXPFLZ52vVxHm6JY+s0LcAgVV8moBS3BVQ=
git.sr.ht/~whereswaldon/gio v0.0.0-20221026194450-4331d4bad0ee/go.mod h1:GN091SCcGAfHfQiSOetXx7Abdy+8nmONj0ZN63Xxf7w=
git.wow.st/gmp/jni v0.0.0-20210610011705-34026c7e22d0 h1:bGG/g4ypjrCJoSvFrP5hafr9PPB5aw8SjcOWWila7ZI=
git.wow.st/gmp/jni v0.0.0-20210610011705-34026c7e22d0/go.mod h1:+axXBRUTIDlCeE73IKeD/os7LoEnTKdkp8/gQOFjqyo=
github.com/benoitkugler/pstokenizer v1.0.0/go.mod h1:l1G2Voirz0q/jj0TQfabNxVsa8HZXh/VMxFSRALWTiE=


@@ 27,8 27,12 @@ github.com/howeyc/ledger v0.3.5 h1:9EfDs73TzUUeK9W5spgAR1ELW5Ywd9lbd6ha25sgDf0=
github.com/howeyc/ledger v0.3.5/go.mod h1:Bt65DBbqSGABPEugJXzcbH1KOi3QBjIk/v6/AtoTkcM=
github.com/joyt/godate v0.0.0-20150226210126-7151572574a7 h1:2wH5antjhmU3EuWyidm0lJ4B9hGMpl5lNRo+M9uGJ5A=
github.com/joyt/godate v0.0.0-20150226210126-7151572574a7/go.mod h1:R+UgFL3iylLhx9N4w35zZ2HdhDlgorRDx4SxbchWuN0=
github.com/lithammer/fuzzysearch v1.1.5 h1:Ag7aKU08wp0R9QCfF4GoGST9HbmAIeLP7xwMrOBEp1c=
github.com/lithammer/fuzzysearch v1.1.5/go.mod h1:1R1LRNk7yKid1BaQkmuLQaHruxcC4HmAH30Dh61Ih1Q=
github.com/marcmak/calc v0.0.0-20150509200512-5bbbfc3b3149 h1:QaKQMdY9TmwTq+UPXBo1hGi95iguDE7q7sPvt6RqLiA=
github.com/marcmak/calc v0.0.0-20150509200512-5bbbfc3b3149/go.mod h1:op87dInbDFPr69TsmmZoW0q4hj8LV8VZYaG4p1rDzLY=
golang.org/x/exp v0.0.0-20221114191408-850992195362 h1:NoHlPRbyl1VFI6FjwHtPQCN7wAMXI6cKcqrmXhOOfBQ=
golang.org/x/exp v0.0.0-20221114191408-850992195362/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91 h1:ryT6Nf0R83ZgD8WnFFdfI8wCeyqgdXWN4+CkFVNPAT0=
golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91/go.mod h1:VjAR7z0ngyATZTELrBSkxOOHhhlnVUxDye4mcjx5h/8=
golang.org/x/image v0.0.0-20210504121937-7319ad40d33e/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=


@@ 38,8 42,8 @@ golang.org/x/image v0.0.0-20220722155232-062f8c9fd539/go.mod h1:doUCurBvlfPMKfmI
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 h1:UiNENfZ8gDvpiWw7IpOMQ27spWmThO1RwwdQVbJahJM=
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=