EditorAPI editor only

Everything a script module may call to extend the editor: tool windows, menu entries, widgets, a drawing canvas, drag and drop, and component access. One header, editor/src/api/EditorAPI.h, compiled into GameScripts.dll with the rest of your scripts. The Editor Windows guide explains the why; this page is the list.

#include "api/EditorAPI.h"
#include "ui/IconsFontAwesome5.h"
using namespace Thread::EditorAPI;

namespace {
    void Draw() {
        if (Thread::Entity e = PrimarySelection()) UI::LabelValue("Selected", EntityName(e));
    }
    EditorWindowRegisterer s_Win{ EditorWindowDesc{ .Id = "mymod.tool", .Title = "My Tool", .Draw = &Draw } };
    MenuItemRegisterer s_Menu{ MenuItemDesc{ .Id = "mymod.open", .Path = "Tools/My Tool",
                                             .Action = [] { FocusWindow("mymod.tool"); } } };
}
From editor code (not a script module), the same two things are EditorPanelRegistry::Register (editor/src/EditorPanelRegistry.h) and EditorMenuRegistry::RegisterItem / RegisterMenu (editor/src/EditorMenuRegistry.h), with full ImGui available.

Windows

CallReturnsWhat it does
RegisterWindow(EditorWindowDesc)boolAdds a tool window. False (with a log line) for an empty or duplicate id or a missing Draw.
UnregisterWindow(id)voidWithdraws a window this module registered. Never touches the editor's own.
IsWindowOpen(id) / SetWindowOpen(id, open)bool / voidRead or set whether it is open.
FocusWindow(id)voidOpen it and bring it to the front.
EditorWindowRegisterer{ desc }structStatic object: registers in its constructor, withdraws in its destructor as the module unloads.

An entry is a path: "Tools/My Module/Bake". Menus and submenus it names are created on demand; a new top-level menu lands between Project and Help. "File/…" appends to the editor's own menus.

CallReturnsWhat it does
RegisterMenuItem(MenuItemDesc)boolAdds an entry. Fields: Id, Path, Icon, Shortcut (display only), Tooltip, Order, Action, optional IsChecked / IsEnabled.
UnregisterMenuItem(id)voidWithdraws an entry this module registered.
MenuItemRegisterer{ desc }structStatic lifetime, like the window registerer.

Text and layout

CallReturnsWhat it does
UI::Text / TextWrapped / TextDisabled / BulletText(text)voidText — never treated as a format string.
UI::TextColored(r, g, b, a, text)voidColoured text.
UI::LabelValue(label, value)void"Label value", aligned like the inspector.
UI::Separator / SeparatorText(label) / SpacingvoidRules and spacing.
UI::SameLine(offset, spacing) / Indent / Unindent / Dummy(w, h)voidPlacement.

Containers

Each takes its contents as a callback, so a Begin can never be left without its End.

CallReturnsWhat it does
UI::Section(label, body, defaultOpen = true)boolCollapsing header.
UI::Tree(label, body)boolTree node.
UI::Child(id, w, h, border, body)voidScrolling child region.
UI::Group(body) / Disabled(disabled, body)voidGroup, greyed-out block.
UI::WithId(id, body)voidMakes widgets with the same label distinct — use in every list loop.
UI::TabBar(id, body) / TabItem(label, body)voidTabs.
UI::Table(id, headers, body) + TableRow() / TableColumn()void / boolTable; walk cells with TableRow then TableColumn.

Input widgets

Each returns true on the frame the value changed, and writes through the reference.

CallReturnsWhat it does
UI::Button(label, w, h) / SmallButton(label)boolClicked this frame.
UI::Selectable(label, selected)boolSelectable row.
UI::Checkbox(label, bool&)boolCheckbox.
UI::InputText / InputTextMultiline(label, std::string&)boolText input.
UI::DragFloat / DragFloat3 / SliderFloat / DragIntboolNumbers. DragFloat3 takes &vec.x.
UI::Combo(label, int& index, items)boolDrop-down list.
UI::ColorEdit3 / ColorEdit4(label, float*)boolColour picker.
UI::Tooltip(text) / IsItemHovered() / IsItemClicked()void / boolAbout the item drawn just before.
UI::Notify(level, title, message, ms)voidCorner toast: Info, Success, Warning, Error.

Images and plots

CallReturnsWhat it does
UI::Image(assetPath, w = 0, h = 0)boolTexture by project path. Loads in the background behind a same-size placeholder; 0 keeps the aspect. True once loaded.
UI::ImageButton(id, assetPath, w, h)boolAn image that is a button.
UI::ProgressBar(fraction, w = 0, overlay = "")void0..1; empty overlay shows the percentage.
UI::PlotLines / PlotHistogram(label, values, h, min, max, overlay)voidmin/max 0/0 fit the values.

