Hi, I’ve a problem with GOTK4. You can find the question on StackOverflow, and if possible, I would prefer you answer on it.
I use github.com/diamondburned/gotk4/pkg/gtk/v4. I’d like to create a modal dialog, like this:
dialog := gtk.NewMessageDialog(
&window.Window,
gtk.DialogModal|gtk.DialogDestroyWithParent,
gtk.MessageInfo,
gtk.ButtonsOK,
"Some info I want to let the user know",
)
dialog.SetTitle("Information")
dialog.SetVisible(true)
Only, NewMessageDialog() is declared like this:
func gtk.NewMessageDialog(parent *gtk.Window, flags gtk.DialogFlags, typ gtk.MessageType, buttons gtk.ButtonsType) *gtk.MessageDialog
Unkike the C function gtk_message_dialog_new(), the Go one doesn’t have the message_format argument, nor the ... (parameters for message_format) one.
My question is: How to create a information dialog in Go, with just a title, a body and one button?
You could try setting the MessageDialog’s text property.
This is completely untested. I’m just going from gtk and gobject documentation, along with gotk4 docs on pkg.go.dev.
dialog := gtk.NewMessageDialog(
&window.Window,
gtk.DialogModal|gtk.DialogDestroyWithParent,
gtk.MessageInfo,
gtk.ButtonsOK,
)
var textValue glib.Value
textValue.InitValue(glib.TypeString)
textValue.SetString("Some info I want to let the user know")
dialog.SetObjectProperty("text", textValue)
Your solution also works, but I prefer the @Vio’s one, for these reasons:
His own does not use SetObjectProperty(), that I keep for cases where I can’t do otherwise.
Your one contains an error: I must not create a nil *glib.Value, then set it a type and a value (by the way, the InitValue doesn’t exists), I just have to run glib.NewValue("...") and it automatically infers type.