Skip to content
gucio321 edited this page Jul 10, 2024 · 17 revisions

Frequently Asked Questions

In this chapter you find many issues, new users may face with.

Work in progress! Feel free to post any suggestions in this issue

Master Window

Q: What is Master Window (giu.MasterWindow)?
A: Master Window is a native application window in you OS.This is hosted (currently) by GLFW. Master window is a workspace for imgui windows created by giu.


Q: Is there a way to open two (or more) Master Windows?
A: No. Current implementation does not allow to have more than one native windows in paralel. You can however have many imgui windows.


Q: What is Run function?
A: It is the most important method of "MasterWindow". You use this to specify, which function should be treated as loop function.


Q: So what is the loop function?
A: This function is responsible for doing everything about imgui. Its may task is to draw widgets that will be visible in MasterWindow. For more details, refer to examples


Q: How to close Master Window from code?
A: There is (*MasterWindow).Close() method. You can also use (*MasterWindow).SetShouldClose(true)


Q: How to use (*MasterWindow).SetCloseCallback?
A: Use it before calling Run. func() bool argument, is a callback called, whnever window needs to be closed (by user of via SetShouldClose). Return value of this callback says, whether the window really should be closed. If false is returned, window remains opened.


Q: My app is refreshed only when I move my mouse or type something, so my constantly changing Widgets doesn't work
A: Giu implements Power Saving Mode. UI is not re-rendered if no event happens. To baypass this, you need to call giu.Update() whenever you want to redraw UI.


Windows

Q: What is a Window?
A: Window is a place where widgets are actually rendered. Windows are placed inside of MasterWindow.


Q: What are the types of Windows?
A: Dear ImGui has 3 types of windows:

  • Window - couldb be moved around workspace. You can have as many Windows as you wish.
  • Popup - is a special kind of window. It appears only when some specified action happens (e.g. Tooltip)
  • Popup Modal - when this window appears, everything else becomes grayed as long as it is open. (e.g. Yes/No dialog)

GIU separates one more window type:

  • Single Window - covers whole workspace. May be used as an alternative to many Windows in simple apps.

Q: How to use popups? I can't open them anyhow...
A: Generally poups are being refactored. Some useful information you can find in this issue. Especially, the code here describes a nice in use wrapper for cimgui-go popups system.


General/Widgets

Q: What is Widget?
A: Widget is a single unit of GIU system. It usually represens a single item (like button, text field) or some more complex structure (like SplitLayout or Date Picker) Refer to wiki.


Q: What is Layout?
A: Layout is a group of Widgets. Technically it is a widget too.


Q: How to handle double-click event on any widget?
A: To do this, you simply need to use EventHandler

giu.Button("Double-click me"),
giu.Event().OnDClick(giu.MouseButtonLeft, func() {fmt.Println("I was double clicked!")}),

Q: Is it possible to wrap text in the InputTextMultilineWidget?
A: Unfortunately, there is no such a way implemented in giu yet. However there is a code written by @rasteric postend here. You can implement it in your project!


Q: Whats the difference between MenuBar and MainMenuBar?
A: You use MainMenuBar with a standard setup when you use multiple WindowWidgets. However if you use SingleWindow and you want a menubar, you should use SingleWiowWithMenuBar and MenuBar.

Check out this code
package main

import "github.com/AllenDang/giu"

var singleWindow bool

func menubarLayout() giu.Widget {
	return giu.Layout{
		giu.Menu("File").Layout(
			giu.MenuItem("Save"),
		),
	}
}

func loop() {
	if singleWindow {
		giu.SingleWindowWithMenuBar().Layout(
			giu.MenuBar().Layout(menubarLayout()),
			giu.Checkbox("Show single window", &singleWindow),
		)
	} else {
		giu.MainMenuBar().Layout(
			menubarLayout(),
		).Build()
		giu.Window("Window 1").Layout(
			giu.Label("I am a window 1"),
		)
		giu.Window("Window 2").Layout(
			giu.Label("I am a window 2"),
			giu.Checkbox("Show single window", &singleWindow),
		)
	}
}

func main() {
	wnd := giu.NewMasterWindow("Menubar usage", 640, 480, 0)
	wnd.Run(loop)
}

Q: CustomWidget inside of RowWidget?
A: Generally, you should avoid using CustomWidget as long as you can, especially inside of RowWidget.

Reason for that is, that our Layout system has no control over what happens inside of the CustomWidget.

What you need to know about RowWidget is that this widget is only a wrap for imgui.SameLine call after each widget inside it. The opposite to imgui.SameLine is imgui.NewLine which you can use to undo the effect of imgui.SameLine if you really need it. Here is an issue about RowWidget


Clone this wiki locally