Skip to content
SheetForge

Authoring surfaces

A declarative authoring surface describes Data Studio UI as data. One registration is drawn by the Unity editor and by the browser alike. This page covers how to register surfaces, the vocabulary they use, and the rules they follow. The contract is opt-in.

Why surfaces are data

The graph widgets, inspector actions and custom cell widgets in Studio extensions hand back a VisualElement. That is why they are editor-only. The browser cannot load a UIToolkit type, so an extension written that way exists on one screen and not the other.

This contract answers the same needs as data. You describe the shell: an id, a label key, a placement and a tone. You supply only the predicate and the effect as delegates.

The editor's UIToolkit renderer and the browser's React renderer then draw that one registration.

Register surfaces

Implement ISheetForgeStudioPlugin and add each surface to the StudioUiRegistry.

using SheetForge.Core.Plugins;
using SheetForge.Core.Studio;
using SheetForge.Core.Theming;   // ThemeColorSlot — tones are slots, never hard-coded colours
 
public sealed class ExampleStudioUi : ISheetForgeStudioPlugin
{
    public void RegisterStudioUi(StudioUiRegistry ui)
    {
        // ① A verb — right-click a row, and this appears at the end of the menu.
        ui.AddAction(new StudioActionDescriptor(
            "skillsDemo.setBrake",                        // unique id ("pack.verb" reads well)
            ExampleLocStrings.BrakeActionKey,             // a Loc key (§4.14); unregistered = shown verbatim
            StudioActionPlacement.RowContextMenu,
            ctx => ctx.Tab == "ExampleActions" && !string.IsNullOrEmpty(ctx.RecordId),   // cheap predicate
            ctx => ctx.StageCell(ctx.Tab, ctx.RecordId, "brakeSeconds", "0.25")));
 
        // ② A summary panel — a node tree, rebuilt each recompute tick.
        ui.AddPanel(new StudioPanelDescriptor("skillsDemo.summary", ExampleLocStrings.PanelTitleKey, ctx =>
            StudioUiNode.List(
                StudioUiNode.Heading("Cast summary"),
                StudioUiNode.KeyValue("Total damage", TotalDamage(ctx).ToString()),
                StudioUiNode.Progress("Cast time", CastRatio(ctx), ThemeColorSlot.Accent),
                StudioUiNode.Button("Fill every unbraked reaction", "skillsDemo.fillBrakes"))));
 
        // ③ A column badge — one node beside a column header (null = nothing on that column).
        ui.AddColumnBadge(new StudioColumnBadgeDescriptor((ctx, tab, field) =>
            field == "brakeSeconds" ? StudioUiNode.Badge(UnbrakedCount(ctx) + " unbraked", ThemeColorSlot.Warning) : null));
 
        // ④ A cell-editor hint — pick a built-in widget for your type without writing one.
        ui.AddCellEditorHint(new StudioCellEditorHint("Modifier", StudioCellEditorArchetype.Dropdown, Options));
    }
}
CallWhat it adds
AddActionA verb. The sample's verb appears at the end of the menu when you right-click a row
AddPanelA summary panel. It is a node tree, rebuilt each recompute tick
AddColumnBadgeOne node beside a column header. Return null for nothing on that column
AddCellEditorHintA built-in widget for your type, without writing one

An action's id must be unique. The form "pack.verb" reads well.

The label is a Loc key. An unregistered key is shown verbatim. To register it, see Theming and strings.

Tones are ThemeColorSlot values, never hard-coded colors.

The vocabulary

The vocabulary is deliberately bounded. It grows only by appending, never by inserting, so an existing registration keeps its meaning.

Action placements

An action has five placements: Inspector, RowContextMenu, TopbarMenu, ColumnHeaderMenu and CanvasNodeMenu.

Each placement fills the context with what is known at that place and leaves the rest empty. Every placement carries the tab.

PlacementThe context carries
Inspector (the node inspector)The active tab only
RowThe record
TopbarThe active tab only
ColumnThe column name
CanvasThe node's record

Guard before you read a field that your placement does not supply.

Node kinds

A panel or a badge is built from thirteen node kinds: Row, Label, Chip, Badge, Button, Rule, Heading, KeyValue, Table, List, Progress, Input and Link.

Nodes are built through static factories, such as StudioUiNode.Label(…) and .WithTooltip(…). A node is therefore immutable, and only the fields that mean something for its kind are set.

Cell-editor archetypes

