From 592a4a0cc315d0441e1df926d8d3d09c655f02ea Mon Sep 17 00:00:00 2001 From: Ben MacKinnon Date: Tue, 17 Nov 2026 12:41:07 +0000 Subject: [PATCH 1/5] Initial reimplementation of the RangeSlider # Unity UI Toolkit Extensions - Pull Request ## Overview Adds **RangeSlider**, a UI Toolkit port of the uGUI Extensions `RangeSlider` (originally contributed via [Dover8/Unity-UI-Extensions#1](https://github.com/Dover8/Unity-UI-Extensions/pull/1)). It's a two-handled horizontal slider that selects a low and a high value between a min and max, e.g. for filtering search results by price or size. ```xml ``` ```csharp var priceFilter = new RangeSlider(minValue: 0, maxValue: 1000, lowValue: 250, highValue: 750, wholeNumbers: true); priceFilter.OnValueChanged += (low, high) => ApplyPriceFilter(low, high); // or the standard UI Toolkit way: priceFilter.RegisterValueChangedCallback(evt => ApplyPriceFilter(evt.newValue.x, evt.newValue.y)); ``` ### Why not use UI Toolkit's `MinMaxSlider`? UI Toolkit has a runtime `MinMaxSlider` (`UnityEngine.UIElements`, under *Standard* in the UI Builder library). It's a different control from IMGUI's editor-only `EditorGUI.MinMaxSlider`. It covers the basics, including dragging the whole range, but it falls short for filtering UIs like this one: - **Float values only.** It has no whole-number option and there's no integer version, so filters like price, bedrooms or year need rounding in user code. RangeSlider has `whole-numbers`, which snaps handle drags, range drags and keyboard steps. - **Basic default look.** It ships as a labelled form field with thin, editor-style thumbs. RangeSlider is a standalone control styled like the rest of this library, with round touch-friendly handles, and can be re-themed through `--rangeSlider-*` custom properties. It has no built-in label, so add a `Label` next to it if needed. - **Same API as the uGUI version.** RangeSlider keeps the uGUI Extensions names (`MinValue`/`MaxValue`/`LowValue`/`HighValue`, `OnValueChanged(low, high)`), which makes moving from the uGUI package easy. Like `MinMaxSlider`, it also raises `ChangeEvent`, so switching between the two is straightforward. ## Changes - `Runtime/Controls/RangeSlider/RangeSlider.cs` - the new `[UxmlElement]` control (namespace `UnityUIToolkit.Extensions`). - Keeps the uGUI API: `MinValue`, `MaxValue`, `LowValue`, `HighValue`, `WholeNumbers`, `NormalizedLowValue`, `NormalizedHighValue`, `SetValueWithoutNotify(low, high)`, `OnValueChanged(low, high)`. - Interaction states follow the original (Low / High / Bar): drag a handle, or drag the fill to move the whole range. - Also implements `INotifyValueChanged`, so `value`, `RegisterValueChangedCallback` and bubbling `ChangeEvent` work like the built-in fields. - UXML attributes: `min-value`, `max-value`, `low-value`, `high-value`, `whole-numbers`. - `Runtime/Styles/UIToolkitExtensionsControlStyles.uss` - `rangeSlider` styles (BEM classes exposed as constants), themeable via `--rangeSlider-*` custom properties. - `Editor/UIToolkitExtensionsMenuOptions.cs` + `Editor/ControlTemplates/RangeSliderStarter.uxml` - `GameObject/UI Toolkit/Extensions/Range Slider` and `Assets/Create/UI Toolkit/Extensions/Range Slider Starter`. - `CHANGELOG.md` (new Unreleased section), `README.md` (control count 25 -> 26), `Documentation~` control list. ### Behaviour changes compared with the uGUI version - **Fixed:** `SetValueWithoutNotify(low, high)` clamped the new low against the *old* high. For example, going from 10..12 to (20, 80) gave 12..80. - **Fixed:** a bar drag re-centred the range on the pointer (it jumped on the first move). It also moved low before high, so a fast drag could collapse the range. It now moves both ends by the drag distance and keeps the range size. - **Fixed:** when both handles overlapped at the max, only the high handle could be grabbed, so the range was stuck. Now the first drag direction decides which handle moves. - **New:** pressing the track outside the range jumps the nearest handle there and keeps dragging it. The original ignored these presses. - **New:** keyboard / gamepad support. Tab to a handle, then left/right steps it (1 for whole numbers, otherwise 10% of the range, as the original `StepSize`). The uGUI version left `OnMove` unimplemented. - **New:** if low/high sits on the min/max when that limit changes, it follows the new limit, so a full-range selection stays full. This also lets UXML set `min-value`/`max-value` then `low-value`/`high-value` without the values being clamped to the default 0..1 range first. ## Breaking Changes - None. This only adds a new control. ## Related Submodule Changes - None yet. A RangeSlider sample scene for `com.unity.uitoolkitextensions.examples` can follow in a separate PR. ## Testing status * No tests have been added (the package has no test assembly yet). ### Manual testing status - To do in the Unity Editor (6000.0): compile, add via `GameObject/UI Toolkit/Extensions/Range Slider`, check it in UI Builder and Play Mode: - drag each handle; drag the fill; press the track either side of the range; overlap both handles at min and at max, then drag each way; - toggle `whole-numbers`; change `min-value`/`max-value` in UI Builder; tab to the handles and use the arrow keys; disable the element with `SetEnabled(false)`. --- CHANGELOG.md | 11 + .../com.unity.uitoolkiyextensions.md | 1 + .../ControlTemplates/RangeSliderStarter.uxml | 6 + .../RangeSliderStarter.uxml.meta | 10 + Editor/UIToolkitExtensionsMenuOptions.cs | 6 + README.md | 2 +- Runtime/Controls/RangeSlider.meta | 8 + Runtime/Controls/RangeSlider/RangeSlider.cs | 565 ++++++++++++++++++ .../Controls/RangeSlider/RangeSlider.cs.meta | 2 + .../UIToolkitExtensionsControlStyles.uss | 56 ++ 10 files changed, 666 insertions(+), 1 deletion(-) create mode 100644 Editor/ControlTemplates/RangeSliderStarter.uxml create mode 100644 Editor/ControlTemplates/RangeSliderStarter.uxml.meta create mode 100644 Runtime/Controls/RangeSlider.meta create mode 100644 Runtime/Controls/RangeSlider/RangeSlider.cs create mode 100644 Runtime/Controls/RangeSlider/RangeSlider.cs.meta diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a44199..235d871 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/). +## Unreleased + +### Added + +- **RangeSlider** - Two-handled slider that selects a low and high value between a min and max, e.g. for filtering search results by a price or size range. A UI Toolkit port of the uGUI Extensions `RangeSlider`, supporting whole-number snapping, dragging the range between the handles, keyboard / gamepad navigation, and `ChangeEvent` / `RegisterValueChangedCallback` notifications alongside the `OnValueChanged(low, high)` event. +- **Range Slider editor menu entries** - `GameObject/UI Toolkit/Extensions/Range Slider` and `Assets/Create/UI Toolkit/Extensions/Range Slider Starter`, with a starter template. + +### Contributors + +[@Dover8](https://github.com/Dover8) + ## Release 1.0.0 - Launch - 2026/09 The first release of **Unity UI Toolkit Extensions** - a brand-new companion to the long-running uGUI Extensions library, built from the ground up for Unity 6 and the UI Toolkit (UITK) system. diff --git a/Documentation~/com.unity.uitoolkiyextensions.md b/Documentation~/com.unity.uitoolkiyextensions.md index c4d5425..7b42780 100644 --- a/Documentation~/com.unity.uitoolkiyextensions.md +++ b/Documentation~/com.unity.uitoolkiyextensions.md @@ -49,6 +49,7 @@ For a full list of the controls and how they are used, please see the [online do - **IconLabelButton** — Row button with a 24 × 24 icon and label, ideal for menu items and list actions. - **DropDownControl** — Custom dropdown selector with a scrollable list of selectable entries. - **SocialLinkContainer** — Editable list of platform-labelled social-link fields with add/remove and a platform picker. +- **RangeSlider** — Two-handled slider selecting a low and high value between a min and max, with whole-number snapping and draggable range. ### Media & Images diff --git a/Editor/ControlTemplates/RangeSliderStarter.uxml b/Editor/ControlTemplates/RangeSliderStarter.uxml new file mode 100644 index 0000000..bdb0c8d --- /dev/null +++ b/Editor/ControlTemplates/RangeSliderStarter.uxml @@ -0,0 +1,6 @@ + +