Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@nmorenor
Copy link
Contributor

Change to allow dynamically set all entries, add an entry or remove an existing entry.

@CLAassistant
Copy link

CLAassistant commented Jun 23, 2023

CLA assistant check
All committers have signed the CLA.

@mcarpenter622
Copy link
Collaborator

This looks good but I still need a little more time to just test it out.

widget/list.go Outdated
scrollContainerOpts []ScrollContainerOpt
sliderOpts []SliderOpt
entries []interface{}
entriesTable map[interface{}]*Button
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This map needs to be initialized ~ line 87. When I run the list demo it fails to start due to this map being null

	l := &List{
		EntrySelectedEvent: &event.Event{},

		init:           &MultiOnce{},
		focusIndex:     0,
		prevFocusIndex: -1,
		entriesTable:   make(map[interface{}]*Button),
	}

widget/list.go Outdated

l.buttons[l.focusIndex].focused = true
} else {
} else if len(l.buttons) > 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're trying to avoid null pointers here, and above, perhaps instead of checking vs 0 we should check vs the focusIndex. So if l.focusIndex <= len(l.buttons) {

@mat007
Copy link
Contributor

mat007 commented Aug 5, 2023

@nmorenor I’m interested by this feature as well. Is adding a new demo the only missing bits? I can probably do it if you want?

@mcarpenter622
Copy link
Collaborator

That is the main thing I've been waiting for. Everything else looks good atm.

@nmorenor
Copy link
Contributor Author

nmorenor commented Aug 7, 2023

Did not notice the request for the widget demo, will work on it over the week.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks.

targetEntry := l.idEntryTable[identifier]
if len(l.entries) > 1 {
for i, e := range l.entries {
if e == targetEntry {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain the entryIdentifier thing? It doesnt really seem like it buys us anything since we're looping through the entries anyways? Why do we want/need this?

Copy link
Contributor Author

@nmorenor nmorenor Aug 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, basically when removing an entry it is a copy of the value so when iterating over entries the == comparison is false, since it is a copy, if we save it on a map it is the same value so comparison is true. It iterates over all of the array to be able to remove the entry from the array. Open to any suggestion.

@mcarpenter622
Copy link
Collaborator

mcarpenter622 commented Aug 13, 2023 via email

Copy link
Collaborator

@mcarpenter622 mcarpenter622 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mcarpenter622 mcarpenter622 merged commit e2722aa into ebitenui:master Aug 23, 2023

func (l *List) RemoveEntry(entry interface{}) {
if l.entryIdentifier == nil {
log.Println("cannot add entry without identifier function")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be

		log.Println("cannot remove entry without identifier function")

?

@mcarpenter622
Copy link
Collaborator

mcarpenter622 commented Aug 24, 2023 via email

@mcarpenter622
Copy link
Collaborator

Hey guys, Just an FYI, I made a few changes to the list to resolve some bugs I found after merging. It should be working a little nicer now. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Changing of List entries not possible after creation?

4 participants