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

Support binding Go objects to GObjects with GObject.set_qdata #117

Open
diamondburned opened this issue Nov 10, 2023 · 0 comments
Open

Support binding Go objects to GObjects with GObject.set_qdata #117

diamondburned opened this issue Nov 10, 2023 · 0 comments

Comments

@diamondburned
Copy link
Owner

GObject.set_qdata_full is an incredibly useful that allows users to bind any arbitrary pointer to a GObject that can be destroyed later on. We can use this to allow users to bind a Go object of any type to a GObject.

Proposed API:

type ObjectDataType[T any] struct{ quark C.GQuark }

func NewObjectDataType[T any]() ObjectDataType[T]
func (d ObjectDataType[T]) SetForObject(obj glib.Objector, T)
func (d ObjectDataType[T]) FromObject(obj glib.Objector) T
func (d ObjectDataType[T]) IsInObject(obj glib.Objector) bool

Usage:

var rowID = glib.NewObjectDataType[discord.MessageID]()

func(id discord.MessageID) {
  row := gtk.NewListBoxRow()
  row.AddCSSClass("message-row")
  row.ConnectSignalX(func() {
    messageID := rowID.FromObject(row)
    // use messageID as normal without needing id!
  })

  rowID.SetForObject(row, id)
}(id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant