Skip to content
NP Editor Docs
This is not the latest version — view the latest

Panel UI (NpUi)

NpUi is a small builder that describes panel content. The plugin only lists rows, and the editor draws them with controls that look the same as the built-in panels. You do not need to know Godot. NpUi is used in two places.

Registration pointFieldWhere it appears
AddContentTabBuildBottom area panel (open from the Window menu)
AddModePanelTool panel while in that mode
  1. At the start of Register, read the saved settings into fields. These become the panel’s initial values.

  2. After new NpUi(), chain rows such as .Title(…) · .Number(…) · .Button(…). Rows are laid out from top to bottom in the order you write them.

    private int _width = 3;
    private bool _lamps = true;
    private int _built;
    public void Register(INpEditorHost host)
    {
    _width = host.Settings.GetInt("width", 3); // read first so the field's initial value is correct
    _lamps = host.Settings.GetBool("lamps", true);
    host.AddContentTab(new NpContentTab("panel", "Road", () => new NpUi()
    .Title("Build road")
    .Number("Width", _width, 1, 9, 1, v => { _width = (int)v; host.Settings.SetInt("width", _width); })
    .Check("Street lamps", _lamps, v => { _lamps = v; host.Settings.SetBool("lamps", v); })
    .Label(() => $"Roads laid {_built} · world blocks {host.World.CountBlocks():N0}")
    .Separator()
    .Button("Lay in selection", () =>
    {
    if (host.World.Selection is not { } b) { host.Message("No selection"); return; }
    _built++;
    // … lay the road with World.Edit …
    }, "Lays a road on the floor of the selection box")));
    }
  3. Build, then click Reload (selected) in the Plugin Manager.

  4. In the Window menu, check the Road panel to open it. The panel opens in the bottom area.

    The Road panel open in the bottom area (Build road, Width 3, Street lamps, Roads laid 0 · world blocks 1,024, Lay in selection) and the checked Road item in the Window menu

  • Right-click the panel tab to move it to another area or a floating window. Move panels you use often to the right area.
  • Show changing values with Label(() => …). It is reread right after a button is clicked, so a value a button changed appears immediately.
  • Keep the results of heavy calculations in fields, and read only those fields in live text.
  • To keep a field’s value in sync with the settings, call host.Settings.Set… directly in the changed callback.

Every method returns the same NpUi, so you chain calls with ..

MethodWhat is drawnWhen the callback is called
Title(string text)Bold group title—
Label(string text)One line of text (wraps)—
Label(Func<string> text)Live text. Reread every 0.5 seconds while visible—
Button(string text, Action click, string tooltip = "")Buttonclick on click
Text(string label, string initial, Action<string> changed)Name + text fieldchanged every time a character is typed
Number(string label, double initial, double min, double max, double step, Action<double> changed)Name + number field (up/down buttons)changed every time the value changes
Check(string label, bool initial, Action<bool> changed)Checkboxchanged when toggled
Separator()Horizontal separator—

Label(() => …) calls the function again every 0.5 seconds while the panel is visible and updates the text.

  • It is also reread immediately when the panel becomes visible again and right after a button is clicked.
  • It is called every 0.5 seconds, so keep it light. Do not put calculations that scan the whole world (Bounds · Blocks()) in it. Show light values such as CountBlocks(), or values you keep in fields.
  • If the function throws, the plugin is isolated.
Registration pointWhen it is built
Build of AddContentTabOnce, when the plugin is enabled
Panel of AddModeOnce, when that mode panel is first shown

A panel, once built, is not rebuilt. So initial for Number · Text · Check is the value at the moment it is built. If code changes the value later, the field does not follow, so show changing values with Label(() => …).

  • Do not put emoji or pictographic characters in on-screen text. Pictographic characters in the panel title (NpContentTab.Label) are stripped on screen.
  • Callbacks (click · changed) are called on the editor main thread. You can call World.Edit from them.
  • If a callback throws, the plugin is isolated, and the panel disappears as the plugin is unloaded.
  • Icon buttons, collapsible groups, lists and color pickers are not available.
  • Plugin text that is not in the editor’s translation table is not translated and appears as written. If you need multiple languages, the plugin chooses the text itself.