mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
[v3] Position/GetPosition -> RelativePosition/GetRelativePosition
This commit is contained in:
+12
-12
@@ -50,7 +50,7 @@ func main() {
|
||||
OnClick(func(ctx *application.Context) {
|
||||
app.NewWebviewWindow().
|
||||
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
|
||||
SetPosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetURL("https://wails.io").
|
||||
Show()
|
||||
windowCounter++
|
||||
@@ -60,7 +60,7 @@ func main() {
|
||||
OnClick(func(ctx *application.Context) {
|
||||
app.NewWebviewWindow().
|
||||
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
|
||||
SetPosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetURL("https://wails.io").
|
||||
SetFrameless(true).
|
||||
Show()
|
||||
@@ -76,7 +76,7 @@ func main() {
|
||||
},
|
||||
}).
|
||||
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
|
||||
SetPosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetHTML("<br/><br/><p>A MacTitleBarHiddenInset WebviewWindow example</p>").
|
||||
Show()
|
||||
windowCounter++
|
||||
@@ -90,7 +90,7 @@ func main() {
|
||||
},
|
||||
}).
|
||||
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
|
||||
SetPosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetHTML("<br/><br/><p>A MacTitleBarHiddenInsetUnified WebviewWindow example</p>").
|
||||
Show()
|
||||
windowCounter++
|
||||
@@ -104,7 +104,7 @@ func main() {
|
||||
},
|
||||
}).
|
||||
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
|
||||
SetPosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetHTML("<br/><br/><p>A MacTitleBarHidden WebviewWindow example</p>").
|
||||
Show()
|
||||
windowCounter++
|
||||
@@ -154,21 +154,21 @@ func main() {
|
||||
})
|
||||
})
|
||||
positionMenu := menu.AddSubmenu("Position")
|
||||
positionMenu.Add("Set Position (0,0)").OnClick(func(ctx *application.Context) {
|
||||
positionMenu.Add("Set Relative Position (0,0)").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.WebviewWindow) {
|
||||
w.SetPosition(0, 0)
|
||||
w.SetRelativePosition(0, 0)
|
||||
})
|
||||
})
|
||||
positionMenu.Add("Set Position (Random)").OnClick(func(ctx *application.Context) {
|
||||
positionMenu.Add("Set Relative Position (Random)").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.WebviewWindow) {
|
||||
w.SetPosition(rand.Intn(1000), rand.Intn(800))
|
||||
w.SetRelativePosition(rand.Intn(1000), rand.Intn(800))
|
||||
})
|
||||
})
|
||||
|
||||
positionMenu.Add("Get Position").OnClick(func(ctx *application.Context) {
|
||||
positionMenu.Add("Get Relative Position").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.WebviewWindow) {
|
||||
x, y := w.Position()
|
||||
app.InfoDialog().SetTitle("Current WebviewWindow Position").SetMessage("X: " + strconv.Itoa(x) + " Y: " + strconv.Itoa(y)).Show()
|
||||
x, y := w.RelativePosition()
|
||||
app.InfoDialog().SetTitle("Current WebviewWindow Relative Position").SetMessage("X: " + strconv.Itoa(x) + " Y: " + strconv.Itoa(y)).Show()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
+11
-11
@@ -50,7 +50,7 @@ func main() {
|
||||
OnClick(func(ctx *application.Context) {
|
||||
app.NewWebviewWindow().
|
||||
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
|
||||
SetPosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetURL("https://wails.io").
|
||||
Show()
|
||||
windowCounter++
|
||||
@@ -79,7 +79,7 @@ func main() {
|
||||
},
|
||||
}).
|
||||
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
|
||||
SetPosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetURL("https://wails.io").
|
||||
Show()
|
||||
windowCounter++
|
||||
@@ -107,7 +107,7 @@ func main() {
|
||||
},
|
||||
}).
|
||||
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
|
||||
SetPosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetHTML("<br/><br/><p>A MacTitleBarHiddenInset WebviewWindow example</p>").
|
||||
Show()
|
||||
windowCounter++
|
||||
@@ -121,7 +121,7 @@ func main() {
|
||||
},
|
||||
}).
|
||||
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
|
||||
SetPosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetHTML("<br/><br/><p>A MacTitleBarHiddenInsetUnified WebviewWindow example</p>").
|
||||
Show()
|
||||
windowCounter++
|
||||
@@ -135,7 +135,7 @@ func main() {
|
||||
},
|
||||
}).
|
||||
SetTitle("WebviewWindow "+strconv.Itoa(windowCounter)).
|
||||
SetPosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetHTML("<br/><br/><p>A MacTitleBarHidden WebviewWindow example</p>").
|
||||
Show()
|
||||
windowCounter++
|
||||
@@ -185,20 +185,20 @@ func main() {
|
||||
})
|
||||
})
|
||||
positionMenu := menu.AddSubmenu("Position")
|
||||
positionMenu.Add("Set Position (0,0)").OnClick(func(ctx *application.Context) {
|
||||
positionMenu.Add("Set Relative Position (0,0)").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.WebviewWindow) {
|
||||
w.SetPosition(0, 0)
|
||||
w.SetRelativePosition(0, 0)
|
||||
})
|
||||
})
|
||||
positionMenu.Add("Set Position (Random)").OnClick(func(ctx *application.Context) {
|
||||
positionMenu.Add("Set Relative Position (Random)").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.WebviewWindow) {
|
||||
w.SetPosition(rand.Intn(1000), rand.Intn(800))
|
||||
w.SetRelativePosition(rand.Intn(1000), rand.Intn(800))
|
||||
})
|
||||
})
|
||||
|
||||
positionMenu.Add("Get Position").OnClick(func(ctx *application.Context) {
|
||||
positionMenu.Add("Get Relative Position").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.WebviewWindow) {
|
||||
x, y := w.Position()
|
||||
x, y := w.RelativePosition()
|
||||
app.InfoDialog().SetTitle("Current WebviewWindow Position").SetMessage("X: " + strconv.Itoa(x) + " Y: " + strconv.Itoa(y)).Show()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -38,7 +38,7 @@ func main() {
|
||||
Name: windowName,
|
||||
}).
|
||||
SetTitle(windowName).
|
||||
SetPosition(rand.Intn(1000), rand.Intn(800)).
|
||||
SetRelativePosition(rand.Intn(1000), rand.Intn(800)).
|
||||
Show()
|
||||
windowCounter++
|
||||
}
|
||||
|
||||
@@ -87,17 +87,17 @@ export function newWindow(windowName) {
|
||||
SetAlwaysOnTop: (onTop) => void call('SetAlwaysOnTop', {alwaysOnTop:onTop}),
|
||||
|
||||
/**
|
||||
* Set the window position.
|
||||
* Set the window relative position.
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
*/
|
||||
SetPosition: (x, y) => call('SetPosition', {x,y}),
|
||||
SetRelativePosition: (x, y) => call('SetRelativePosition', {x,y}),
|
||||
|
||||
/**
|
||||
* Get the window position.
|
||||
* @returns {Promise<Position>} The window position
|
||||
*/
|
||||
Position: () => { return call('Position'); },
|
||||
RelativePosition: () => { return call('RelativePosition'); },
|
||||
|
||||
/**
|
||||
* Get the screen the window is on.
|
||||
|
||||
@@ -30,14 +30,14 @@ func (m *MessageProcessor) processWindowMethod(method string, rw http.ResponseWr
|
||||
}
|
||||
window.SetSize(*width, *height)
|
||||
m.ok(rw)
|
||||
case "SetPosition":
|
||||
case "SetRelativePosition":
|
||||
x := args.Int("x")
|
||||
y := args.Int("y")
|
||||
if x == nil || y == nil {
|
||||
m.Error("Invalid SetPosition Message")
|
||||
m.Error("Invalid SetRelativePosition Message")
|
||||
return
|
||||
}
|
||||
window.SetPosition(*x, *y)
|
||||
window.SetRelativePosition(*x, *y)
|
||||
m.ok(rw)
|
||||
case "Fullscreen":
|
||||
window.Fullscreen()
|
||||
@@ -78,8 +78,8 @@ func (m *MessageProcessor) processWindowMethod(method string, rw http.ResponseWr
|
||||
"width": width,
|
||||
"height": height,
|
||||
})
|
||||
case "Position":
|
||||
x, y := window.Position()
|
||||
case "RelativePosition":
|
||||
x, y := window.RelativePosition()
|
||||
m.json(rw, map[string]interface{}{
|
||||
"x": x,
|
||||
"y": y,
|
||||
|
||||
@@ -30,7 +30,7 @@ type (
|
||||
size() (int, int)
|
||||
width() int
|
||||
height() int
|
||||
position() (int, int)
|
||||
relativePosition() (int, int)
|
||||
destroy()
|
||||
reload()
|
||||
forceReload()
|
||||
@@ -43,7 +43,7 @@ type (
|
||||
close()
|
||||
zoom()
|
||||
setHTML(html string)
|
||||
setPosition(x int, y int)
|
||||
setRelativePosition(x int, y int)
|
||||
on(eventID uint)
|
||||
minimise()
|
||||
unminimise()
|
||||
@@ -574,14 +574,14 @@ func (w *WebviewWindow) Height() int {
|
||||
return invokeSyncWithResult(w.impl.height)
|
||||
}
|
||||
|
||||
// Position returns the position of the window
|
||||
func (w *WebviewWindow) Position() (int, int) {
|
||||
// RelativePosition returns the relative position of the window to the screen
|
||||
func (w *WebviewWindow) RelativePosition() (int, int) {
|
||||
if w.impl == nil {
|
||||
return 0, 0
|
||||
}
|
||||
var x, y int
|
||||
invokeSync(func() {
|
||||
x, y = w.impl.position()
|
||||
x, y = w.impl.relativePosition()
|
||||
})
|
||||
return x, y
|
||||
}
|
||||
@@ -690,13 +690,13 @@ func (w *WebviewWindow) SetHTML(html string) *WebviewWindow {
|
||||
return w
|
||||
}
|
||||
|
||||
// SetPosition sets the position of the window.
|
||||
func (w *WebviewWindow) SetPosition(x, y int) *WebviewWindow {
|
||||
// SetRelativePosition sets the position of the window.
|
||||
func (w *WebviewWindow) SetRelativePosition(x, y int) *WebviewWindow {
|
||||
w.options.X = x
|
||||
w.options.Y = y
|
||||
if w.impl != nil {
|
||||
invokeSync(func() {
|
||||
w.impl.setPosition(x, y)
|
||||
w.impl.setRelativePosition(x, y)
|
||||
})
|
||||
}
|
||||
return w
|
||||
|
||||
@@ -277,8 +277,8 @@ void windowZoomOut(void* nsWindow) {
|
||||
}
|
||||
}
|
||||
|
||||
// set the window position
|
||||
void windowSetPosition(void* nsWindow, int x, int y) {
|
||||
// set the window position relative to the screen
|
||||
void windowSetrelativePosition(void* nsWindow, int x, int y) {
|
||||
WebviewWindow* window = (WebviewWindow*)nsWindow;
|
||||
NSScreen* screen = [window screen];
|
||||
if( screen == NULL ) {
|
||||
@@ -941,8 +941,8 @@ func (w *macosWebviewWindow) size() (int, int) {
|
||||
return int(width), int(height)
|
||||
}
|
||||
|
||||
func (w *macosWebviewWindow) setPosition(x, y int) {
|
||||
C.windowSetPosition(w.nsWindow, C.int(x), C.int(y))
|
||||
func (w *macosWebviewWindow) setRelativePosition(x, y int) {
|
||||
C.windowSetrelativePosition(w.nsWindow, C.int(x), C.int(y))
|
||||
}
|
||||
|
||||
func (w *macosWebviewWindow) width() int {
|
||||
|
||||
@@ -344,7 +344,7 @@ func (w *linuxWebviewWindow) fullscreen() {
|
||||
w.setMinMaxSize(0, 0, width*scale, height*scale)
|
||||
w.setSize(width*scale, height*scale)
|
||||
C.gtk_window_fullscreen((*C.GtkWindow)(w.window))
|
||||
w.setPosition(0, 0)
|
||||
w.setRelativePosition(0, 0)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -613,7 +613,7 @@ func (w *linuxWebviewWindow) size() (int, int) {
|
||||
return int(width), int(height)
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) setPosition(x, y int) {
|
||||
func (w *linuxWebviewWindow) setRelativePosition(x, y int) {
|
||||
mx, my, _, _, _ := w.getCurrentMonitorGeometry()
|
||||
globalApplication.dispatchOnMainThread(func() {
|
||||
C.gtk_window_move((*C.GtkWindow)(w.window), C.int(x+mx), C.int(y+my))
|
||||
@@ -675,7 +675,7 @@ func (w *linuxWebviewWindow) run() {
|
||||
w.setFrameless(w.parent.options.Frameless)
|
||||
|
||||
if w.parent.options.X != 0 || w.parent.options.Y != 0 {
|
||||
w.setPosition(w.parent.options.X, w.parent.options.Y)
|
||||
w.setRelativePosition(w.parent.options.X, w.parent.options.Y)
|
||||
} else {
|
||||
fmt.Println("attempting to set in the center")
|
||||
w.center()
|
||||
@@ -710,7 +710,7 @@ func (w *linuxWebviewWindow) run() {
|
||||
if !w.parent.options.Hidden {
|
||||
w.show()
|
||||
if w.parent.options.X != 0 || w.parent.options.Y != 0 {
|
||||
w.setPosition(w.parent.options.X, w.parent.options.Y)
|
||||
w.setRelativePosition(w.parent.options.X, w.parent.options.Y)
|
||||
} else {
|
||||
fmt.Println("attempting to set in the center")
|
||||
w.center()
|
||||
|
||||
@@ -217,7 +217,7 @@ func (w *linuxWebviewWindow) fullscreen() {
|
||||
}
|
||||
w.setMinMaxSize(0, 0, width*scale, height*scale)
|
||||
w.setSize(width*scale, height*scale)
|
||||
w.setPosition(0, 0)
|
||||
w.setRelativePosition(0, 0)
|
||||
fullScreen(w.window)
|
||||
})
|
||||
}
|
||||
@@ -365,7 +365,7 @@ func (w *linuxWebviewWindow) center() {
|
||||
newX := ((width - int(windowWidth)) / 2) + x
|
||||
newY := ((height - int(windowHeight)) / 2) + y
|
||||
|
||||
w.setPosition(newX, newY)
|
||||
w.setRelativePosition(newX, newY)
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) isMinimised() bool {
|
||||
@@ -530,11 +530,11 @@ func (w *linuxWebviewWindow) size() (int, int) {
|
||||
return width, height
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) setPosition(x, y int) {
|
||||
func (w *linuxWebviewWindow) setRelativePosition(x, y int) {
|
||||
var windowMove func(uintptr, int, int)
|
||||
purego.RegisterLibFunc(&windowMove, gtk, "gtk_window_move")
|
||||
mx, my, _, _, _ := w.getCurrentMonitorGeometry()
|
||||
fmt.Println("setPosition", mx, my)
|
||||
fmt.Println("setRelativePosition", mx, my)
|
||||
globalApplication.dispatchOnMainThread(func() {
|
||||
windowMove(w.window, x+mx, y+my)
|
||||
})
|
||||
@@ -641,7 +641,7 @@ func (w *linuxWebviewWindow) run() {
|
||||
if w.parent.options.Hidden == false {
|
||||
w.show()
|
||||
if w.parent.options.X != 0 || w.parent.options.Y != 0 {
|
||||
w.setPosition(w.parent.options.X, w.parent.options.Y)
|
||||
w.setRelativePosition(w.parent.options.X, w.parent.options.Y)
|
||||
} else {
|
||||
w.center()
|
||||
}
|
||||
@@ -697,7 +697,7 @@ func (w *linuxWebviewWindow) setBackgroundColour(colour RGBA) {
|
||||
setBackgroundColor(w.webview, pointer)
|
||||
}
|
||||
|
||||
func (w *linuxWebviewWindow) position() (int, int) {
|
||||
func (w *linuxWebviewWindow) relativePosition() (int, int) {
|
||||
var getPosition func(uintptr, *int, *int) bool
|
||||
purego.RegisterLibFunc(&getPosition, gtk, "gtk_window_get_position")
|
||||
|
||||
|
||||
@@ -334,7 +334,7 @@ func (w *windowsWebviewWindow) height() int {
|
||||
return height
|
||||
}
|
||||
|
||||
func (w *windowsWebviewWindow) position() (int, int) {
|
||||
func (w *windowsWebviewWindow) relativePosition() (int, int) {
|
||||
rect := w32.GetWindowRect(w.hwnd)
|
||||
left, right := w.scaleToDefaultDPI(int(rect.Left), int(rect.Right))
|
||||
return left, right
|
||||
@@ -416,7 +416,7 @@ func (w *windowsWebviewWindow) setHTML(html string) {
|
||||
w.execJS(fmt.Sprintf("document.documentElement.innerHTML = %q;", html))
|
||||
}
|
||||
|
||||
func (w *windowsWebviewWindow) setPosition(x int, y int) {
|
||||
func (w *windowsWebviewWindow) setRelativePosition(x int, y int) {
|
||||
x, y = w.scaleWithWindowDPI(x, y)
|
||||
info := w32.GetMonitorInfoForWindow(w.hwnd)
|
||||
workRect := info.RcWork
|
||||
|
||||
Reference in New Issue
Block a user