-
Notifications
You must be signed in to change notification settings - Fork 112
/
DemoUIGrabBar.cs
53 lines (44 loc) · 2.08 KB
/
DemoUIGrabBar.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// SPDX-License-Identifier: MIT
// The authors below grant copyright rights under the MIT license:
// Copyright (c) 2019-2023 Nick Klingensmith
// Copyright (c) 2023 Qualcomm Technologies, Inc.
using StereoKit;
class DemoUIGrabBar : ITest
{
string title = "UI Grab Bar";
string description = "This is an example of using external handles to manipulate a Window's pose! Since _you_ own the Pose data, you can do whatever you want with it!\nThe grab bar below the window is a common sight to see in recent XR UI, so here's one way to replicate that with SK's API.";
public void Initialize()
{
}
public void Shutdown()
{
}
public void Step()
{
Tests.Screenshot("UIGrabBarWindow.jpg", 1, 400, 400, 90, grabBarPose.position + V.XYZ(0, 0.06f, 0.12f), grabBarPose.position + V.XYZ(0, 0.06f, 0));
GrabBarWindow();
Demo.ShowSummary(title, description, new Bounds(V.XY0(0, -0.04f), V.XYZ(.2f, .2f, 0)));
}
Pose grabBarPose = (Demo.contentPose * Matrix.T(0,-0.1f,0)).Pose;
Vec2 windowSize = Vec2.Zero; // First frame will not be in the right spot unless we know window size in advance.
public void GrabBarWindow()
{
// 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);
}
}