Class TweakMenu
A floating control that switches the host Panel's theme and density.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class TweakMenu : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
Remarks
TweakMenu is a developer and design-review affordance: a gear button pinned to a corner of the screen that opens a menu of every App UI theme and every density step. Drop one into a sample, a test scene or a debug overlay and the whole panel restyles live, which is the fastest way to check a component under all eight themes and all three densities without rebuilding.
It writes straight through to the two context providers that matter, theme and density, so every descendant of the panel follows. On attach it reads the panel back, so the menu opens showing the state that is actually in effect rather than its own defaults.
The density axis is normal / compact / comfort. It is a design axis and is
unrelated to Platform.scaleFactor, which is display DPI.
This is not a user-facing preferences UI. It has no persistence of its own; if you want the choice to survive a session, listen to themeChanged and densityChanged and store it yourself.
Examples
Adding a tweak menu to a panel.
<ui:Panel theme="dark" density="normal">
<ui:TweakMenu />
</ui:Panel>
Persisting the choice.
var tweaks = new TweakMenu
{
theme = PlayerPrefs.GetString("theme", "dark"),
density = PlayerPrefs.GetString("density", "normal"),
};
tweaks.themeChanged += t => PlayerPrefs.SetString("theme", t);
tweaks.densityChanged += d => PlayerPrefs.SetString("density", d);
panel.Add(tweaks);
Constructors
TweakMenu()
Default constructor.
Declaration
public TweakMenu()
Fields
densities
Every density step the menu offers, in display order.
Declaration
public static readonly string[] densities
Field Value
| Type | Description |
|---|---|
| string[] |
menuUssClassName
The TweakMenu menu styling class.
Declaration
public const string menuUssClassName = "appui-tweakmenu__menu"
Field Value
| Type | Description |
|---|---|
| string |
themes
Every theme the menu offers, in display order.
Declaration
public static readonly string[] themes
Field Value
| Type | Description |
|---|---|
| string[] |
triggerUssClassName
The TweakMenu trigger button styling class.
Declaration
public const string triggerUssClassName = "appui-tweakmenu__trigger"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The TweakMenu main styling class.
Declaration
public const string ussClassName = "appui-tweakmenu"
Field Value
| Type | Description |
|---|---|
| string |
Properties
density
Declaration
[CreateProperty]
[UxmlAttribute]
public string density { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
densityRadioGroup
The density radio group.
Declaration
public MenuRadioGroup densityRadioGroup { get; }
Property Value
| Type | Description |
|---|---|
| MenuRadioGroup |
menu
The menu shown by the trigger.
Declaration
public Menu menu { get; }
Property Value
| Type | Description |
|---|---|
| Menu |
theme
Declaration
[CreateProperty]
[UxmlAttribute]
public string theme { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
themeRadioGroup
The theme radio group.
Declaration
public MenuRadioGroup themeRadioGroup { get; }
Property Value
| Type | Description |
|---|---|
| MenuRadioGroup |
trigger
The gear button that opens the menu.
Declaration
public IconButton trigger { get; }
Property Value
| Type | Description |
|---|---|
| IconButton |
Events
densityChanged
Raised when the density has changed.
Declaration
public event Action<string> densityChanged
Event Type
| Type | Description |
|---|---|
| Action<string> |
themeChanged
Raised when the theme has changed.
Declaration
public event Action<string> themeChanged
Event Type
| Type | Description |
|---|---|
| Action<string> |