go-sciter
go-sciter copied to clipboard
how to make window center
how to make window center . I can see C#-sciter have a method like topCenterXXX().
You can use view.screenBox and view.move script methods to achieve that for your native window or just an alignment argument in view.dialog or view.window for newly created windows.
If it can be setting in golang?
You can call a script function from Go's side.
You can create a native window (SciterCreateWindow) at specified coordinates, which can be taken from OS.
You can take a handle of native window and call OS api to reposition it.
But no, there is no ready-to-use function similar to SciterSharp's implementation.
//var hwnd win.HWND cxScreen := win.GetSystemMetrics(win.SM_CXSCREEN) cyScreen := win.GetSystemMetrics(win.SM_CYSCREEN)
var formWidth, formHeight int32 = 900, 600
var fromPosLeft, formPosTop int32
fromPosLeft = (cxScreen - formWidth) / 2
formPosTop = (cyScreen - formHeight) / 2
w, err := window.New(sciter.SW_POPUP|sciter.SW_MAIN|sciter.SW_ENABLE_DEBUG, &sciter.Rect{fromPosLeft, formPosTop, fromPosLeft + 900, formPosTop + 600})
@taonylu how do you do this on Mac/Linux ?
Using view.screenBox and view.move w(width) and h(height) should match the values you used to create with window.New(...)
` var w = 400; var h = 600; var (sx, sy, sw, sh) = view.screenBox(#frame,#rectw); var myX = (((sx-sw)/2)-1)-(w/2); var myY = (((sy-sh)/2)-1)-(h/2); view.move( myX,myY );
`
I'm a bit late for the party...
I made a custom error dialog following this example. To place it in the middle of the screen, I did this...
// place dialog in middle of primary screen (monitor)
const viewWidth = 600;
const viewHeight = 500;
const (screenWidth, screenHeight) = view.screenBox(#frame,#dimension);
const xPosition = screenWidth / 2 - viewWidth / 2;
const yPosition = screenHeight / 2 - viewHeight / 2;
view.move(xPosition, yPosition, viewWidth, viewHeight);
This just centers it in the middle of the primary monitor (even if the main window is on another one). If you want to center it on the main window, you'd need to know its position, and also which monitor it's on.
Yeah, I just left a post...16 minutes ago.
I found a different way, that takes into consideration the monitor the main window is one, and centers the dialog there (instead of the primary monitor). See the documentation for View. It's in the part labeled dialog.
function loadErrorDialog(errorMessage) {
view.dialog {
url: self.url("error-dialog.htm"),
parameters: { text: errorMessage },
alignment: 5,
width: 600,
height: 500
};
}