### Main Application Window Setup Source: https://github.com/allendang/giu/wiki/FAQ Initializes the main application window with a title, dimensions, and flags, then runs the main loop. ```go func main() { giu.NewMasterWindow("Cats example [state, custom widet].", 800, 600, 0).Run(loop) } ``` -------------------------------- ### Install Mingw-w64 on Fedora/RHEL/CentOS Source: https://github.com/allendang/giu/blob/master/README.md Installs mingw-w64 GCC toolchain and winpthreads for cross-compiling to Windows. ```bash sudo dnf install mingw64-gcc mingw64-gcc-c++ mingw64-winpthreads-static ``` -------------------------------- ### Hello World GUI in Go Source: https://github.com/allendang/giu/blob/master/README.md Basic 'Hello World' example demonstrating window creation, layout, and button click handlers. Requires importing the 'giu' package. ```go package main import ( "fmt" g "github.com/AllenDang/giu" ) func onClickMe() { fmt.Println("Hello world!") } func onImSoCute() { fmt.Println("Im sooooooo cute!!") } func loop() { g.SingleWindow().Layout( g.Label("Hello world from giu"), g.Row( g.Button("Click Me").OnClick(onClickMe), g.Button("I'm so cute").OnClick(onImSoCute), ), ) } func main() { wnd := g.NewMasterWindow("Hello world", 400, 200, g.MasterWindowFlagsNotResizable) wnd.Run(loop) } ``` -------------------------------- ### Install Giu on Windows Source: https://github.com/allendang/giu/blob/master/README.md Installs the giu library on Windows. Requires MinGW-w64 and adding its binaries to the system PATH. ```sh go get github.com/AllenDang/giu ``` -------------------------------- ### Build a Widget Layout Source: https://github.com/allendang/giu/wiki/FAQ Illustrates how to define the UI structure for a widget using `giu.Layout`. This example includes a label and a text input field for the cat's name. ```go func (c *CatWidget) Build() { state := c.getState() giu.Layout{ giu.Label("The name of the cat is:"), giu.InputText(&state.catName), }.Build() } ``` -------------------------------- ### Full Custom Widget Implementation with State Management Source: https://github.com/allendang/giu/wiki/FAQ A comprehensive example of a custom widget (`CatWidget`) including state management (`catState`), ID generation, default name setting, and the `Build` method for UI layout. It also shows how to manage state using `giu.GetState` and `giu.Context.SetState`. ```go package main import ( "github.com/AllenDang/giu" ) type catState struct { catName string } func (c *catState) Dispose() { // nothing to do here } func (w *CatWidget) getState() *catState { if s := giu.GetState[catState](giu.Context, w.stateID()); s != nil { return s } newState := w.newState() giu.Context.SetState(w.stateID(), newState) return w.getState() } func (w *CatWidget) newState() *catState { return &catState{ catName: w.defaultName, } } func (w *CatWidget) stateID() giu.ID { return w.id } type CatWidget struct { id giu.ID // this should be unique for each cat defaultName string } func Cat() *CatWidget { return &CatWidget{ id: giu.GenAutoID("cat"), // this guarants an unique value } } func (w *CatWidget) ID(id giu.ID) *CatWidget { w.id = id return w } func (w *CatWidget) DefaultName(name string) *CatWidget { w.defaultName = name return w } func (c *CatWidget) Build() { state := c.getState() giu.Layout{ giu.Label("The name of the cat is:"), giu.InputText(&state.catName), }.Build() } func loop() { giu.SingleWindow().Layout( Cat().DefaultName("Luna"), Cat(), Cat(), ) } func main() { giu.NewMasterWindow("Cats example [state, custom widet].", 800, 600, 0).Run(loop) } ``` -------------------------------- ### Install Mingw-w64 on Mac for Windows Cross-compilation Source: https://github.com/allendang/giu/blob/master/README.md Installs mingw-w64 using Homebrew for cross-compiling to Windows from macOS. ```sh brew install mingw-w64 ``` -------------------------------- ### Install Giu on macOS Source: https://github.com/allendang/giu/blob/master/README.md Installs the giu library on macOS. Ensure Xcode command line tools are installed. ```sh xcode-select --install go get github.com/AllenDang/giu ``` -------------------------------- ### Build Windows Executable from Linux Source: https://github.com/allendang/giu/wiki/Home Build a Windows executable on Linux using Go. This command uses mingw64 cross-compiler. Ensure mingw64 gcc and g++ are installed. ```bash GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC="x86_64-w64-mingw32-gcc" CXX="x86_64-w64-mingw32-g++" go build -o YourExeName.exe ``` -------------------------------- ### Install Mingw-w64 on Arch Linux Source: https://github.com/allendang/giu/blob/master/README.md Installs the mingw-w64 GCC toolchain for cross-compiling to Windows on Arch Linux. ```bash pacman -Sy mingw-w64-gcc ``` -------------------------------- ### Install Giu Dependencies on Debian/Ubuntu Source: https://github.com/allendang/giu/blob/master/README.md Installs necessary development libraries for giu on Debian-based Linux distributions. ```bash sudo apt install libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libglx-dev libgl1-mesa-dev libxxf86vm-dev ``` -------------------------------- ### CSS Styling Example Source: https://github.com/allendang/giu/blob/master/docs/css.md Demonstrates how to apply various CSS properties like color, background-color, alpha, and item-spacing to a 'main' element. Supports named colors, rgb/rgba, hsl/hsla, hwb/hwba, and hsv/hsva color formats. Float values are plain numbers, and Vec2 values are pairs of numbers. ```css main { color: rgba(50, 100, 150, 255); background-color: yellow; alpha: 100; item-spacing: 80, 20; } ``` -------------------------------- ### Install Giu Dependencies on Fedora/Red Hat/CentOS Source: https://github.com/allendang/giu/blob/master/README.md Installs necessary development libraries for giu on Fedora-based Linux distributions. ```bash sudo dnf install libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel libXi-devel libGL-devel libXxf86vm-devel ``` -------------------------------- ### Install Giu Dependencies on Arch Linux Source: https://github.com/allendang/giu/blob/master/README.md Installs the glfw library for giu on Arch Linux. A C/C++ compiler may also be needed. ```bash sudo pacman -Sy glfw ``` -------------------------------- ### Cross-compiling Giu for Linux ARM64 Source: https://github.com/allendang/giu/blob/master/README.md Builds a giu application for Linux ARM64. Requires installing cross-compilation toolchains and dependencies. ```bash sudo dpkg --add-architecture arm64 sudo apt update sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libx11-dev:arm64 libxcursor-dev:arm64 libxrandr-dev:arm64 libxinerama-dev:arm64 libxi-dev:arm64 libglx-dev:arm64 libgl1-mesa-dev:arm64 libxxf86vm-dev:arm64 GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ HOST=aarch64-linux-gnu go build -v ``` -------------------------------- ### Render Custom Widgets with Direct imgui Calls Source: https://context7.com/allendang/giu/llms.txt Use the Custom widget to wrap any function, enabling direct imgui/OpenGL calls or complex stateful logic inline within the layout. This example shows how to make a direct imgui API call to render colored text. ```go import "github.com/AllenDang/cimgui-go/imgui" func loop() { g.SingleWindow().Layout( g.Custom(func() { // Direct imgui API call imgui.TextColored(imgui.Vec4{X: 1, Y: 0.5, Z: 0, W: 1}, "Orange text via raw imgui") }), g.Label("Normal label below custom widget"), ) } ``` -------------------------------- ### Prepare and Build Windows Executable with Icon Source: https://github.com/allendang/giu/blob/master/README.md Creates a Windows resource file for the application icon and then builds the Windows executable with static linking and GUI flags. ```sh cat > YourExeName.rc << EOL id ICON "./res/app_win.ico" GLFW_ICON ICON "./res/app_win.ico" EOL x86_64-w64-mingw32-windres YourExeName.rc -O coff -o YourExeName.syso GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ HOST=x86_64-w64-mingw32 go build -ldflags "-s -w -H=windowsgui -extldflags=-static" -p 4 -v -o YourExeName.exe rm YourExeName.syso rm YourExeName.rc ``` -------------------------------- ### Create and Run MasterWindow in giu Source: https://context7.com/allendang/giu/llms.txt Initializes GLFW, ImGui, and ImPlot. Configure window properties like size, flags, and callbacks before running the main loop. ```go package main import ( g "github.com/AllenDang/giu" "golang.org/x/image/colornames" ) func loop() { g.SingleWindow().Layout( g.Label("Hello, giu!"), ) } func main() { wnd := g.NewMasterWindow("My App", 800, 600, g.MasterWindowFlagsNotResizable) wnd.SetBgColor(colornames.Darkslategray) wnd.SetTargetFPS(60) wnd.SetTitle("My App v1.0") wnd.SetDropCallback(func(files []string) { // handle drag-and-drop }) wnd.SetCloseCallback(func() bool { return true // allow close }) wnd.Run(loop) } ``` -------------------------------- ### Build Application MenuBar Source: https://context7.com/allendang/giu/llms.txt Construct an application menu bar with File, Edit, and Help menus, including menu items with shortcuts and actions. ```go func loop() { g.MainMenuBar().Layout( g.Menu("File").Layout( g.MenuItem("New").Shortcut("Ctrl+N").OnClick(func() { /* new */ }), g.MenuItem("Open").Shortcut("Ctrl+O").OnClick(func() { /* open */ }), g.MenuItem("Save").Shortcut("Ctrl+S").OnClick(func() { /* save */ }), g.Separator(), g.MenuItem("Exit").OnClick(func() { /* exit */ }), ), g.Menu("Edit").Layout( g.MenuItem("Undo").Shortcut("Ctrl+Z"), g.MenuItem("Redo").Shortcut("Ctrl+Y"), ), g.Menu("Help").Enabled(true).Layout( g.MenuItem("About"), ), ) g.SingleWindow().Layout( g.Label("App content here"), ) } ``` -------------------------------- ### Build Windows Executable from Linux with Zig Source: https://github.com/allendang/giu/wiki/Home Alternative method to build a Windows executable on Linux using Go and Zig's C toolchain. This approach bypasses the need for mingw64. ```bash GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC="zig cc -target x86_64-windows" CXX="zig c++ -target x86_64-windows" go build -o YourExeName.exe ``` -------------------------------- ### State Management with Context.GetState and Context.SetState Source: https://github.com/allendang/giu/wiki/FAQ Illustrates how to use the state system for managing widget data across frames. It involves creating a state struct, using unique IDs, and employing Context.GetState and Context.SetState. ```go type catState struct { catName string } func (c *catState) Dispose() { // nothing to do here } ``` ```go func (w *CatWidget) getState() *catState { if s := giu.GetState[catState](giu.Context, w.stateID()); s != nil { return s } newState := w.newState() giu.SetState(giu.Context, w.stateID(), newState) return w.getState() } func (w *CatWidget) newState() *catState { return &catState{ // initialize here } } func (w *CatWidget) stateID() giu.ID { return w.id } ``` -------------------------------- ### Create Widgets from a Loop using RangeBuilder Source: https://github.com/allendang/giu/wiki/Home Demonstrates how to dynamically create multiple widgets from a slice using `giu.RangeBuilder`. ```go layout := g.Layout{ g.RangeBuilder("Buttons", []interface{}{"Button1", "Button2", "Button3"}, func(i int, v interface{}) g.Widget { str := v.(string) return g.Button(str, func() { fmt.Println(str, "is clicked") }) }) } ``` -------------------------------- ### Checkbox, RadioButton, Selectable Widgets Source: https://context7.com/allendang/giu/llms.txt Demonstrates the usage of Checkbox, RadioButton, and Selectable widgets. State is managed externally via boolean or integer pointers. Radio buttons require manual state management. ```go var ( checkA = true checkB = false choice = int32(0) ) func loop() { g.SingleWindow().Layout( g.Checkbox("Enable feature A", &checkA).OnChange(func() { // triggered when toggled }), g.Checkbox("Enable feature B", &checkB), g.Separator(), // Radio buttons — manually manage the int g.RadioButton("Option 1", choice == 0).OnChange(func() { choice = 0 }), g.RadioButton("Option 2", choice == 1).OnChange(func() { choice = 1 }), g.RadioButton("Option 3", choice == 2).OnChange(func() { choice = 2 }), g.Separator(), // Selectable — highlighted list item g.Selectable("File.txt").Selected(true).OnClick(func() { /* open */ }), g.Selectable("Image.png").Selected(false).OnClick(func() { /* open */ }), ) } ``` -------------------------------- ### Handle Widget Events (Hover, Double Click) Source: https://github.com/allendang/giu/wiki/Home Shows how to attach event handlers like hover and double-click to a widget by placing `giu.Event()` immediately after it. ```go // Create a button giu.Button("Click Me") // Place the event handling APIs right after the button to capture key/mouse events. giu.Event().OnHover(func() { // Do event handling here. }).OnDoubleClick(func() { fmt.Println("Double cicked") }) ``` -------------------------------- ### SingleWindow and Window UI Containers in giu Source: https://context7.com/allendang/giu/llms.txt Use SingleWindow for full-screen content or Window for floating sub-windows. Both use a Layout function to define their content. ```go func loop() { // A full-screen content area — no title bar, no resize g.SingleWindow().Layout( g.Label("Full screen content"), ) // A floating, resizable sub-window isOpen := true g.Window("Settings"). IsOpen(&isOpen). Size(400, 300). Pos(50, 50). Flags(g.WindowFlagsNoCollapse). Layout( g.Label("Settings panel"), ) } ``` -------------------------------- ### Display Images from Various Sources in Giu Source: https://context7.com/allendang/giu/llms.txt Use ImageWithFile for local files, ImageWithRgba for Go image.Image types, and ImageWithURL for asynchronous loading from web URLs. ImageWithURL supports loading, error, and ready states. ```go import ( "image" _ "image/png" "os" "time" g "github.com/AllenDang/giu" ) func loop() { g.SingleWindow().Layout( // From a file path (not portable — use embed instead) g.ImageWithFile("assets/logo.png").Size(128, 128), // From an image.Image (e.g. loaded/generated in Go) // img, _ := loadMyImage() // g.ImageWithRgba(img).Size(200, 200).OnClick(func() { /* ... */ }), // From a URL (async, shows placeholder while loading) g.ImageWithURL("https://example.com/photo.jpg"). Size(200, 150). Timeout(5*time.Second). LayoutForLoading(g.Label("Loading...")). LayoutForFailure(g.Label("Failed to load")), ) } ``` -------------------------------- ### Combo and ComboCustom Dropdown Selectors Source: https://context7.com/allendang/giu/llms.txt Shows how to create dropdown selectors using Combo for string lists and ComboCustom for custom widget layouts. The standard Combo includes fuzzy filtering. ```go var ( items = []string{"Apple", "Banana", "Cherry", "Date"} selected = int32(0) ) func loop() { g.SingleWindow().Layout( // Standard string-list combo with fuzzy filter g.Combo("Fruit", items[selected], items, &selected). Filter(true). Size(200). OnChange(func() { /* selection changed */ }), g.Labelf("Selected: %s", items[selected]), g.Separator(), // Custom combo with arbitrary widget layout inside g.ComboCustom("Custom", "Choose..."). Size(200). Layout( g.Label("Custom dropdown content"), g.Button("Action").OnClick(func() { /* ... */ }), g.Selectable("Option A"), g.Selectable("Option B"), ), ) } ``` -------------------------------- ### TabBar and TabItem for Tabbed Panels Source: https://context7.com/allendang/giu/llms.txt Shows how to implement tabbed interfaces using TabBar and TabItem. Each TabItem can contain its own layout and widgets, with an option to control its open state. ```go var activeTab bool func loop() { g.SingleWindow().Layout( g.TabBar().TabItems( g.TabItem("Overview").Layout( g.Label("Overview content"), ), g.TabItem("Details").Layout( g.Label("Details content"), g.InputText(&name).Label("Name"), ), g.TabItem("Logs").IsOpen(&activeTab).Layout( g.InputTextMultiline(&logs).Size(g.Auto, g.Auto), ), ), ) } ``` -------------------------------- ### Create ContextMenu with MenuItems Source: https://context7.com/allendang/giu/llms.txt Define a context menu with various options like copy, paste, and delete. Activates on right-click. ```go func loop() { g.SingleWindow().Layout( g.Label("Right-click me"), g.ContextMenu().Layout( g.MenuItem("Copy").OnClick(func() { /* copy */ }), g.MenuItem("Paste").OnClick(func() { /* paste */ }), g.Separator(), g.MenuItem("Delete").OnClick(func() { /* delete */ }), ), g.Button("Right-click this button"), g.ContextMenu(). MouseButton(g.MouseButtonRight). Layout( g.MenuItem("Button Action"), ), ) } ``` -------------------------------- ### Register Global and Local Keyboard Shortcuts Source: https://context7.com/allendang/giu/llms.txt Register global shortcuts on the MasterWindow and local shortcuts on a specific Window that are active only when the window is focused. Callbacks are executed when shortcuts are triggered. ```go func main() { wnd := g.NewMasterWindow("Shortcuts Demo", 800, 600, 0) wnd.RegisterKeyboardShortcuts( g.WindowShortcut{ Key: g.KeyS, Modifier: g.ModControl, Callback: func() { /* Ctrl+S: save */ }, }, g.WindowShortcut{ Key: g.KeyQ, Modifier: g.ModControl, Callback: func() { wnd.Close() }, }, ) wnd.Run(func() { g.Window("Editor"). RegisterKeyboardShortcuts( g.WindowShortcut{ Key: g.KeyZ, Modifier: g.ModControl, Callback: func() { /* local undo */ }, }, ). Layout( g.Label("Press Ctrl+S to save, Ctrl+Q to quit"), ) }) } ``` -------------------------------- ### Build Application for Windows Source: https://github.com/allendang/giu/blob/master/README.md Compiles the application for Windows, creating a GUI application without a console window and statically linking libraries. ```sh go build -ldflags "-s -w -H=windowsgui -extldflags=-static" . ``` -------------------------------- ### Create a Custom Widget with Unique ID Source: https://github.com/allendang/giu/wiki/FAQ Demonstrates how to create a custom widget, `CatWidget`, ensuring each instance has a unique ID using `giu.GenAutoID`. This is crucial for state management. ```go type CatWidget struct { id giu.ID // this should be unique for each cat } func Cat() *CatWidget { return &CatWidget{ id: giu.GenAutoID("cat"), // this guarants an unique value } } ``` -------------------------------- ### Label, BulletText, Link Widgets Source: https://context7.com/allendang/giu/llms.txt Shows how to use Label, BulletText, and Link widgets for displaying text and hyperlinks. Labels support wrapping and formatted strings, while BulletText adds a bullet point. ```go func loop() { g.SingleWindow().Layout( g.Label("Plain label"), g.Label("Wrapped long text that will wrap automatically").Wrapped(true), g.Labelf("Value = %d, Float = %.2f", 42, 3.14), g.Separator(), g.BulletText("First item"), g.BulletTextf("Dynamic item: %s", "hello"), g.Separator(), g.Link("Visit GitHub").OnClick(func() { // open browser }), ) } ``` -------------------------------- ### Create and Populate Data Tables in Giu Source: https://context7.com/allendang/giu/llms.txt Render scrollable, resizable, and sortable tables using the Table widget. Rows are defined by TableRow, and columns by TableColumn. Data can be sorted programmatically. ```go type person struct{ name, city string; age int } var data = []person{ {"Alice", "New York", 30}, {"Bob", "London", 25}, {"Carol", "Tokyo", 35}, } func loop() { ows := make([]*g.TableRowWidget, len(data)) for i, p := range data { ows[i] = g.TableRow( g.Label(p.name), g.Labelf("%d", p.age), g.Label(p.city), ) } g.SingleWindow().Layout( g.Table(). Size(g.Auto, 200). Flags(g.TableFlagsBorders|g.TableFlagsResizable|g.TableFlagsScrollY|g.TableFlagsSortable). Columns( g.TableColumn("Name").Flags(g.TableColumnFlagsDefaultSort).Sort(func(dir g.SortDirection) { if dir == g.SortAscending { // sort data ascending } }), g.TableColumn("Age"), g.TableColumn("City") ). Rows(rows...), ) } ``` -------------------------------- ### ProgressBar for Progress Indication Source: https://context7.com/allendang/giu/llms.txt Demonstrates the ProgressBar widget for indicating progress. It can be used with default sizing or with custom dimensions and overlay text. ```go var progress = float32(0.65) func loop() { g.SingleWindow().Layout( // Default size bar g.ProgressBar(progress), // Sized bar with overlay text g.ProgressBar(progress). Size(300, 20). Overlayf("%.0f%%", progress*100), ) } ``` -------------------------------- ### Programmatic Styling with Giu StyleSetter Source: https://context7.com/allendang/giu/llms.txt Apply styles like colors, frame rounding, and font sizes to groups of widgets using Style().To(...). This allows for dynamic styling of UI elements. ```go import ( g "github.com/AllenDang/giu" "golang.org/x/image/colornames" ) func loop() { g.SingleWindow().Layout( // Apply a style to specific widgets g.Style(). SetColor(g.StyleColorButton, colornames.Steelblue). SetColor(g.StyleColorButtonHovered, colornames.Deepskyblue). SetStyleFloat(g.StyleVarFrameRounding, 6). SetDisabled(false). To( g.Button("Styled Button").Size(150, 35), g.Button("Another Styled").Size(150, 35), ), // Change font size for a label g.Style(). SetFontSize(22). To( g.Label("Big label"), ), ) } ``` -------------------------------- ### Input Widgets for Text and Numbers Source: https://context7.com/allendang/giu/llms.txt Demonstrates various input widgets including InputText, InputTextMultiline, InputInt, and InputFloat. These widgets bind to external variables and support labels, sizes, flags, and change events. ```go var ( name = "" notes = "" age = int32(25) score = float32(9.5) ) func loop() { g.SingleWindow().Layout( g.InputText(&name). Label("Name"). Hint("Enter your name"). Size(200). OnChange(func() { /* validate */ }), g.InputTextMultiline(¬es). Label("Notes"). Size(300, 120). AutoScrollToBottom(true), g.InputInt(&age). Label("Age"). Size(100). StepSize(1). StepSizeFast(5). OnChange(func() { /* age changed */ }), g.InputFloat(&score). Label("Score"). Format("%.1f"). Size(100), ) } ``` -------------------------------- ### Implement Tooltip for Widgets Source: https://context7.com/allendang/giu/llms.txt Add tooltips to widgets, either as simple strings or custom layouts. Tooltips can be attached to specific widgets using .To(). ```go func loop() { g.SingleWindow().Layout( g.Button("?"), g.Tooltip("Click for help"), g.Label("Hover me"), g.Tooltip("").Layout( g.Label("Custom tooltip"), g.Separator(), g.Label("With multiple lines"), ), // Attach tooltip to a specific widget using .To() g.Tooltip("Saves the file").To( g.Button("Save").OnClick(func() { /* save */ }), ), ) } ``` -------------------------------- ### Apply Global and Tagged CSS Styling in Giu Source: https://context7.com/allendang/giu/llms.txt Load CSS files using `ParseCSSStyleSheet` for global theming and apply specific rules to widget groups using `CSSTag`. The `main` tag applies to the entire application. ```css // style.css // main { background-color: #1e1e2e; color: white; } // .button { button-color: steelblue; frame-rounding: 6; } ``` ```go //go:embed style.css var cssStyle []byte func loop() { giu.SingleWindow().Layout( giu.CSSTag("button").To( giu.Button("CSS Styled Button"), ), giu.CSSTag("label").To( giu.Label("CSS Styled Label"), ), ) } func main() { wnd := giu.NewMasterWindow("CSS Demo", 800, 600, 0) if err := giu.ParseCSSStyleSheet(cssStyle); err != nil { panic(err) } wnd.Run(loop) } ``` -------------------------------- ### Implement Modal and Non-Modal Popups in Giu Source: https://context7.com/allendang/giu/llms.txt Use `OpenPopup` to trigger popups. `PopupModal` creates blocking dialogs, while `Popup` creates non-modal popups that appear near the mouse cursor. Popups are declared inline within the layout. ```go var showConfirm = false func loop() { g.SingleWindow().Layout( g.Button("Delete").OnClick(func() { g.OpenPopup("confirm_delete") }), g.PopupModal("confirm_delete").Layout( g.Label("Are you sure you want to delete?"), g.Row( g.Button("Yes").OnClick(func() { // perform delete g.CloseCurrentPopup() }), g.Button("No").OnClick(func() { g.CloseCurrentPopup() }), ), ), // Non-modal popup (appears near mouse) g.Button("Options").OnClick(func() { g.OpenPopup("options_popup") }), g.Popup("options_popup").Layout( g.MenuItem("Copy"), g.MenuItem("Paste"), g.MenuItem("Delete") ), ) } ``` -------------------------------- ### Build Windows Executable from macOS Source: https://github.com/allendang/giu/wiki/Home Shell script to build a Windows executable from macOS. Requires mingw-w64 and a `.rc` file for the application icon. Ensure the script is executable before running. ```shell cat > YourExeName.rc << EOL id ICON "./res/app_win.ico" GLFW_ICON ICON "./res/app_win.ico" EOL x86_64-w64-mingw32-windres YourExeName.rc -O coff -o YourExeName.syso GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ HOST=x86_64-w64-mingw32 go build -ldflags "-s -w -H=windowsgui -extldflags=-static" -p 4 -v -o YourExeName.exe rm YourExeName.syso rm YourExeName.rc ``` ```shell chmod +x ./build_win.sh ``` -------------------------------- ### TreeNode for Collapsible Tree Items Source: https://context7.com/allendang/giu/llms.txt Demonstrates the creation of collapsible tree structures using TreeNode. Nested TreeNodes allow for building hierarchical UIs. ```go func loop() { g.SingleWindow().Layout( g.TreeNode("Project"). Flags(g.TreeNodeFlagsDefaultOpen). Layout( g.TreeNode("src").Layout( g.TreeNode("main.go").Layout( g.Label("package main"), ), g.TreeNode("utils.go").Layout( g.Label("package main"), ), ), g.TreeNode("assets").Layout( g.Label("logo.png"), ), ), ) } ``` -------------------------------- ### Slider Widgets for Value Selection Source: https://context7.com/allendang/giu/llms.txt Illustrates the use of SliderInt and SliderFloat for selecting values within a range. Sliders require pointers to integer or float variables and define minimum and maximum bounds. ```go var ( volume = int32(50) opacity = float32(1.0) ) func loop() { g.SingleWindow().Layout( g.SliderInt(&volume, 0, 100). Label("Volume"). Format("Vol: %d%%"). Size(250). OnChange(func() { /* apply volume */ }), g.SliderFloat(&opacity, 0.0, 1.0). Label("Opacity"). Format("%.2f"). Size(250), ) } ``` -------------------------------- ### Usage of MainMenuBar vs. SingleWindowWithMenuBar Source: https://github.com/allendang/giu/wiki/FAQ Demonstrates the usage of MainMenuBar for multi-window applications and SingleWindowWithMenuBar for single-window applications requiring a menubar. The menubarLayout function defines the structure of the menu. ```go 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) } ``` -------------------------------- ### Button Widgets in giu Source: https://context7.com/allendang/giu/llms.txt Implement clickable buttons with options for size, click handlers, and disabled states. Includes standard, small, arrow, and invisible buttons. ```go var counter int func loop() { g.SingleWindow().Layout( // Standard button with size and click handler g.Button("Click me"). Size(120, 30). OnClick(func() { counter++ }), g.Labelf("Clicked %d times", counter), // Small inline button (no frame padding) g.Row( g.Label("Action:"), g.SmallButton("Run").OnClick(func() { /* ... */ }), ), // Arrow button (directional) g.Row( g.ArrowButton(g.DirectionLeft).OnClick(func() { counter-- }), g.ArrowButton(g.DirectionRight).OnClick(func() { counter++ }), ), // Disabled button g.Button("Locked").Disabled(true), // Invisible clickable region (overlay other widgets manually) g.InvisibleButton().Size(200, 40).OnClick(func() { /* ... */ }), ) } ``` -------------------------------- ### Layout Primitives in giu Source: https://context7.com/allendang/giu/llms.txt Organize widgets using Layout (vertical), Row (horizontal), Column (vertical within row), and Child (scrollable panel). ```go func loop() { g.SingleWindow().Layout( // Vertical stack (default) g.Label("Line 1"), g.Label("Line 2"), g.Separator(), // Horizontal row g.Row( g.Button("OK").OnClick(func() { /* ... */ }), g.Button("Cancel"), g.Dummy(10, 0), // spacer g.Label("Status: ready"), ), // Scrollable child panel, 300x150, with border g.Child().Border(true).Size(300, 150).Layout( g.Label("Inside child panel"), g.BulletText("item one"), g.BulletText("item two"), ), ) } ``` -------------------------------- ### Define giu Widget Interface Source: https://github.com/allendang/giu/wiki/Home Defines the `Build` method required for all widgets in the giu framework. ```go type Widget interface { Build() } ``` -------------------------------- ### Prepare GIU Message Box Source: https://github.com/allendang/giu/wiki/Home Embed giu.PrepareMsgbox at the end of your window layout to enable giu.Msgbox functionality. This is a prerequisite for displaying message boxes. ```go giu.SingleWindow().Layout( // You layout. giu.PrepareMsgbox(), ) ``` -------------------------------- ### Build Application for MacOS Source: https://github.com/allendang/giu/blob/master/README.md Compiles the application for macOS with stripped debug information and symbols. ```sh go build -ldflags "-s -w" . ``` -------------------------------- ### Handle Double-Click Events Source: https://github.com/allendang/giu/wiki/FAQ Use giu.Event().OnDClick to register a callback for double-click events on a widget. Specify the mouse button to trigger the event. ```go giu.Button("Double-click me"), giu.Event().OnDClick(giu.MouseButtonLeft, func() {fmt.Println("I was double clicked!")}), ``` -------------------------------- ### Create Resizable Split Panels with SplitLayout Source: https://context7.com/allendang/giu/llms.txt Use SplitLayout to create two resizable panels separated by a draggable divider. Specify the direction (vertical or horizontal) and a pointer to a float32 variable that stores the split position. ```go var splitPos float32 = 250 func loop() { g.SingleWindow().Layout( g.SplitLayout(g.DirectionVertical, &splitPos, // Left panel g.Layout{ g.Label("Left panel"), g.Button("Left action"), }, // Right panel g.Layout{ g.Label("Right panel"), g.Button("Right action"), }, ), ) } ``` -------------------------------- ### Create Charts and Graphs with Giu Plot Source: https://context7.com/allendang/giu/llms.txt Utilize the Plot widget to integrate ImPlot charts like Line, Bar, and Scatter. Axis limits can be set, and plots can be styled using CSS tags. ```go var yData = []float64{0, 1, 4, 9, 16, 25, 36, 49} func loop() { g.SingleWindow().Layout( g.Plot("My Chart"). Size(500, 300). AxisLimits(0, 8, 0, 60, g.ConditionAlways). Plots( g.Line("y = x²", yData), ), // CSS-styled plot g.CSSTag("chart").To( g.Plot("Styled Chart"). Size(500, 200). Plots( g.Line("Series A", []float64{1, 3, 2, 5, 4}), ), ), ) } ``` -------------------------------- ### Align Widgets within Container Source: https://context7.com/allendang/giu/llms.txt Use Align for auto-measured centering or right-alignment, and AlignManually for stable alignment when widget width is known. ```go func loop() { g.SingleWindow().Layout( // Auto-measured center alignment (experimental) g.Align(g.AlignCenter).To( g.Button("Centered Button").Size(160, 30), ), // Right alignment g.Align(g.AlignRight).To( g.Label("Right-aligned text"), ), // Manual alignment — reliable, requires known width g.AlignManually(g.AlignCenter, g.Button("OK").Size(80, 28), 80, false), ) } ``` -------------------------------- ### Manage Custom Fonts in Giu Source: https://context7.com/allendang/giu/llms.txt Add custom fonts to the FontAtlas from TTF files or byte slices before running the application. Apply fonts using Style().SetFont() or widget-specific .Font(). ```go var boldFont *g.FontInfo func main() { wnd := g.NewMasterWindow("Fonts Demo", 800, 600, 0) // Add a font by file path boldFont = g.Context.FontAtlas.AddFontFromFileTTF("fonts/Roboto-Bold.ttf", 16) // Add a font from embedded bytes // boldFont = g.Context.FontAtlas.AddFontFromBytes("RobotoBold", fontBytes, 16) wnd.Run(func() { g.SingleWindow().Layout( g.Label("Default font"), g.Label("Bold font").Font(boldFont), g.Style().SetFont(boldFont).To( g.Button("Bold Button"), g.Label("Also bold"), ), ) }) } ``` -------------------------------- ### Enable Word Wrap in InputTextMultilineWidget Source: https://github.com/allendang/giu/wiki/FAQ Set the giu.InputTextFlagsWordWrap flag when creating an InputTextMultilineWidget to enable text wrapping. ```go giu.InputTextMultilineFlagsWordWrap ``` -------------------------------- ### Demonstrate Duplicated Widget IDs Source: https://github.com/allendang/giu/wiki/Home Shows the behavior when two buttons share the same ID. In this case, the second button's onClick callback is not triggered. ```go package main import ( "fmt" "github.com/AllenDang/giu" ) func loop() { giu.SingleWindow().Layout( giu.Button("").OnClick(func() { fmt.Println("button 1 clicked") }).ID("ok"), giu.Button("").OnClick(func() { fmt.Println("button 2 clicked") }).ID("ok"), // <- this string is the same as the one above, lets see what happens ) } func main() { giu.NewMasterWindow("Duplicated ID demo", 640, 480, 0).Run(loop) } ``` -------------------------------- ### Set Default Name for Widget Source: https://github.com/allendang/giu/wiki/FAQ Allows setting a default name for the widget when it's initialized. This value is used if no other name is provided. ```go func (w *CatWidget) DefaultName(name string) *CatWidget { w.defaultName = name return w } ``` -------------------------------- ### Use ColorEdit for Color Picking Source: https://context7.com/allendang/giu/llms.txt Bind a ColorEdit widget to a *color.RGBA variable to display an inline color picker. Flags like ColorEditFlagsNoAlpha can modify its behavior. The OnChange callback is triggered when the color is updated. ```go import "image/color" var bgColor = color.RGBA{R: 100, G: 149, B: 237, A: 255} func loop() { g.SingleWindow().Layout( g.ColorEdit("Background Color", &bgColor). Flags(g.ColorEditFlagsNoAlpha). Size(250). OnChange(func() { // bgColor is updated; apply it }), g.Labelf("RGBA: %d %d %d %d", bgColor.R, bgColor.G, bgColor.B, bgColor.A), ) } ``` -------------------------------- ### Manually Set Widget ID Source: https://github.com/allendang/giu/wiki/FAQ Provides a method to manually assign a specific ID to a widget. This can be used as an alternative to auto-generated IDs if needed. ```go func (w *CatWidget) ID(id giu.ID) *CatWidget { w.id = id return w } ``` -------------------------------- ### Disable Viewports in Dear ImGui Source: https://github.com/allendang/giu/wiki/FAQ Disable the Dear ImGui docking branch feature that allows windows to be dragged out of the master window. Apply this after creating the master window. ```go io := imgui.CurrentIO() io.SetConfigFlags(io.ConfigFlags() & ^imgui.ConfigFlagsViewportsEnable) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.