Repository navigation
Is every thing need to be set in the Build(context *guigui.Context, adder *guigui.ChildAdder) error function every time #441
Answered
by
hajimehoshi
udan-jayanith
asked this question in
Q&A
|
If i have a popup and a button that show the popup when the button is clicked, I would normally listn for button click and on that listner, OnClose function is set for popup. // SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2026 The Guigui Authors
package main
import (
"fmt"
"image"
"os"
"github.com/hajimehoshi/ebiten/v2"
"github.com/guigui-gui/guigui"
"github.com/guigui-gui/guigui/basicwidget"
)
type Root struct {
guigui.DefaultWidget
background basicwidget.Background
popup basicwidget.Popup
show_popup basicwidget.Button
}
func (r *Root) Build(context *guigui.Context, adder *guigui.ChildAdder) error {
adder.AddWidget(&r.background)
if r.popup.IsOpen() {
adder.AddWidget(&r.popup)
}
r.show_popup.SetText("Show popup")
r.show_popup.OnDown(func(context *guigui.Context) {
r.popup.SetModal(true)
r.popup.SetCloseByClickingOutside(true)
r.popup.SetBackgroundDark(true)
r.popup.SetBackgroundBlurred(true)
r.popup.OnClose(func(context *guigui.Context, reason basicwidget.PopupCloseReason) {
println("Popup closed")
})
r.popup.SetOpen(true)
})
adder.AddWidget(&r.show_popup)
return nil
}
func (r *Root) Layout(context *guigui.Context, widgetBounds *guigui.WidgetBounds, layouter *guigui.ChildLayouter) {
bounds := widgetBounds.Bounds()
layouter.LayoutWidget(&r.background, bounds)
if r.popup.IsOpen() {
b := bounds
w := 200
h := 200
b.Min.X += b.Dx()/2 - w/2
b.Max.X = b.Min.X + w
b.Min.Y += b.Dy()/2 - h/2
b.Max.Y = b.Min.Y + h
layouter.LayoutWidget(&r.popup, b)
}
layouter.LayoutWidget(&r.show_popup, bounds)
}
func main() {
op := &guigui.RunOptions{
Title: "Popup",
WindowMinSize: image.Pt(600, 400),
RunGameOptions: &ebiten.RunGameOptions{
ApplePressAndHoldEnabled: true,
},
}
if err := guigui.Run(&Root{}, op); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}Is that the right way or r.popup.SetModal(true)
r.popup.SetCloseByClickingOutside(true)
r.popup.SetBackgroundDark(true)
r.popup.SetBackgroundBlurred(true)
r.popup.OnClose(func(context *guigui.Context, reason basicwidget.PopupCloseReason) {
println("Popup closed")
})in every build. |
Answered by
hajimehoshi
Jun 10, 2026
Replies: 2 comments
|
Note: OnClose function need to be set for popup in every build when the popup is opened otherwise OnClose function dosen't run. Is this a bug. If popup.SetOpen(true) runs in every build, popup gives a flickering effect. |
0 replies
r.show_popup.SetText("Show popup")
r.show_popup.OnDown(func(context *guigui.Context) {
r.popup.SetModal(true)
r.popup.SetCloseByClickingOutside(true)
r.popup.SetBackgroundDark(true)
r.popup.SetBackgroundBlurred(true)
r.popup.OnClose(func(context *guigui.Context, reason basicwidget.PopupCloseReason) {
println("Popup closed")
})
r.popup.SetOpen(true)
})Not correct. This should be r.show_popup.SetText("Show popup")
r.show_popup.OnDown(func(context *guigui.Context) {
r.popup.SetOpen(true)
})
r.popup.SetModal(true)
r.popup.SetCloseByClickingOutside(true)
r.popup.SetBackgroundDark(true)
r.popup.SetBackgroundBlurred(true)
r.popup.OnClose(func(context *guigui.Context, reason basicwidget.PopupCloseReason) {
println("Popup closed")
})though I might be missing something. |
0 replies
Answer selected by
udan-jayanith
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not correct. This should be