Skip to content

Instantly share code, notes, and snippets.

@maluoi
Last active March 22, 2023 22:21
Show Gist options
  • Save maluoi/43a2b9a55791a09a64caf5a0364c987a to your computer and use it in GitHub Desktop.
Save maluoi/43a2b9a55791a09a64caf5a0364c987a to your computer and use it in GitHub Desktop.
StereoKit: using a grab bar below the window for movement.
Pose grabBarPose = new Pose(0, 0, -0.5f, Quat.LookDir(0, 0, 1));
Vec2 windowSize = Vec2.Zero; // First frame will not be in the right spot unless we know window size in advance.
public void Update()
{
// Use the size of the Window to position it directly above the grab
// bar. Note that we're using the Pose relative Up direction instead of
// just the Y axis.
Pose windowPose = grabBarPose;
windowPose.position -= grabBarPose.Up * windowSize.y;
// Begin the window, only show the body, and don't allow the user to
// grab it. That'd require a bit more work :)
UI.WindowBegin("Interface", ref windowPose, new Vec2(0.15f, 0), UIWin.Body, UIMove.None);
// Some UI to fill up space
UI.Text("Here's a window that can be moved via a bar below the window!", TextAlign.Center);
UI.HSeparator();
UI.Button("Testing!");
// Save the size of the window before ending it. MUST be on a new line.
windowSize = new Vec2(UI.LayoutRemaining.x, UI.LayoutAt.y - UI.Settings.margin);
UI.WindowEnd();
// Show the window grab bar at its own location.
UI.Handle("GrabBar", ref grabBarPose, new Bounds(new Vec3(windowSize.x * 0.9f, 0.01f, 0.01f)), true, UIMove.FaceUser);
}
@maluoi
Copy link
Author

maluoi commented Mar 22, 2023

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment