-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Widgets added to Overlay have incorrect Size until window Resize event occurs. #5299
Comments
Confirmed on my windows machine. It seems like the main reason is that the canvas object for the overlay isn't in the cache yet when the initial refreshes are called. So seems like a cache issue. It appears that maybe mobile driver actually will force the minsize but the gl driver doesn't? @Sponge96 this is a workaround based on your code: package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
"image/color"
)
type Foo struct {
canvas fyne.Canvas
}
func main() {
a := app.New()
w := a.NewWindow("Test")
foo := &Foo{
canvas: w.Canvas(),
}
mainView := container.NewVBox(widget.NewLabel("SOME CONTENT"))
w.SetContent(mainView)
w.Canvas().SetOnTypedKey(NewKeyHandler(foo, w))
w.ShowAndRun()
}
func NewKeyHandler(f *Foo, w fyne.Window) func(e *fyne.KeyEvent) {
return func(e *fyne.KeyEvent) {
switch e.Name {
case fyne.KeySpace:
bar := canvas.NewRectangle(color.Black)
pos, size := w.Canvas().InteractiveArea()
bar.Move(pos)
bar.Resize(size)
f.canvas.Overlays().Add(bar)
}
}
} edit: sorry for the extra old test code that was in there before. |
@Sharrnah this is not related - the ticket is explicitly a problem for overlays only. With regards to your problem a widget should never be in two places at once. So something that is "on multiple tabs" should really be two similar widgets. Remember that this toolkit is stateful - it remembers everything for you. Therefore the position of a widget is remembered and if you put it into multiple containers it won't know where it is supposed to be. |
I am aware of that, but the Widgets are always only shown once on screen, not at the same time. And it worked flawlessly before. If its unrelated i will create a new issue, since i am still the opnion that this is a bug. |
A widget should not be in two places at the same time - it doesn't matter if they are shown or not. |
Since my issue is not related, i say we continue this in my new opened issue that also has some additional information and demo code. :) |
Checklist
Describe the bug
When adding a Widget to the
Canvas().Overlays()
without first setting itsSize()
toCanvas().Size()
it is displayed with it's currentSize()
(Usually itsMinSize()
) instead of the size of the Canvas. Upon resizing the Window (Not via code) it is then resized to the fullCanvas().Size()
as you would have expected when it was initially added. The 'correct' behavior would be for the WidgetsLayout()
to be called with theCanvas.Size()
whenCanvas().Overlays().Add(widget)
is called.canvas.Rectangle
,widget.Label
, etc)widget.NewSimpleRenderer()
)Canvas().Overlays()
such asModalPopup
.How to reproduce
Canvas().Overlays()
. It will be 100, 100 instead of spanning the full Canvas.Screenshots
Using the example code provided, when you press "Space" it will add
bar
to theCanvas().Overlays()
which in this case is a simplecanvas.Rectangle
. When this is added to the overlay it's using the currentSize()
value of 100, 100.If you resize the window by dragging it out slightly, it updates to span the Width/Height of the full Canvas.
Example code
Fyne version
v2.5.2
Go compiler version
1.22.6
Operating system and version
NixOS
Additional Information
Reproducible on NixOS with both Hyprland and Gnome as well as Window11, with multiple different hardware setups.
Another method for viewing this behavior. This requires you to launch the application in debug mode
go run -tags debug .
This method will add a Label instead and you will see that it's bounding box is it's MinSize() when first added but after resizing the window the bounding box spans the Width/Height of the canvas the same as the Rectangle example.The text was updated successfully, but these errors were encountered: