Skip to content

Commit

Permalink
introduce default alternative
Browse files Browse the repository at this point in the history
  • Loading branch information
roffe committed Dec 9, 2024
1 parent 80614bf commit 5a1eda1
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions container/innerwindow.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package container

import (
"runtime"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
intWidget "fyne.io/fyne/v2/internal/widget"
Expand All @@ -15,8 +17,9 @@ var _ fyne.Widget = (*InnerWindow)(nil)
type InnerWindowButtonAlignment int

const (
InnerWindowButtonAlignLeft InnerWindowButtonAlignment = iota // OSX style (default)
InnerWindowButtonAlignRight // Linux, Windows style
InnerWindowButtonAlignDefault InnerWindowButtonAlignment = iota // Default, OS specific alignment ( macOS: Left, Windows & Linux: Right )
InnerWindowButtonAlignLeft // Left, macOS style
InnerWindowButtonAlignRight // Right, Windows style
)

// InnerWindow defines a container that wraps content in a window border - that can then be placed inside
Expand Down Expand Up @@ -88,16 +91,15 @@ func (w *InnerWindow) CreateRenderer() fyne.WidgetRenderer {
var buttons *fyne.Container
var bar *fyne.Container

switch w.ButtonAlignment {
case InnerWindowButtonAlignRight: // Right side
buttons = NewHBox(
min, max, close,
)
isLeftSide := w.ButtonAlignment == InnerWindowButtonAlignLeft || (w.ButtonAlignment == InnerWindowButtonAlignDefault && runtime.GOOS == "darwin")

if isLeftSide {
// Left side (macOS default or explicit left alignment)
buttons = NewHBox(min, max, close)
bar = NewBorder(nil, nil, icon, buttons, title)
default: // Left side
buttons = NewHBox(
close, min, max,
)
} else {
// Right side (Windows/Linux default and explicit right alignment)
buttons = NewHBox(close, min, max)
bar = NewBorder(nil, nil, buttons, icon, title)
}

Expand Down Expand Up @@ -128,6 +130,10 @@ func (w *InnerWindow) SetPadded(pad bool) {
w.content.Refresh()
}

func (w *InnerWindow) Title() string {
return w.title
}

func (w *InnerWindow) SetTitle(title string) {
w.title = title
w.Refresh()
Expand Down

0 comments on commit 5a1eda1

Please sign in to comment.