diamondburned/gotk4

Widgets not usable as Widgetter: FontButton and MenuButton

Closed this issue · 3 comments

sqp commented

Hey, I'm working on a gallery example for the package and (so far only) found 2 widgets that weren't usable as Widgetter, so they can't be inserted into a GUI.
And a big "gg wp" for that lib, it almost feels like an old used one.

gtk.FontButton.FontMap is ambiguous
cannot use btn (type *gtk.FontButton) as type gtk.Widgetter in argument to toBox:
*gtk.FontButton does not implement gtk.Widgetter (missing FontMap method)

cannot use btn (type *gtk.MenuButton) as type gtk.Widgetter in argument to toBox:
*gtk.MenuButton does not implement gtk.Widgetter (wrong type for Direction method)
have Direction() gtk.ArrowType
want Direction() gtk.TextDirection

gtk4-gallery

For some widgets, you might need to explicitly reference the field, such as with
adw.Avatar:

box.Append(&adw.Widget)

There's not really a way around this other than to autogenerate more fields into
the class struct. In fact, this is already done with classes that potentially
yield ambiguous selectors for glib.Objector:

type Widget struct {
	externglib.InitiallyUnowned

	Accessible
	Buildable
	ConstraintTarget
	*externglib.Object // extra field
}

Having to do this for all possible interfaces is a lot of work and potentially a
lot of unnecessary overhead, though, so I've decided not to go all the way.

gopls should suggest you the right selector when you try to plug the widget
in.

sqp commented

For the gtk.MenuButton the name conflict could be resolved by renaming :

  • Direction -> MenuDirection
  • SetDirection -> SetMenuDirection
    (or Arrow instead of Menu as the argument is an ArrowType but I think a MenuDirection method is fine for a MenuButton)

It would be easier to have the widget behave like the others and be usable directly as Widgetter.

Their documentation:

Direction returns the direction the popup will be pointing at when popped up.

SetDirection sets the direction in which the popup will be popped up.
If the button is automatically populated with an arrow icon, its direction will be changed to match.
If the does not fit in the available space in the given direction, GTK will its best to keep it inside the screen and fully visible.
If you pass GTK_ARROW_NONE for a direction, the popup will behave as if you passed GTK_ARROW_DOWN (although you won’t see any arrows).

Created issue #36 to trackthe
MenuButton changes.