Canvas and Draw

A reserved rectangle with its own coordinates: (0,0) is its top-left corner. Draw:: calls draw into it, clipped; outside a canvas body they draw nothing and log one warning.

CallReturnsWhat it does
UI::Canvas(id, w, h, body(const CanvasInput&))voidw = 0 takes the width, h = 0 is 200 px.
CanvasInputstructWidth, Height, MouseX/Y, DragX/Y, Wheel, Hovered, Active, Clicked[3], Down[3], Released[3], DoubleClicked.
UI::Color{ R, G, B, A = 1 }structColour for every Draw:: call.
Draw::Line / Rect / RectFilledvoidLines and rectangles (rounding, thickness).
Draw::Circle / CircleFilled / TriangleFilledvoidShapes.
Draw::Polyline(xy, colour, closed, thickness)voidxy = x0, y0, x1, y1, …
Draw::Bezier(…)voidCubic Bézier curve.
Draw::Text(x, y, colour, text, size = 0)voidText; size 0 is the UI font size.
Draw::Image(assetPath, x0, y0, x1, y1, tint)voidTexture into a rectangle.

Drag and drop

The editor's own payloads, so your widgets trade with the Content Browser, the hierarchy, the inspector and the viewport. Each acts on the item drawn just before it.

CallReturnsWhat it does
UI::AssetDropTarget(AssetType = None)std::stringThe dropped project path, or "". None accepts any asset.
UI::AssetDragSource(assetPath)voidMakes the item draggable as that asset.
UI::EntityDropTarget()EntityA hierarchy row dropped this frame, or an invalid Entity.
UI::EntityDragSource(Entity)voidMakes the item draggable as that entity.

Reference fields

CallReturnsWhat it does
UI::AssetField(label, std::string& path, AssetType)boolThe inspector's asset row: drop target, picker with thumbnails, clear.
UI::EntityField(label, Entity&)boolSearchable entity list, drop target, clear, select-it.

Editor context

The scene can be null and the selection empty on any frame — check, do not assume.

CallReturnsWhat it does
ActiveScene() / ScenePath() / IsPlaying()Scene* / string / boolThe open scene.
Selection() / PrimarySelection()vector / EntityWhat is selected; the primary is the one the inspector shows.
Select(Entity) / ClearSelection()voidReplace / clear the selection.
EntityName / SetEntityNamestring / voidNames, through the editor.
CreateEntity(name) / DestroyEntity(Entity)Entity / voidDone by the editor; wrap in Edit to undo.

Components

By name, through the scene serializer's registry; values as YAML — the same text as in a .thread file. Rotation is in radians.

CallReturnsWhat it does
ComponentNames()vector<string>Every registered component.
ComponentsOf(Entity)vector<string>The ones this entity has.
HasComponent / AddComponent / RemoveComponent(e, name)boolPresence. Add is false for an unknown name.
GetComponent(e, name)std::stringThe component as a YAML map, or "".
PatchComponent(e, name, yaml)boolWrites only the keys given; the rest stays.
GetComponentField / SetComponentField(e, name, field[, value])string / boolOne key, as YAML text: "5", "[1, 2, 3]", "true".
GetTransform / SetTransform(e, t, r, s)boolThe transform (not in the registry).

Undo

CallReturnsWhat it does
Edit (RAII) / BeginEdit() / CommitEdit()struct / voidOne undo step. Use this, never Thread::ScopedEdit from a module.
HostApiVersion() / kApiVersionintChecked by the registerers; a mismatch refuses to register.

See also

Editor Windows · Scripts & IDE Workflow · Native Scripting

EditorAPI tylko edytor

Wszystko, co moduł skryptów może wywołać, żeby rozszerzyć edytor: okna narzędziowe, pozycje menu, widgety, canvas do rysowania, drag & drop i dostęp do komponentów. Jeden nagłówek, editor/src/api/EditorAPI.h, kompilowany do GameScripts.dll razem z resztą skryptów. Przewodnik Okna edytora wyjaśnia dlaczego; ta strona to lista.

#include "api/EditorAPI.h"
#include "ui/IconsFontAwesome5.h"
using namespace Thread::EditorAPI;

