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
| Call | Returns | What it does |
| RegisterWindow(EditorWindowDesc) | bool | Adds a tool window. False (with a log line) for an empty or duplicate id or a missing Draw. |
| UnregisterWindow(id) | void | Withdraws a window this module registered. Never touches the editor's own. |
| IsWindowOpen(id) / SetWindowOpen(id, open) | bool / void | Read or set whether it is open. |
| FocusWindow(id) | void | Open it and bring it to the front. |
| EditorWindowRegisterer{ desc } | struct | Static 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.
| Call | Returns | What it does |
| RegisterMenuItem(MenuItemDesc) | bool | Adds an entry. Fields: Id, Path, Icon, Shortcut (display only), Tooltip, Order, Action, optional IsChecked / IsEnabled. |
| UnregisterMenuItem(id) | void | Withdraws an entry this module registered. |
| MenuItemRegisterer{ desc } | struct | Static lifetime, like the window registerer. |
Text and layout
| Call | Returns | What it does |
| UI::Text / TextWrapped / TextDisabled / BulletText(text) | void | Text — never treated as a format string. |
| UI::TextColored(r, g, b, a, text) | void | Coloured text. |
| UI::LabelValue(label, value) | void | "Label value", aligned like the inspector. |
| UI::Separator / SeparatorText(label) / Spacing | void | Rules and spacing. |
| UI::SameLine(offset, spacing) / Indent / Unindent / Dummy(w, h) | void | Placement. |
Containers
Each takes its contents as a callback, so a Begin can never be left without its End.
| Call | Returns | What it does |
| UI::Section(label, body, defaultOpen = true) | bool | Collapsing header. |
| UI::Tree(label, body) | bool | Tree node. |
| UI::Child(id, w, h, border, body) | void | Scrolling child region. |
| UI::Group(body) / Disabled(disabled, body) | void | Group, greyed-out block. |
| UI::WithId(id, body) | void | Makes widgets with the same label distinct — use in every list loop. |
| UI::TabBar(id, body) / TabItem(label, body) | void | Tabs. |
| UI::Table(id, headers, body) + TableRow() / TableColumn() | void / bool | Table; walk cells with TableRow then TableColumn. |
Each returns true on the frame the value changed, and writes through the reference.
| Call | Returns | What it does |
| UI::Button(label, w, h) / SmallButton(label) | bool | Clicked this frame. |
| UI::Selectable(label, selected) | bool | Selectable row. |
| UI::Checkbox(label, bool&) | bool | Checkbox. |
| UI::InputText / InputTextMultiline(label, std::string&) | bool | Text input. |
| UI::DragFloat / DragFloat3 / SliderFloat / DragInt | bool | Numbers. DragFloat3 takes &vec.x. |
| UI::Combo(label, int& index, items) | bool | Drop-down list. |
| UI::ColorEdit3 / ColorEdit4(label, float*) | bool | Colour picker. |
| UI::Tooltip(text) / IsItemHovered() / IsItemClicked() | void / bool | About the item drawn just before. |
| UI::Notify(level, title, message, ms) | void | Corner toast: Info, Success, Warning, Error. |
Images and plots
| Call | Returns | What it does |
| UI::Image(assetPath, w = 0, h = 0) | bool | Texture 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) | bool | An image that is a button. |
| UI::ProgressBar(fraction, w = 0, overlay = "") | void | 0..1; empty overlay shows the percentage. |
| UI::PlotLines / PlotHistogram(label, values, h, min, max, overlay) | void | min/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.
| Call | Returns | What it does |
| UI::Canvas(id, w, h, body(const CanvasInput&)) | void | w = 0 takes the width, h = 0 is 200 px. |
| CanvasInput | struct | Width, Height, MouseX/Y, DragX/Y, Wheel, Hovered, Active, Clicked[3], Down[3], Released[3], DoubleClicked. |
| UI::Color{ R, G, B, A = 1 } | struct | Colour for every Draw:: call. |
| Draw::Line / Rect / RectFilled | void | Lines and rectangles (rounding, thickness). |
| Draw::Circle / CircleFilled / TriangleFilled | void | Shapes. |
| Draw::Polyline(xy, colour, closed, thickness) | void | xy = x0, y0, x1, y1, … |
| Draw::Bezier(…) | void | Cubic Bézier curve. |
| Draw::Text(x, y, colour, text, size = 0) | void | Text; size 0 is the UI font size. |
| Draw::Image(assetPath, x0, y0, x1, y1, tint) | void | Texture 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.
| Call | Returns | What it does |
| UI::AssetDropTarget(AssetType = None) | std::string | The dropped project path, or "". None accepts any asset. |
| UI::AssetDragSource(assetPath) | void | Makes the item draggable as that asset. |
| UI::EntityDropTarget() | Entity | A hierarchy row dropped this frame, or an invalid Entity. |
| UI::EntityDragSource(Entity) | void | Makes the item draggable as that entity. |
Reference fields
| Call | Returns | What it does |
| UI::AssetField(label, std::string& path, AssetType) | bool | The inspector's asset row: drop target, picker with thumbnails, clear. |
| UI::EntityField(label, Entity&) | bool | Searchable 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.
| Call | Returns | What it does |
| ActiveScene() / ScenePath() / IsPlaying() | Scene* / string / bool | The open scene. |
| Selection() / PrimarySelection() | vector / Entity | What is selected; the primary is the one the inspector shows. |
| Select(Entity) / ClearSelection() | void | Replace / clear the selection. |
| EntityName / SetEntityName | string / void | Names, through the editor. |
| CreateEntity(name) / DestroyEntity(Entity) | Entity / void | Done 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.
| Call | Returns | What it does |
| ComponentNames() | vector<string> | Every registered component. |
| ComponentsOf(Entity) | vector<string> | The ones this entity has. |
| HasComponent / AddComponent / RemoveComponent(e, name) | bool | Presence. Add is false for an unknown name. |
| GetComponent(e, name) | std::string | The component as a YAML map, or "". |
| PatchComponent(e, name, yaml) | bool | Writes only the keys given; the rest stays. |
| GetComponentField / SetComponentField(e, name, field[, value]) | string / bool | One key, as YAML text: "5", "[1, 2, 3]", "true". |
| GetTransform / SetTransform(e, t, r, s) | bool | The transform (not in the registry). |
Undo
| Call | Returns | What it does |
| Edit (RAII) / BeginEdit() / CommitEdit() | struct / void | One undo step. Use this, never Thread::ScopedEdit from a module. |
| HostApiVersion() / kApiVersion | int | Checked 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łanie | Zwraca | Co robi |
| RegisterWindow(EditorWindowDesc) | bool | Dodaje okno narzędziowe. False (z linią w logu) dla pustego lub zdublowanego id albo braku Draw. |
| UnregisterWindow(id) | void | Wycofuje okno zarejestrowane przez ten moduł. Nigdy nie rusza okien edytora. |
| IsWindowOpen(id) / SetWindowOpen(id, open) | bool / void | Odczyt / ustawienie, czy jest otwarte. |
| FocusWindow(id) | void | Otwiera i wysuwa na wierzch. |
| EditorWindowRegisterer{ desc } | struct | Obiekt 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łanie | Zwraca | Co robi |
| RegisterMenuItem(MenuItemDesc) | bool | Dodaje pozycję. Pola: Id, Path, Icon, Shortcut (tylko napis), Tooltip, Order, Action, opcjonalnie IsChecked / IsEnabled. |
| UnregisterMenuItem(id) | void | Wycofuje pozycję zarejestrowaną przez ten moduł. |
| MenuItemRegisterer{ desc } | struct | Czas życia statyczny, jak rejestrator okna. |
Tekst i układ
| Wywołanie | Zwraca | Co robi |
| UI::Text / TextWrapped / TextDisabled / BulletText(text) | void | Tekst — nigdy nie jest traktowany jako format. |
| UI::TextColored(r, g, b, a, text) | void | Kolorowy tekst. |
| UI::LabelValue(label, value) | void | „Etykieta wartość”, wyrównane jak w inspektorze. |
| UI::Separator / SeparatorText(label) / Spacing | void | Linie i odstępy. |
| UI::SameLine(offset, spacing) / Indent / Unindent / Dummy(w, h) | void | Rozmieszczenie. |
Kontenery
Każdy przyjmuje zawartość jako callback, więc Begin nigdy nie zostanie bez End.
| Wywołanie | Zwraca | Co robi |
| UI::Section(label, body, defaultOpen = true) | bool | Zwijany nagłówek. |
| UI::Tree(label, body) | bool | Węzeł drzewa. |
| UI::Child(id, w, h, border, body) | void | Przewijany obszar potomny. |
| UI::Group(body) / Disabled(disabled, body) | void | Grupa, wyszarzony blok. |
| UI::WithId(id, body) | void | Rozróżnia widgety o tej samej etykiecie — używaj w każdej pętli listy. |
| UI::TabBar(id, body) / TabItem(label, body) | void | Zakładki. |
| UI::Table(id, headers, body) + TableRow() / TableColumn() | void / bool | Tabela; komórki przez TableRow, potem TableColumn. |
Każde zwraca true w klatce, w której wartość się zmieniła, i zapisuje przez referencję.
| Wywołanie | Zwraca | Co robi |
| UI::Button(label, w, h) / SmallButton(label) | bool | Kliknięty w tej klatce. |
| UI::Selectable(label, selected) | bool | Wiersz do wybrania. |
| UI::Checkbox(label, bool&) | bool | Checkbox. |
| UI::InputText / InputTextMultiline(label, std::string&) | bool | Pole tekstowe. |
| UI::DragFloat / DragFloat3 / SliderFloat / DragInt | bool | Liczby. DragFloat3 przyjmuje &vec.x. |
| UI::Combo(label, int& index, items) | bool | Lista rozwijana. |
| UI::ColorEdit3 / ColorEdit4(label, float*) | bool | Wybór koloru. |
| UI::Tooltip(text) / IsItemHovered() / IsItemClicked() | void / bool | Dotyczą elementu narysowanego tuż przed. |
| UI::Notify(level, title, message, ms) | void | Powiadomienie w rogu: Info, Success, Warning, Error. |
Obrazki i wykresy
| Wywołanie | Zwraca | Co robi |
| UI::Image(assetPath, w = 0, h = 0) | bool | Tekstura 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) | bool | Obrazek, który jest przyciskiem. |
| UI::ProgressBar(fraction, w = 0, overlay = "") | void | 0..1; pusty napis pokazuje procent. |
| UI::PlotLines / PlotHistogram(label, values, h, min, max, overlay) | void | min/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łanie | Zwraca | Co robi |
| UI::Canvas(id, w, h, body(const CanvasInput&)) | void | w = 0 bierze szerokość, h = 0 to 200 px. |
| CanvasInput | struct | Width, Height, MouseX/Y, DragX/Y, Wheel, Hovered, Active, Clicked[3], Down[3], Released[3], DoubleClicked. |
| UI::Color{ R, G, B, A = 1 } | struct | Kolor dla każdego wywołania Draw::. |
| Draw::Line / Rect / RectFilled | void | Linie i prostokąty (zaokrąglenie, grubość). |
| Draw::Circle / CircleFilled / TriangleFilled | void | Kształty. |
| Draw::Polyline(xy, colour, closed, thickness) | void | xy = x0, y0, x1, y1, … |
| Draw::Bezier(…) | void | Krzywa Béziera trzeciego stopnia. |
| Draw::Text(x, y, colour, text, size = 0) | void | Tekst; rozmiar 0 = czcionka UI. |
| Draw::Image(assetPath, x0, y0, x1, y1, tint) | void | Tekstura 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łanie | Zwraca | Co robi |
| UI::AssetDropTarget(AssetType = None) | std::string | Upuszczona ścieżka projektu albo "". None przyjmuje każdy asset. |
| UI::AssetDragSource(assetPath) | void | Czyni element przeciągalnym jako ten asset. |
| UI::EntityDropTarget() | Entity | Wiersz hierarchii upuszczony w tej klatce albo nieważna Entity. |
| UI::EntityDragSource(Entity) | void | Czyni element przeciągalnym jako ta encja. |
Pola referencji
| Wywołanie | Zwraca | Co robi |
| UI::AssetField(label, std::string& path, AssetType) | bool | Wiersz assetu z inspektora: upuszczanie, wybór z miniaturami, czyszczenie. |
| UI::EntityField(label, Entity&) | bool | Lista 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łanie | Zwraca | Co robi |
| ActiveScene() / ScenePath() / IsPlaying() | Scene* / string / bool | Otwarta scena. |
| Selection() / PrimarySelection() | vector / Entity | Co jest zaznaczone; główna to ta w inspektorze. |
| Select(Entity) / ClearSelection() | void | Zastępuje / czyści zaznaczenie. |
| EntityName / SetEntityName | string / void | Nazwy, przez edytor. |
| CreateEntity(name) / DestroyEntity(Entity) | Entity / void | Wykonywane 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łanie | Zwraca | Co robi |
| ComponentNames() | vector<string> | Każdy zarejestrowany komponent. |
| ComponentsOf(Entity) | vector<string> | Te, które ma encja. |
| HasComponent / AddComponent / RemoveComponent(e, name) | bool | Obecność. Add zwraca false dla nieznanej nazwy. |
| GetComponent(e, name) | std::string | Komponent jako mapa YAML albo "". |
| PatchComponent(e, name, yaml) | bool | Zapisuje tylko podane klucze; reszta zostaje. |
| GetComponentField / SetComponentField(e, name, field[, value]) | string / bool | Jeden klucz jako tekst YAML: "5", "[1, 2, 3]", "true". |
| GetTransform / SetTransform(e, t, r, s) | bool | Transform (nie ma go w rejestrze). |
Cofanie
| Wywołanie | Zwraca | Co robi |
| Edit (RAII) / BeginEdit() / CommitEdit() | struct / void | Jeden krok cofania. Używaj tego, nigdy Thread::ScopedEdit z modułu. |
| HostApiVersion() / kApiVersion | int | Sprawdzane przez rejestratory; niezgodność odmawia rejestracji. |
Zobacz też
Okna edytora · Skrypty i IDE · Skrypty natywne