-
Notifications
You must be signed in to change notification settings - Fork 73
Allow to dynamically change the list entries #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) {
|
@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? |
|
That is the main thing I've been waiting for. Everything else looks good atm. |
|
Did not notice the request for the widget demo, will work on it over the week. |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
|
Thanks for clarifying. Not sure a better way but will think on it tonight
and get back to you. Thank you again for helping with this!
…On Sat, Aug 12, 2023, 10:25 PM Ignacio Moreno ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In widget/list.go
<#78 (comment)>:
> + l.createWidget()
+ l.resetFocusIndex()
+}
+
+func (l *List) RemoveEntry(entry interface{}) {
+ if l.entryIdentifier == nil {
+ log.Println("cannot add entry without identifier function")
+ return
+ }
+ l.init.Do()
+
+ identifier := (*l.entryIdentifier)(entry)
+ targetEntry := l.idEntryTable[identifier]
+ if len(l.entries) > 1 {
+ for i, e := range l.entries {
+ if e == targetEntry {
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 we iterate
over all of the array to be able to remove the entry from the array. Open
to any suggestion.
—
Reply to this email directly, view it on GitHub
<#78 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADJ7PVSDBKCXGJWWR4C4WDLXVA3LBANCNFSM6AAAAAAZR5MNSA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
mcarpenter622
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
|
|
||
| func (l *List) RemoveEntry(entry interface{}) { | ||
| if l.entryIdentifier == nil { | ||
| log.Println("cannot add entry without identifier function") |
There was a problem hiding this comment.
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")
?
|
There are several concerns with this one I found after merging yesterday.
I'm reworking most of this and will have it fixed later today. Good eye
though!
…On Thu, Aug 24, 2023, 4:44 AM Mathieu Champlon ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In widget/list.go
<#78 (comment)>:
> - l.sliderOpts = nil
+
+}
+
+func (l *List) SetEntries(entries []interface{}) {
+ l.entries = entries
+ l.entriesButtonTable = make(map[interface{}]*Button, len(entries))
+ l.idEntryTable = make(map[string]interface{}, len(entries))
+ l.container.RemoveChildren()
+ l.createWidget()
+ l.resetFocusIndex()
+}
+
+func (l *List) RemoveEntry(entry interface{}) {
+ if l.entryIdentifier == nil {
+ log.Println("cannot add entry without identifier function")
I believe this should be
log.Println("cannot remove entry without identifier function")
?
—
Reply to this email directly, view it on GitHub
<#78 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADJ7PVUPXT5MNV7LLWFTKRTXW4H5LANCNFSM6AAAAAAZR5MNSA>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
|
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! |
Change to allow dynamically set all entries, add an entry or remove an existing entry.