namespace {
    void Draw() {
        if (Thread::Entity e = PrimarySelection()) UI::LabelValue("Selected", EntityName(e));
    }
    EditorWindowRegisterer s_Win{ EditorWindowDesc{ .Id = "mymod.tool", .Title = "My Tool", .Draw = &Draw } };
    MenuItemRegisterer s_Menu{ MenuItemDesc{ .Id = "mymod.open", .Path = "Tools/My Tool",
                                             .Action = [] { FocusWindow("mymod.tool"); } } };
}
Z kodu edytora (nie z modułu skryptów) te same dwie rzeczy to EditorPanelRegistry::Register (editor/src/EditorPanelRegistry.h) oraz EditorMenuRegistry::RegisterItem / RegisterMenu (editor/src/EditorMenuRegistry.h), z pełnym ImGui.

Okna

WywołanieZwracaCo robi
RegisterWindow(EditorWindowDesc)boolDodaje okno narzędziowe. False (z linią w logu) dla pustego lub zdublowanego id albo braku Draw.
UnregisterWindow(id)voidWycofuje okno zarejestrowane przez ten moduł. Nigdy nie rusza okien edytora.
IsWindowOpen(id) / SetWindowOpen(id, open)bool / voidOdczyt / ustawienie, czy jest otwarte.
FocusWindow(id)voidOtwiera i wysuwa na wierzch.
EditorWindowRegisterer{ desc }structObiekt statyczny: rejestruje w konstruktorze, wycofuje w destruktorze przy wyładowaniu modułu.

Pozycja to ścieżka: "Tools/My Module/Bake". Menu i podmenu, które wskazuje, powstają same; nowe menu główne ląduje między Project a Help. "File/…" dopisuje do menu edytora.

WywołanieZwracaCo robi
RegisterMenuItem(MenuItemDesc)boolDodaje pozycję. Pola: Id, Path, Icon, Shortcut (tylko napis), Tooltip, Order, Action, opcjonalnie IsChecked / IsEnabled.
UnregisterMenuItem(id)voidWycofuje pozycję zarejestrowaną przez ten moduł.
MenuItemRegisterer{ desc }structCzas życia statyczny, jak rejestrator okna.

Tekst i układ

WywołanieZwracaCo robi
UI::Text / TextWrapped / TextDisabled / BulletText(text)voidTekst — nigdy nie jest traktowany jako format.
UI::TextColored(r, g, b, a, text)voidKolorowy tekst.
UI::LabelValue(label, value)void„Etykieta wartość”, wyrównane jak w inspektorze.
UI::Separator / SeparatorText(label) / SpacingvoidLinie i odstępy.
UI::SameLine(offset, spacing) / Indent / Unindent / Dummy(w, h)voidRozmieszczenie.

Kontenery

Każdy przyjmuje zawartość jako callback, więc Begin nigdy nie zostanie bez End.

WywołanieZwracaCo robi
UI::Section(label, body, defaultOpen = true)boolZwijany nagłówek.
UI::Tree(label, body)boolWęzeł drzewa.
UI::Child(id, w, h, border, body)voidPrzewijany obszar potomny.
UI::Group(body) / Disabled(disabled, body)voidGrupa, wyszarzony blok.
UI::WithId(id, body)voidRozróżnia widgety o tej samej etykiecie — używaj w każdej pętli listy.
UI::TabBar(id, body) / TabItem(label, body)voidZakładki.
UI::Table(id, headers, body) + TableRow() / TableColumn()void / boolTabela; komórki przez TableRow, potem TableColumn.

Pola wejściowe

Każde zwraca true w klatce, w której wartość się zmieniła, i zapisuje przez referencję.

WywołanieZwracaCo robi
UI::Button(label, w, h) / SmallButton(label)boolKliknięty w tej klatce.
UI::Selectable(label, selected)boolWiersz do wybrania.
UI::Checkbox(label, bool&)boolCheckbox.
UI::InputText / InputTextMultiline(label, std::string&)boolPole tekstowe.
UI::DragFloat / DragFloat3 / SliderFloat / DragIntboolLiczby. DragFloat3 przyjmuje &vec.x.
UI::Combo(label, int& index, items)boolLista rozwijana.
UI::ColorEdit3 / ColorEdit4(label, float*)boolWybór koloru.
UI::Tooltip(text) / IsItemHovered() / IsItemClicked()void / boolDotyczą elementu narysowanego tuż przed.
UI::Notify(level, title, message, ms)voidPowiadomienie w rogu: Info, Success, Warning, Error.

Obrazki i wykresy

