Image menu
Hi Is it possible to attach menu to an image button?
`
g.MenuBar().Layout(
g.Menu("File").Layout(g.MenuItem(...)),
g.ImageButton(...). // ---> how to attach a g.Menu(...) to this?
....
`
Thanks Jasmeer
@jasmeer could you tell more about what are going to achive?
e.g., do you want to have a main menu bar with File and some image element next to it?
@gucio321 Thank you for the reply.
What I want is to main menu bar with icons. In the File example, can I cannot use an icon, i have to use a string. I can use ImageButton; then I don't know how to attach a Menu to it.
Thx
hmm, it is kind of difficult thing as imgui doesn't suppor that by default (as far as I know :smile: ) BUT, I'd try
- create dropdown (probably combo custom widget)
- set an image widget as a preview value
- in dropdown's layout put list of selectable widgets it probably will do what you're looking for
well, it'll not work - unfortunately ComboCustomWidget doesn't support "custom" preview value - only strings
ok, @jasmeer it isn't exactly what you're looking for but it could be a nice workaround
package main
import (
"fmt"
"image"
"github.com/AllenDang/giu"
)
var img *image.RGBA
func loop() {
giu.Window("my window").Layout(
giu.MainMenuBar().Layout(
giu.ImageWithRgba(img).Size(80, 20),
giu.ContextMenu().MouseButton(giu.MouseButtonLeft).Layout(
giu.Selectable("option1").OnClick(func() { fmt.Println("I was clicked!") }),
),
),
)
}
func main() {
img, _ = giu.LoadImage("gopher.png")
giu.NewMasterWindow("issue 474 [example 1]", 640, 480, 0).Run(loop)
}
(remember to put file named gopher.png in the same directory with go file)
@gucio321 It works. I modified it to use MenuItems.
One small issue - menu appears to the right of the image. How do i remove this x offset? I
@jasmeer thats exactly the problemm with context menu; it gets opened over mouse cursor rather than over widget.
@gucio321 Thanks. I am using Font Awesome ICON fonts and it is working. I want to use large ICONs; but there is not room in MenuBar. Is it possible to increase the height?
Thanks Jasmeer
@jasmeer sure, check (*StyleSetter).SetFontSize it allows you to set font size in any item
The only point here is, that font size stuff is currently bugged (see #479 )
so if you want to play with that, you need to execute command like that:
go mod edit -replace github.com/AllenDang/giu=github.com/gucio321/giu@02e72d9237d62767afa1637e6189aeffd2e50b47
@jasmeer does this work?
@gucio321 Is this feature merged in @v0.6.2 ?
Thanks
@jasmeer yep, as far as I see, it is part of v0.6.2.
@gucio321 It doesn't work. Font size does increase, but the menubar height doesn't change; in effect a portion of the text is outside the bar.
giu.SingleWindowWithMenuBar().Layout( giu.Style().SetFontSize(30).To( giu.MenuBar().Layout( giu.Menu("File").Layout(giu.MenuItem("menu")))),
Thanks
Jasmeer
I think it is not issue on giu-side since I don't thing this feature is available in Dear ImGui itself