~whereswaldon/rosebud

9028c694b5a424dc0ee8e61196fdf597f163afd8 — Chris Waldon 1 year, 2 months ago aeb4309
appwidget{,/apptheme}: use slice of pointers to avoid weird state bugs

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

M appwidget/apptheme/suggestor.go
M appwidget/tx-editor.go
M appwidget/apptheme/suggestor.go => appwidget/apptheme/suggestor.go +3 -3
@@ 51,9 51,9 @@ func (s SuggestorStyle[T]) Layout(gtx C) D {
			if index < len(s.State.Entities) {
				entity := s.State.Entities[index]
				for index > len(s.State.Clickables)-1 {
					s.State.Clickables = append(s.State.Clickables, widget.Clickable{})
					s.State.Clickables = append(s.State.Clickables, &widget.Clickable{})
				}
				click := &s.State.Clickables[index]
				click := s.State.Clickables[index]
				return material.Clickable(gtx, click, func(gtx C) D {
					return layout.Stack{}.Layout(gtx,
						layout.Expanded(func(gtx C) D {


@@ 72,7 72,7 @@ func (s SuggestorStyle[T]) Layout(gtx C) D {
					)
				})
			}
			click := &s.State.Clickables[index]
			click := s.State.Clickables[index]
			return material.Clickable(gtx, click, func(gtx C) D {
				return layout.Stack{}.Layout(gtx,
					layout.Expanded(func(gtx C) D {

M appwidget/tx-editor.go => appwidget/tx-editor.go +3 -3
@@ 59,7 59,7 @@ type Suggestor[T comparable] struct {
	// After the first layout, there should always be one more clickable
	// than entity. The final clickable is used for the "create new entity"
	// option.
	Clickables []widget.Clickable
	Clickables []*widget.Clickable
	Entities   []T
	events     []event.Event
}


@@ 94,7 94,7 @@ func (s *Suggestor[T]) Events() []event.Event {
func (s *Suggestor[T]) Layout(gtx C) D {
	for i := range s.Entities {
		if i >= len(s.Clickables) {
			s.Clickables = append(s.Clickables, widget.Clickable{})
			s.Clickables = append(s.Clickables, &widget.Clickable{})
		}
		if s.Clickables[i].Clicked() {
			s.events = append(s.events, SuggestionAcceptedEvent[T]{


@@ 104,7 104,7 @@ func (s *Suggestor[T]) Layout(gtx C) D {
	}
	createIndex := len(s.Entities)
	if createIndex > len(s.Clickables)-1 {
		s.Clickables = append(s.Clickables, widget.Clickable{})
		s.Clickables = append(s.Clickables, &widget.Clickable{})
	}
	if s.Clickables[createIndex].Clicked() {
		s.events = append(s.events, SuggestionCreateNewEvent[T]{})