Skip to content
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

Prepend or more general Insert functionality for widgets like Accordion etc #5413

Closed
2 tasks done
JeffreyLeeLi opened this issue Jan 15, 2025 · 3 comments
Closed
2 tasks done
Labels
question A question has been asked

Comments

@JeffreyLeeLi
Copy link

Checklist

  • I have searched the issue tracker for open issues that relate to the same feature, before opening a new one.
  • This issue only relates to a single feature. I will open new issues for any other features.

Is your feature request related to a problem?

For one of my application, new search result is best suited to appear on the top.

Is it possible to construct a solution with the existing API?

I tried following means, yet none can meet the need: (Point me a direction if I miss something.)

  • Insert to Accordion's Items slice: it'll crash due to, in my opinion, lack of access to perpertyLock protection, which is not exported
  • New Accordion with a StringList binding: NO such API found
  • Sort mechanism for Accordion: NO such API found

Describe the solution you'd like to see.

Correct me if I'm wrong:

  • add Prepend, or further Insert (more general) method to Accordion, similar to existing Append, which I think is the easiest
  • Export internal lock field
  • add data-binding style constructor to Accordion
  • add sort mechanism
@Jacalz Jacalz added the question A question has been asked label Jan 15, 2025
@Jacalz
Copy link
Member

Jacalz commented Jan 15, 2025

Please keep issues specific to a single request. Keeping track of lots of stuff in issues gets complicated quickly. I'll try to answer some of the things mentioned above.

add Prepend, or further Insert (more general) method to Accordion, similar to existing Append, which I think is the easiest

That can absolutely be a good idea API-wise but FYI, you can do all of this now using append() to the .Items field of the widget. The slices package in 1.21 has many ready-made APIs that you can use on top of that field: https://pkg.go.dev/slices. If you want to propose adding a new API for this in accordion, please open a separate feature request just for that.

Export internal lock field

As a rule of thumb, you should never export locks as public fields. That is dangerous. All of the locking should be handled internally inside the API. However, we are working on a new threading model and that will solve the synchronisation problems. See #4654.

add data-binding style constructor to Accordion

Feel free to open a separate feature request only about adding data binding to accordion.

add sort mechanism

You can easily sort the underlying items using something like slices.Sort or similar.

@Jacalz
Copy link
Member

Jacalz commented Jan 15, 2025

Closing this as it contains more than one feature request. As noted above, please open one feature request for each specific feature instead. Thanks.

@Jacalz Jacalz closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 2025
@JeffreyLeeLi
Copy link
Author

Thanks for quick and detailed reply.

As for the following, I wanna further help.

add Prepend, or further Insert (more general) method to Accordion, similar to existing Append, which I think is the easiest

That can absolutely be a good idea API-wise but FYI, you can do all of this now using append() to the .Items field of the widget. The slices package in 1.21 has many ready-made APIs that you can use on top of that field: https://pkg.go.dev/slices. If you want to propose adding a new API for this in accordion, please open a separate feature request just for that.

As I mentioned earlier, I tried to "Insert to Accordion's Items slice: it'll crash due to, in my opinion, lack of access to perpertyLock protection" with codeines:

	accordion.Append(widget.NewAccordionItem("a", obj))
	fmt.Println(len(accordion.Items), accordion.Items)
	accordion.Items = slices.Insert(accordion.Items, 0, item)
	fmt.Println(len(accordion.Items), accordion.Items)

new item is inserted as expected:

1 [0xc0039f6810]
2 [0xc0039f67e0 0xc0039f6810]

yet panic error follows:

panic: runtime error: index out of range [1] with length 1

goroutine 15 [running, locked to thread]:
fyne.io/fyne/v2/widget.(*accordionRenderer).MinSize(0xc006ef2500)
	/Users/jeffreyleeli/go/pkg/mod/fyne.io/fyne/[email protected]/widget/accordion.go:216 +0x1fc
fyne.io/fyne/v2/widget.(*BaseWidget).MinSize(0xc0001200e0?)
	/Users/jeffreyleeli/go/pkg/mod/fyne.io/fyne/[email protected]/widget/widget.go:79 +0x3f
fyne.io/fyne/v2/widget.(*Accordion).MinSize(0xc0001200e0)
	/Users/jeffreyleeli/go/pkg/mod/fyne.io/fyne/[email protected]/widget/accordion.go:73 +0x2f
fyne.io/fyne/v2/internal/widget.(*Scroll).MinSize(0xc0001503c0)
	/Users/jeffreyleeli/go/pkg/mod/fyne.io/fyne/[email protected]/internal/widget/scroller.go:465 +0x96
fyne.io/fyne/v2/layout.(*borderLayout).MinSize(0xc0003600c0, {0xc000360080?, 0x0?, 0x0?})
	/Users/jeffreyleeli/go/pkg/mod/fyne.io/fyne/[email protected]/layout/borderlayout.go:79 +0x174
fyne.io/fyne/v2.(*Container).MinSize(0x200000003?)
	/Users/jeffreyleeli/go/pkg/mod/fyne.io/fyne/[email protected]/container.go:90 +0x51
fyne.io/fyne/v2/internal/driver/glfw.(*glCanvas).MinSize(0xc000134000)
	/Users/jeffreyleeli/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/canvas.go:75 +0x90
fyne.io/fyne/v2/internal/driver/common.(*Canvas).EnsureMinSize(0xc000134000)
	/Users/jeffreyleeli/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/common/canvas.go:92 +0x8b
fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).repaintWindow.func1()
	/Users/jeffreyleeli/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/loop.go:210 +0x2b
fyne.io/fyne/v2/internal/driver/glfw.(*window).RunWithContext(0xc000102700, 0xc003a5fe58)
	/Users/jeffreyleeli/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/window.go:929 +0x43
fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).repaintWindow(0x0?, 0xc000283030?)
	/Users/jeffreyleeli/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/loop.go:209 +0x35
fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).drawSingleFrame(0xc0002fd520)
	/Users/jeffreyleeli/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/loop.go:95 +0x13f
fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).startDrawThread.func1()
	/Users/jeffreyleeli/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/loop.go:263 +0x1f4
created by fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).startDrawThread in goroutine 1
	/Users/jeffreyleeli/go/pkg/mod/fyne.io/fyne/[email protected]/internal/driver/glfw/loop.go:241 +0xbb
exit status 2

Could you please drop me a hint how to avoid above error?

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question has been asked
Projects
None yet
Development

No branches or pull requests

2 participants