Skip to content

Commit

Permalink
Merge pull request #2794 from fyne-io/fix/2784
Browse files Browse the repository at this point in the history
If FixedSize is set without a preferred size we should fall back to minimum
  • Loading branch information
andydotxyz committed Feb 18, 2022
2 parents f257a3f + 852ba30 commit 0d0e999
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/driver/glfw/window.go
Expand Up @@ -218,7 +218,7 @@ func (w *window) FixedSize() bool {

func (w *window) SetFixedSize(fixed bool) {
w.fixedSize = fixed

w.ensureFixedHasSize()
if w.view() != nil {
w.runOnMainWhenCreated(w.fitContent)
}
Expand Down Expand Up @@ -501,6 +501,10 @@ func (w *window) SetContent(content fyne.CanvasObject) {
}

w.canvas.SetContent(content)
if !visible {
w.ensureFixedHasSize()
}

// show new canvas element
if content != nil {
content.Show()
Expand Down Expand Up @@ -535,6 +539,14 @@ func (w *window) destroy(d *gLDriver) {
}
}

// ensureFixedHasSize makes sure that if a window is fixed size it has a requested size, or is set to minimum
func (w *window) ensureFixedHasSize() {
if w.FixedSize() && (w.requestedWidth == 0 || w.requestedHeight == 0) {
bigEnough := w.canvas.canvasSize(w.canvas.Content().MinSize())
w.Resize(bigEnough)
}
}

func (w *window) moved(_ *glfw.Window, x, y int) {
if !w.fullScreen { // don't save the move to top left when changing to fullscreen
// save coordinates
Expand Down
17 changes: 17 additions & 0 deletions internal/driver/glfw/window_test.go
Expand Up @@ -78,6 +78,23 @@ func TestGLDriver_CreateSplashWindow(t *testing.T) {
assert.True(t, w.centered)
}

func TestWindow_MinSize_Fixed(t *testing.T) {
w := createWindow("Test").(*window)
r := canvas.NewRectangle(color.White)
r.SetMinSize(fyne.NewSize(100, 100))
w.SetContent(r)
w.SetFixedSize(true)

assert.Equal(t, float32(100)+theme.Padding()*2, w.Canvas().Size().Width)

w = createWindow("Test").(*window)
r.SetMinSize(fyne.NewSize(100, 100))
w.SetFixedSize(true)
w.SetContent(r)

assert.Equal(t, float32(100)+theme.Padding()*2, w.Canvas().Size().Width)
}

func TestWindow_ToggleMainMenuByKeyboard(t *testing.T) {
w := createWindow("Test").(*window)
c := w.Canvas().(*glCanvas)
Expand Down

0 comments on commit 0d0e999

Please sign in to comment.