A cell-editor hint picks one of seven archetypes.

  • Dropdown. You supply the candidates.
  • MultilineText.
  • Slider. You supply the range.
  • Toggle. You supply the two canonical texts.
  • ColorPicker (#RRGGBB / #RRGGBBAA).
  • CurveEditor and GradientEditor. The cell text is the canonical curve or gradient notation.

Visual types defines the curve and gradient notation. A plugin whose own type writes that notation may declare CurveEditor or GradientEditor. It can write the notation through CurveValue.Render(), for example.

The Plugin Demo's Falloff type does exactly that. Its parser reads the cell with CurveValue.TryParse. One hint registration gives it the curve editor in Unity and in the browser.

Built-in visual types

The built-in Color, AnimationCurve and Gradient types are wired through the very same mechanism. BuiltinCellEditorHints holds their three hints.

A host consults a plugin's registrations first. Registering a hint under one of those type names therefore overrides the built-in choice. It is not refused.

The last three archetypes are drawn the same way on both hosts.

HostColorPicker, CurveEditor, GradientEditor
Unity editorThe web app's color, curve and gradient editors, drawn inside the Data Studio
BrowserThe app's own editors

A List<> of a type carrying one of them becomes a chip editor in both.

No layout numbers

There are no layout numbers anywhere. Pixels and ratios would leak one screen's grain into the other. You say what to show, and each renderer decides how to place it.

Rules for surfaces

Read these rules before you write a surface.

Actions stage edits

An action changes data the same way your own edits in the Data Studio do. StudioSurfaceContext gives an action exactly four powers:

  • StageCell
  • StageCells, which stages several cells as one Undo step, all-or-nothing
  • FocusRecord
  • RequestRebuild

The powers come on top of the read-only Tables, References and CodeRegistries.

A plugin's verb is therefore an ordinary staged edit. It is one Ctrl+Z step. Nothing reaches the sheet until you reflect, which writes the staged edits to the source. The same pre-flight applies.

The staging gate applies too. A read-only source, a running pipeline or an xlsx-backed tab blocks the edit, with the reason shown. When editing is blocked lists each case.

Keep predicates cheap

Predicates run constantly. AppliesTo, panel building and badge provision run on every gesture and every recompute tick.

Read the snapshot you were handed. Do no IO, no network access and no long computation.

The predicate is checked again on invocation

The host re-checks the predicate at invocation. If the situation changed since the menu was drawn, the answer is a no-op plus a redraw, not a second failure. The browser does the same for a stale id.

Ask before running

ConfirmKey asks first. Give an action a confirmation key, and the host shows that sentence before running the action. That is the right thing for a verb that stages many cells at once.

A Link node opens http and https only. The rule is one Core predicate, StudioUiNode.IsAllowedUrl, that both hosts ask. The hosts therefore cannot disagree about what is safe to open.

The browser then re-checks the same shape before it renders an anchor. That check can only refuse more, never less.

The url is stored exactly as you wrote it. It is refused at the opening end with a reason. It is not scrubbed at registration time, because the plugin that wrote it should be able to find out why nothing happened.

Panels hold no state

Panels are rebuilt each tick. The only place a value belongs is the sheet, as a staged edit.

If nothing registers a panel, the pane is not drawn at all.

When a surface throws

A throw becomes an English console warning. It removes that one affordance, not the window.

Paint a panel yourself

Arbitrary rendering, composite input and multi-step flows have no vocabulary here. A vocabulary for them would grow into a whole UI framework to maintain, so the vocabulary stops short of them. The editor offers a way past that limit instead.

When description is not enough, implement IStudioPanelProvider in your editor companion assembly and paint whatever you like. The interface belongs to the Editor assembly.

using SheetForge.Editor.Studio;
using UnityEngine.UIElements;
 
public sealed class ExampleStudioPanel : IStudioPanelProvider
{
    public string Id => "skillsDemo.summary";        // same id as the descriptive panel above
    public string TitleKey => ExampleLocStrings.PanelTitleKey;
    public bool AppliesTo(StudioSurfaceContext context) => context.Tab == "ExampleSkills";
    public VisualElement CreatePanel(StudioSurfaceContext context) => new Label("…anything…");
}

Pair a rich panel with a declarative one

Register both panels under the same Id, and each host takes what it can draw. The editor uses the rich one. The browser uses the declarative one.

So the browser shows what the declarative panel can say, and the editor shows the rich panel, without a second set of contracts.

There is no web-only variant. A missing rich panel means that the declarative one is drawn, not that the panel disappears.

The element lives one recompute tick, so it holds no state either.

Next steps