If you prefer not to use the UI designer, you can construct windows and widgets entirely through Go code. This involves initializing the app, creating a window with specific styles, and adding widgets like buttons manually.
package main
import (
"github.com/twgh/xcgui/app"
"github.com/twgh/xcgui/imagex"
"github.com/twgh/xcgui/widget"
"github.com/twgh/xcgui/window"
"github.com/twgh/xcgui/xcc"
)
func main() {
// 1. Initialize XCGUI
app.Init()
a := app.New(true)
a.EnableAutoDPI(true).EnableDPI(true)
// 2. Create window
w := window.New(0, 0, 430, 300, "xcgui window", 0, xcc.Window_Style_Default|xcc.Window_Style_Drag_Window)
w.SetBorderSize(0, 30, 0, 0)
a.SetWindowIcon(imagex.NewBySvgString(svgIcon).Handle)
w.SetTransparentType(xcc.Window_Transparent_Shadow)
w.SetShadowInfo(8, 255, 10, false, 0)
// Create a button
btn := widget.NewButton(165, 135, 100, 30, "Button", w.Handle)
// Registration button clicked event
btn.AddEvent_BnClick(func(hEle int, pbHandled *bool) int {
w.MessageBox("tip", btn.GetText(), xcc.MessageBox_Flag_Ok|xcc.MessageBox_Flag_Icon_Info, xcc.Window_Style_Modal)
return 0
})
// 3. Display window
w.Show(true)
// 4. Run the program
a.Run()
// 5. Exit the program
a.Exit()
}
var svgIcon = `<svg ...>...</svg>` // SVG content