WywołanieZwracaCo robi
UI::Image(assetPath, w = 0, h = 0)boolTekstura po ścieżce projektu. Wczytuje się w tle za prostokątem tego samego rozmiaru; 0 zachowuje proporcje. True po wczytaniu.
UI::ImageButton(id, assetPath, w, h)boolObrazek, który jest przyciskiem.
UI::ProgressBar(fraction, w = 0, overlay = "")void0..1; pusty napis pokazuje procent.
UI::PlotLines / PlotHistogram(label, values, h, min, max, overlay)voidmin/max 0/0 dopasowują się do wartości.

Canvas i Draw

Zarezerwowany prostokąt z własnymi współrzędnymi: (0,0) to jego lewy górny róg. Wywołania Draw:: rysują w nim, z przycinaniem; poza ciałem canvasu nic nie rysują i raz zapisują ostrzeżenie.

WywołanieZwracaCo robi
UI::Canvas(id, w, h, body(const CanvasInput&))voidw = 0 bierze szerokość, h = 0 to 200 px.
CanvasInputstructWidth, Height, MouseX/Y, DragX/Y, Wheel, Hovered, Active, Clicked[3], Down[3], Released[3], DoubleClicked.
UI::Color{ R, G, B, A = 1 }structKolor dla każdego wywołania Draw::.
Draw::Line / Rect / RectFilledvoidLinie i prostokąty (zaokrąglenie, grubość).
Draw::Circle / CircleFilled / TriangleFilledvoidKształty.
Draw::Polyline(xy, colour, closed, thickness)voidxy = x0, y0, x1, y1, …
Draw::Bezier(…)voidKrzywa Béziera trzeciego stopnia.
Draw::Text(x, y, colour, text, size = 0)voidTekst; rozmiar 0 = czcionka UI.
Draw::Image(assetPath, x0, y0, x1, y1, tint)voidTekstura w prostokącie.

Drag & drop

Formaty samego edytora, więc twoje widgety wymieniają się z Content Browserem, hierarchią, inspektorem i viewportem. Każde działa na elemencie narysowanym tuż przed nim.

WywołanieZwracaCo robi
UI::AssetDropTarget(AssetType = None)std::stringUpuszczona ścieżka projektu albo "". None przyjmuje każdy asset.
UI::AssetDragSource(assetPath)voidCzyni element przeciągalnym jako ten asset.
UI::EntityDropTarget()EntityWiersz hierarchii upuszczony w tej klatce albo nieważna Entity.
UI::EntityDragSource(Entity)voidCzyni element przeciągalnym jako ta encja.

Pola referencji

WywołanieZwracaCo robi
UI::AssetField(label, std::string& path, AssetType)boolWiersz assetu z inspektora: upuszczanie, wybór z miniaturami, czyszczenie.
UI::EntityField(label, Entity&)boolLista encji z wyszukiwarką, upuszczanie, czyszczenie, zaznacz.

Kontekst edytora

Scena może być null, a zaznaczenie puste w każdej klatce — sprawdzaj, nie zakładaj.

WywołanieZwracaCo robi
ActiveScene() / ScenePath() / IsPlaying()Scene* / string / boolOtwarta scena.
Selection() / PrimarySelection()vector / EntityCo jest zaznaczone; główna to ta w inspektorze.
Select(Entity) / ClearSelection()voidZastępuje / czyści zaznaczenie.
EntityName / SetEntityNamestring / voidNazwy, przez edytor.
CreateEntity(name) / DestroyEntity(Entity)Entity / voidWykonywane przez edytor; owiń w Edit, żeby cofać.

Komponenty

Po nazwie, przez rejestr serializera sceny; wartości jako YAML — ten sam tekst co w pliku .thread. Rotacja w radianach.

WywołanieZwracaCo robi
ComponentNames()vector<string>Każdy zarejestrowany komponent.
ComponentsOf(Entity)vector<string>Te, które ma encja.
HasComponent / AddComponent / RemoveComponent(e, name)boolObecność. Add zwraca false dla nieznanej nazwy.
GetComponent(e, name)std::stringKomponent jako mapa YAML albo "".
PatchComponent(e, name, yaml)boolZapisuje tylko podane klucze; reszta zostaje.
GetComponentField / SetComponentField(e, name, field[, value])string / boolJeden klucz jako tekst YAML: "5", "[1, 2, 3]", "true".
GetTransform / SetTransform(e, t, r, s)boolTransform (nie ma go w rejestrze).

Cofanie

WywołanieZwracaCo robi
Edit (RAII) / BeginEdit() / CommitEdit()struct / voidJeden krok cofania. Używaj tego, nigdy Thread::ScopedEdit z modułu.
HostApiVersion() / kApiVersionintSprawdzane przez rejestratory; niezgodność odmawia rejestracji.

Zobacz też

Okna edytora · Skrypty i IDE · Skrypty natywne