Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programmatically move a window #72

Closed
sharpobject opened this issue Jan 13, 2021 · 1 comment
Closed

Programmatically move a window #72

sharpobject opened this issue Jan 13, 2021 · 1 comment

Comments

@sharpobject
Copy link

Hello,

I tried out the example and noticed that it was easy for the window to end up out of the viewport. So I wanted to make it so that the window was clamped inside a viewport, and to do that I wanted to programmatically move the window. Is there a recommended way to do this?

@coding-jackalope
Copy link
Collaborator

Hi @sharpobject, you do have control over the placement of the window programmatically through the 'X' and 'Y' options you pass into the 'BeginWindow' function. Passing NoMove = true with the options will disable movement of the window. More information can be found here.

local X, Y = 50, 50
Slab.BeginWindow('MyWindow', {Title = "My Window", X = X, Y = Y, NoMove = true})
Slab.EndWindow()

Unfortunately, Slab does not support constraining the window to the viewport at the moment. I looked into how it can be done quickly, but you may need to dive into the Slab internals to get this to work. I can add an option to constrain the window to the viewport in the next update.

The basic gist of how window movement works in Slab is that it records any delta changes when a window is dragged. This delta is then applied to the requested window position on the next frame. The main logic for how a window position is updated is done in the UpdateTitleBar function in the Window.lua module. I would start there if you decide to jump in and try to look into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants