|
2 | 2 | title: Quick Start |
3 | 3 | slug: quick-start |
4 | 4 | sections: |
5 | | - - Why Roots? |
6 | | -icon: handshake |
| 5 | + - Installation |
| 6 | + - Setup |
| 7 | + - Loading Assets |
| 8 | + - Responsive Style Sheets |
| 9 | + - Utilities |
| 10 | + - Samples |
| 11 | +icon: download |
7 | 12 | --- |
8 | 13 |
|
9 | | -Roots is a UI toolkit built on top of [Rish](/docs/rish/quick-start). Rish is very thin and provides no elements out of the box. Roots is a great foundation for your UI app. |
| 14 | +Roots is a UI toolkit built on top of [Rish](/docs/rish/quick-start). Rish is very thin and provides virtually no elements out of the box. Roots provides actual building blocks to get your application running immediately. |
| 15 | + |
| 16 | +#### What’s Included? |
| 17 | +- **Layout Components:** Robust, responsive solutions for structural UI. |
| 18 | +- **Foundational Elements:** Low-level, abstract building blocks. |
| 19 | +- **Utilities:** Helper classes and methods to streamline development. |
| 20 | +- **High-level Elements:** Optional reference elements to use as a starting point. |
| 21 | + |
| 22 | +<div class="callout-block callout-block-note"> |
| 23 | + <div class="content"> |
| 24 | + <h4 class="callout-title"><i class="fa-solid fa-circle-info"></i>Note</h4> |
| 25 | + <p>Roots takes inspiration from established frameworks like Bootstrap but introduces custom approaches for Unity-specific challenges, such as tooltips and dropdowns.</p> |
| 26 | + </div> |
| 27 | +</div> |
| 28 | + |
| 29 | +## Installation |
| 30 | +Installing Roots is simple. You can add the package via the Unity Package Manager using the Git URL, or by modifying your `manifest.json` file directly. |
| 31 | + |
| 32 | +Add the following package URL: `https://github.com/clockworklabs/roots#[target-version]`. |
| 33 | + |
| 34 | +### Dependencies |
| 35 | +Roots requires the following dependencies to function correctly: |
| 36 | +- [Rish](/docs/rish/quick-start): `io.clockworklabs.rish` (version `3.0.0+`). |
| 37 | +- [Motion](https://github.com/clockworklabs/motion): `io.clockworklabs.motion` (version `1.7.9+`). |
10 | 38 |
|
11 | 39 | ## Setup |
| 40 | +To initialize the Roots ecosystem, add the following to the GameObject containing your `RishRoot`: |
| 41 | +1. **`RootsSetup`:** Required for `ResponsiveStyleSheets`. |
| 42 | +2. **`AssetsLoader`:** An abstract bridge to your asset pipeline. |
| 43 | + - Roots includes a `ResourcesLoader` for quick prototyping, but you should implement a custom version for production pipelines (Addressables, etc.). |
| 44 | + |
| 45 | +If you plan to use animated elements (like `MotionDiv`), you also need a `MotionAutoUpdate` component in your project. You can skip this if you prefer to manually call `DoMotion.Step`. |
| 46 | + |
| 47 | +## Responsive Style Sheets |
| 48 | +Roots introduces a system similar to CSS `min-width` media queries, allowing you to stack USS files based on screen width. |
| 49 | + |
| 50 | +1. **Create:** Go to `Create -> Roots -> ResponsiveStyleSheet`. |
| 51 | +2. **Configure:** Add pairs of <strong>Min Width</strong> (`int`) and <strong>Style Sheet</strong> (`StyleSheet`). |
| 52 | + - `min-width <= 0`: The stylesheet is always loaded. |
| 53 | + - `min-width > 0`: Loaded only when screen width ≥ value. |
| 54 | +3. **Include:** Add the `ResponsiveStyleSheet` to your `RootsSetup` component. |
| 55 | + |
| 56 | +Higher `min-width` sheets should be used to override styles defined in the "base" (0) or lower `min-width` sheets. |
| 57 | + |
| 58 | +<figure> |
| 59 | + <figcaption>styles-xs.uss (min-width: 0)</figcaption> |
| 60 | +{% highlight css %} |
| 61 | +.example { |
| 62 | + margin: 8px; |
| 63 | +} |
| 64 | +{% endhighlight %} |
| 65 | +</figure> |
| 66 | + |
| 67 | +<figure> |
| 68 | + <figcaption>styles-lg.uss (min-width: 1024)</figcaption> |
| 69 | +{% highlight css %} |
| 70 | +.example { |
| 71 | + margin: 30px; |
| 72 | +} |
| 73 | +{% endhighlight %} |
| 74 | +</figure> |
| 75 | + |
| 76 | +`ResponsiveStyleSheets` are also convenient to pack style sheets together, even if you don't need responsive logic. You can just leave all the `min-size` as 0. |
| 77 | + |
| 78 | +<div class="callout-block callout-block-danger"> |
| 79 | + <div class="content"> |
| 80 | + <h4 class="callout-title"><i class="fa-solid fa-circle-info"></i>Style Overrides</h4> |
| 81 | + <p>Roots appends these style sheets on top of those handled by <code>RishRoot</code>. Ensure your selectors account for this override order.</p> |
| 82 | + </div> |
| 83 | +</div> |
| 84 | + |
| 85 | +## Utilities |
| 86 | +### Resolved Language Direction |
| 87 | +`VisualElements` have a `languageDirection` property of type `public enum LanguageDirection{ Inherit, LTR, RTL }`. But when the value is `Inherit`, we don't know what the language direction is. Roots adds the `GetResolvedLanguageDirection` extension method which resolves the inherited directionlity. |
| 88 | + |
| 89 | +### Style |
| 90 | +Roots provides chain extension methods to set up inline `style`. |
| 91 | + |
| 92 | +{% highlight csharp %} |
| 93 | +Div.Create( |
| 94 | + style: StyleUtilites |
| 95 | + .FlexRow(). |
| 96 | + .AlignItemsCenter() |
| 97 | + .Padding(16, 8) |
| 98 | + children: H3.Create(text: "Hello World")); |
| 99 | +{% endhighlight %} |
| 100 | + |
| 101 | +As always, the rule of favoring USS class names and style sheets over inline styling still apply, but these chain methods sometimes come handy. |
12 | 102 |
|
| 103 | +### Vector Swizzling |
| 104 | +We found ourselves needing to swizzle vector components all the time. So we created a bunch of extension methods just for that purpose and pack it as part of Roots. |
13 | 105 |
|
| 106 | +{% highlight csharp %} |
| 107 | +var vec0 = new Vector4(1, 2, 3, 4); // (1, 2, 3, 4) |
| 108 | +var vec1 = vec0.sXY(); // (1, 2) |
| 109 | +var vec2 = vec0.sX0Y(); // (1, 0, 2) |
| 110 | +var vec3 = vec0.sZWWX(); // (3, 4, 4, 1) |
| 111 | +{% endhighlight %} |
14 | 112 |
|
| 113 | +## Samples |
| 114 | +Roots comes with samples showing a wide range of UI Elements (from simple buttons to complex scroll views or responsive layouts). |
15 | 115 |
|
16 | | -It provides |
17 | | -- Unity Components to structure and setup your Rish App. |
18 | | -- Low-level abstract elements. |
19 | | -- High-level reference or starting-point elements. |
| 116 | +1. Open the **Package Manager**. |
| 117 | +2. Select the **Roots** package. |
| 118 | +3. Go to the **Samples** tab and import **Rootstrap** and **Samples**. |
| 119 | +4. Open the newly imported `Samples` scene and enter Play Mode. |
20 | 120 |
|
| 121 | +Each sample is contained in a resizable container and has a "View Code" button to easily explore the code. |
0 commit comments