Skip to content

Commit 0a08110

Browse files
committed
feat: add option WindowInitialLocations
1 parent 3bfa4f2 commit 0a08110

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

application.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,25 @@ func (a *Application) Run() error {
100100
return errors.Errorf("invalid window mode %T", a.config.windowMode)
101101
}
102102

103+
if a.config.windowInitialLocations.xpos != 0 {
104+
// To create the window at a specific position, make it initially invisible
105+
// using the Visible window hint, set its position and then show it.
106+
glfw.WindowHint(glfw.Visible, glfw.False)
107+
}
108+
103109
a.window, err = glfw.CreateWindow(a.config.windowInitialDimensions.width, a.config.windowInitialDimensions.height, "Loading..", monitor, nil)
104110
if err != nil {
105111
return errors.Wrap(err, "creating glfw window")
106112
}
107113
glfw.DefaultWindowHints()
108114
defer a.window.Destroy()
109115

116+
if a.config.windowInitialLocations.xpos != 0 {
117+
a.window.SetPos(a.config.windowInitialLocations.xpos,
118+
a.config.windowInitialLocations.ypos)
119+
a.window.Show()
120+
}
121+
110122
a.resourceWindow, err = createResourceWindow(a.window)
111123
if err != nil {
112124
fmt.Printf("go-flutter: WARNING %v\n", err)

option.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type config struct {
1616
windowInitializerDeprecated func(*glfw.Window) error
1717
windowIconProvider func() ([]image.Image, error)
1818
windowInitialDimensions windowDimensions
19+
windowInitialLocations windowLocations
1920
windowDimensionLimits windowDimensionLimits
2021
windowMode windowMode
2122

@@ -30,6 +31,11 @@ type windowDimensions struct {
3031
height int
3132
}
3233

34+
type windowLocations struct {
35+
xpos int
36+
ypos int
37+
}
38+
3339
type windowDimensionLimits struct {
3440
minWidth int
3541
minHeight int
@@ -118,6 +124,25 @@ func WindowInitialDimensions(width, height int) Option {
118124
}
119125
}
120126

127+
// WindowInitialLocations specify the startup's position of the window.
128+
// Location, in screen coordinates, of the upper-left corner of the client area
129+
// of the window.
130+
func WindowInitialLocations(xpos, ypos int) Option {
131+
if xpos < 1 {
132+
fmt.Println("go-flutter: invalid initial value for xpos location, must be 1 or greater.")
133+
os.Exit(1)
134+
}
135+
if ypos < 1 {
136+
fmt.Println("go-flutter: invalid initial value for ypos location, must be 1 or greater.")
137+
os.Exit(1)
138+
}
139+
140+
return func(c *config) {
141+
c.windowInitialLocations.xpos = xpos
142+
c.windowInitialLocations.ypos = ypos
143+
}
144+
}
145+
121146
// WindowDimensionLimits specify the dimension limits of the window.
122147
// Does not work when the window is fullscreen or not resizable.
123148
func WindowDimensionLimits(minWidth, minHeight, maxWidth, maxHeight int) Option {

0 commit comments

Comments
 (0)