Skip to content

Commit

Permalink
Remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Feb 18, 2022
1 parent 46e2640 commit 852ba30
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions internal/driver/glfw/window.go
Expand Up @@ -218,11 +218,7 @@ func (w *window) FixedSize() bool {

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

if fixed && (w.requestedWidth == 0 || w.requestedHeight == 0) {
bigEnough := w.canvas.canvasSize(w.canvas.Content().MinSize())
w.Resize(bigEnough)
}
w.ensureFixedHasSize()
if w.view() != nil {
w.runOnMainWhenCreated(w.fitContent)
}
Expand Down Expand Up @@ -505,9 +501,8 @@ func (w *window) SetContent(content fyne.CanvasObject) {
}

w.canvas.SetContent(content)
if !visible && w.fixedSize && (w.requestedWidth == 0 || w.requestedHeight == 0) {
bigEnough := w.canvas.canvasSize(content.MinSize())
w.Resize(bigEnough)
if !visible {
w.ensureFixedHasSize()
}

// show new canvas element
Expand Down Expand Up @@ -544,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

0 comments on commit 852ba30

Please sign in to comment.