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

Image menu #474

Open
jasmeer opened this issue Mar 4, 2022 · 14 comments
Open

Image menu #474

jasmeer opened this issue Mar 4, 2022 · 14 comments
Labels
External Issue Issue in dependencies - can't make progress in giu yet. question Further information is requested

Comments

@jasmeer
Copy link

jasmeer commented Mar 4, 2022

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

@gucio321
Copy link
Collaborator

gucio321 commented Mar 6, 2022

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

@jasmeer
Copy link
Author

jasmeer commented Mar 6, 2022

@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

@gucio321
Copy link
Collaborator

gucio321 commented Mar 6, 2022

hmm, it is kind of difficult thing as imgui doesn't suppor that by default (as far as I know 😄 )
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
Copy link
Collaborator

gucio321 commented Mar 6, 2022

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

@gucio321
Copy link
Collaborator

gucio321 commented Mar 6, 2022

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)

@jasmeer
Copy link
Author

jasmeer commented Mar 6, 2022

@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 jasmeer closed this as completed Mar 6, 2022
@jasmeer jasmeer reopened this Mar 6, 2022
@gucio321
Copy link
Collaborator

gucio321 commented Mar 7, 2022

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

@jasmeer
Copy link
Author

jasmeer commented Mar 19, 2022

@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

@gucio321
Copy link
Collaborator

@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
Copy link
Collaborator

gucio321 commented May 8, 2022

@jasmeer does this work?

@jasmeer
Copy link
Author

jasmeer commented May 12, 2022

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

Thanks

@gucio321
Copy link
Collaborator

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

@jasmeer
Copy link
Author

jasmeer commented May 13, 2022

@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

@gucio321 gucio321 added the question Further information is requested label May 9, 2023
@gucio321
Copy link
Collaborator

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

@gucio321 gucio321 added the External Issue Issue in dependencies - can't make progress in giu yet. label May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External Issue Issue in dependencies - can't make progress in giu yet. question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants