giu icon indicating copy to clipboard operation
giu copied to clipboard

Image menu

Open jasmeer opened this issue 3 years ago • 14 comments

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 avatar Mar 04 '22 23:03 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 avatar Mar 06 '22 18:03 gucio321

@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

jasmeer avatar Mar 06 '22 19:03 jasmeer

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

gucio321 avatar Mar 06 '22 20:03 gucio321

well, it'll not work - unfortunately ComboCustomWidget doesn't support "custom" preview value - only strings

gucio321 avatar Mar 06 '22 20:03 gucio321

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 avatar Mar 06 '22 20:03 gucio321

@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

image

jasmeer avatar Mar 06 '22 20:03 jasmeer

@jasmeer thats exactly the problemm with context menu; it gets opened over mouse cursor rather than over widget.

gucio321 avatar Mar 07 '22 07:03 gucio321

@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?

image

Thanks Jasmeer

jasmeer avatar Mar 19 '22 21:03 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

gucio321 avatar Mar 20 '22 10:03 gucio321

@jasmeer does this work?

gucio321 avatar May 08 '22 10:05 gucio321

@gucio321 Is this feature merged in @v0.6.2 ?

Thanks

jasmeer avatar May 12 '22 13:05 jasmeer

@jasmeer yep, as far as I see, it is part of v0.6.2.

gucio321 avatar May 12 '22 14:05 gucio321

@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.

image

giu.SingleWindowWithMenuBar().Layout( giu.Style().SetFontSize(30).To( giu.MenuBar().Layout( giu.Menu("File").Layout(giu.MenuItem("menu")))), Thanks Jasmeer

jasmeer avatar May 13 '22 15:05 jasmeer

I think it is not issue on giu-side since I don't thing this feature is available in Dear ImGui itself

gucio321 avatar May 10 '23 15:05 gucio321