← Back

ofxKit

github.com/ofxyz/ofxKit · @ofxyz
OF 0.12 Templates GUI

ofKitty runtime

0 0 Last commit 3mo ago Created 3mo ago

README

ofxKit



Editor Shell for openFrameworks.
ofKit is a composition-first, ECS-first runtime addon. It injects the Edit Inspector overlay into ofBaseApp sketches with one explicit attach call in main.cpp.

Press Cmd-E at runtime to toggle the overlay (Ctrl-E is also registered as a fallback).

ofKitty is an ECS edit-mode framework. Apps own an entt::registry; the
Runtime is the edit-mode shell over it, and domain features (paths, paint,
audio, …) ship as kit addons. Classic ofPath-in-ofApp patterns still work
as compatibility shims, but the entity-centric path is the architecture —
see docs/from-openframeworks.md for friendly
side-by-side translations.
ofKitty is a stack of addons, not a single package. ofxKit is the
edit-mode shell; data, properties, and domain tools live in other addons. See
docs/supported-stack.md for the inventory and
docs/addon-boundaries.md for what each layer owns.
---

What it does



Registered ImGui windows



Sketches register dockable Inspector panels via Runtime::registerWindow — either with a lambda or (when the window-class headers are present in your ofxKit checkout) by subclassing KitRegisteredWindow. See docs/windows.md for lambdas, KitPropertyBag / baseProp parity.

Built-in windows (Scene, Properties, Toolbar, Shortcuts, Preferences, Code Editor) are opt-in by default — none are registered unless you ask for them. Call any of these before ofRunApp():

runtime().enableBuiltInWindows();           // Scene + Properties (standard set)
runtime().enableBuiltInWindow("Toolbar");   // one at a time (additive)
runtime().enableAllBuiltInWindows();        // all built-in panels
runtime().disableBuiltInWindows();          // reset to default (none)


---

How attach works



The project template includes ofxKit.h. In main.cpp it creates the app as a std::shared_ptr and attached it to the runtime, then we pass the app to ofRunApp(). Meaning we can push improvements up and run ofKitty from Addons in Vanilla OF.

ofApp.h  →  #include "ofxKit.h"
main.cpp →  ofkitty::Runtime::attach(window, app[, registry])
         →  ofRunApp(window, std::move(app))


main.cpp stays close to the standard openFrameworks shape:

#include "ofMain.h"

include "ofApp.h"

int main() { ofGLWindowSettings settings; settings.setSize(1024, 768); settings.title = "My App"; // also used as menu/status app name auto window = ofCreateWindow(settings); auto app = std::make_shared<ofApp>(); ofkitty::Runtime::attach(window, app); ofRunApp(window, std::move(app)); ofRunMainLoop(); }


---

Usage in a sketch



Runtime-owned registry



// ofApp.h  (generated template — nothing to add)

pragma once

include "ofMain.h"

include "ofxKit.h" // already here from the template

class ofApp : public ofBaseApp { ... };


// ofApp.cpp — access the registry anywhere

include "ofApp.h"

void ofApp::setup() { auto& reg = ofkitty::runtime().registry(); auto e = reg.create(); reg.emplace<ecs::named_entity>(e, "My Node"); ecs::ensureSpatialComponents(reg, e); // ... }


App-owned registry



When your app owns the ECS state, pass it to attach so the Runtime's inspector, status bar, and Scene panel all see the same entities:

// ofApp.h
class ofApp : public ofBaseApp {
public:
    entt::registry& registry() { return m_registry; }
    void setup() override;
private:
    entt::registry m_registry;
};


// main.cpp
auto app = std::make_shared<ofApp>();
ofkitty::Runtime::attach(window, app, app->registry());
ofRunApp(window, std::move(app));


If you omit the registry argument, runtime().registry() returns Runtime's own internal registry — only use that path if your app creates all entities via runtime().registry() directly.

---

Runtime registries



ofxKit is the composition runtime for ofKitty. Core addons should stay small and headless where possible; optional kit addons can register the UI, ECS components, and systems that make sense for a specific app.

The first concrete registry is the window registry:

ofkitty::runtime().registerWindow({
    "Machine",
    "View",
    true,
    [](bool& visible) {
        if (ImGui::Begin("Machine", &visible)) {
            ImGui::TextUnformatted("Machine status");
        }
        ImGui::End();
    },
});


Built-in windows such as Properties, and Shortcuts use the same path. The View menu is generated from the registered windows, so addon-owned windows appear beside the built-in ones.

Kit addon pattern



Use a companion kit addon when a core addon needs optional ofKitty integration.

ofx-X-Kit can contain windows, components, systems, and ofKitty registration helpers:

ofx-X-Kit/src/windows/
ofx-X-Kit/src/components/
ofx-X-Kit/src/systems/
ofx-X-Kit/src/kit/


Components and systems



The "+ Add Component" picker is driven by ofxEnTTKit (ecs::componentMenuEntries()). ofxKit finalises the registry on attach; addons extend it via ecs::registerComponent<T>(). Component property panels stay type-driven via ofxEnTTInspector.

#include "component_editor_registration.h"

// minimal — has / remove generated automatically from T
ecs::registerComponent<grbl::MachineStateComponent>(
    "Machine State", "Machines");

// custom add — when default emplace<T>(entity) needs extra work
ecs::registerComponent<grbl::MachineStateComponent>(
    "Machine State", "Machines",
    [](entt::registry& r, entt::entity e) {
        r.emplace<grbl::MachineStateComponent>(e).connect("/dev/ttyUSB0");
    });


See ofxEnTTKit/docs/component-registry.md for the full API. See docs/component-registry.md for how ofxKit consumes the registry.

Kit addons register lifecycle systems against the Runtime (beside the window registry). Systems implement ecs::ISystem (ofxEnTTKit). Update runs automatically in Runtime::onUpdate; draw uses named phases:

// Owned — Runtime constructs and owns the system:
runtime().registerSystem<grbl::MachineSystem>({.update = true, .drawPhase = {}});

// Non-owned — kit keeps a member (typical registerWith pattern):
runtime().registerSystem(m_system, {
    .update    = false,
    .drawPhase = ofkitty::system_phase::canvas, // or "gui"
});

// Inside ofApp::draw(), under your pan/zoom transform:
runtime().drawSystems(); // defaults to "canvas"


Built-in draw phases: "canvas" (app-invoked) and "gui" (auto, inside drawOverlay while the ImGui frame is open). Kits may use any phase string. Enable/disable from the Debug window's Systems list.

WindowRegistry       UI panels and menu visibility (ofxKit)
ComponentRegistry    picker rows — owned by ofxEnTTKit (ecs::)
SystemRegistry       setup / update / named draw / cleanup (ofxKit)


---

API reference



ofkitty::Runtime



MemberDescription
Runtime::instance()Returns the singleton
runtime()Free-function shorthand for Runtime::instance()
runtime().registry()The active entt::registry (owned by runtime or supplied by the app)
runtime().selected()Currently selected entity (entt::null if none)
runtime().select(e)Programmatically select an entity
runtime().isEditMode()Whether the overlay is currently visible
runtime().toggleEditMode()Toggle Edit mode on/off
runtime().setAppName(name)Menu/status bar name (else settings.title on attach, else exe stem)
runtime().registerWindow(w)Register a dockable UI panel (appears in the View menu)
runtime().registerSystem(sys, opts)Register an ecs::ISystem (update + named draw phase)
runtime().registerSystem<T>(opts, …)Construct and own a system
runtime().drawSystems(phase)Draw all systems for a phase ("canvas" default; "gui" auto)
runtime().getSystem<T>()Lookup a registered system by type
runtime().unregisterSystem(sys)Remove a system (calls cleanup)
runtime().disableBuiltInWindows()Reset to default: no built-in windows registered
runtime().enableBuiltInWindow(nameOrId)Opt in to one specific built-in window (additive)
runtime().enableBuiltInWindows()Register the standard set: Scene + Properties
runtime().enableAllBuiltInWindows()Register all built-in windows
runtime().addMenuBarGroup(name, cb)Add a top-level menu group to the main menu bar
runtime().showRulers()Whether pixel rulers are visible
runtime().setShowRulers(bool)Show/hide the pixel ruler overlay
runtime().toggleRulers()Toggle ruler visibility (also bound to F2)
runtime().setViewportRenderer(fn)Register the scene-draw callback for the secondary Viewport panel
runtime().clearViewportRenderer()Remove the viewport renderer (panel shows a placeholder)
runtime().registerPreferencePage(page)Add a page to the Preferences window (built-ins + addon pages)
runtime().unregisterPreferencePage(id)Remove a preference page by id
runtime().registerStatusItem(item)Push an item into the status bar (compact draw callback)
runtime().unregisterStatusItem(id)Remove a status bar item by id
runtime().openFileDialog(key,title,flt,cb)Open a file-open dialog; cb fires with the chosen path on confirm
runtime().saveFileDialog(key,title,flt,fn,cb)Open a file-save dialog; cb fires with the chosen path on confirm
runtime().setSceneCamera(cam)Provide the main-scene camera so the gizmo can be drawn on it
runtime().clearSceneCamera()Remove the scene camera reference
runtime().setGizmoOperation(op)Set gizmo mode: Translate / Rotate / Scale / Universal (W/E/R shortcuts)
runtime().setGizmoMode(mode)Set gizmo space: World / Local (X shortcut)
runtime().codeEditorSetText(src)Seed the Code Editor with a source string
runtime().codeEditorGetText()Read back the current Code Editor contents
runtime().codeEditorSetLanguage(lang)Set syntax-highlighting language (GLSL, C++, Lua, Python, …)


ofkitty::Runtime::attach(window, app)



Call this once before ofRunApp():

auto app = std::make_shared<ofApp>();
ofkitty::Runtime::attach(window, app);
ofRunApp(window, std::move(app));


ofkitty::Runtime::attach(window, app, registry)



Pass your app's registry when the app owns ECS state. The Runtime's inspector, status bar, and Scene panel all read from this registry:

ofkitty::Runtime::attach(window, app, app->registry());


---

Dependencies



The spine below is the minimum. For the full stack (shell utilities, domain Kit addons, what each owns), see docs/supported-stack.md.

For a vanilla openFrameworks project using addons.make, add:

ofxEnTT
ofxImGui
ofxImGuiStyle
ofxEnTTKit
ofxEnTTInspector
ofxKit


AddonRole
ofxEnTTEnTT ECS library
ofxEnTTKitECS components for OF types + ofxNode + TransformSystem
ofxEnTTInspectorImGui inspector panels for ECS components
ofxImGuiImGui integration for openFrameworks
ofxImGuiStyleTheme registry (ImTheme) + bundled fonts/icons (ImFonts)


In the ofKitty distribution, install/update these dependencies with:

./scripts/install_ofkitty_spine.sh


---

Keyboard shortcuts



KeyAction
Cmd-EToggle Edit mode overlay
Ctrl-EToggle Edit mode overlay
Ctrl/Cmd+ZUndo (app stack; skipped while typing in ImGui fields)
Ctrl+Y / Cmd+Shift+ZRedo
F2Toggle Rulers
TABToggle Edit mode (built-in alias; suppressed when ImGui has keyboard focus)
WGizmo: Translate (while in Edit mode)
EGizmo: Rotate (while in Edit mode)
RGizmo: Scale (while in Edit mode)
XGizmo: Toggle World / Local space
Gizmo modes are also under Edit in the menu bar (Edit mode only). Enabling the Toolbar built-in adds the same tools as icon buttons plus View → Toolbar to show or hide the panel.

---

Examples



ExampleWhat it shows
example-emptyMinimal ECS 2D sketch — author shapes with ecs::Painter (or layer.begin()/ecs::drawRect/end()), rendered via drawLayerContents(); Scene / Properties
example-uiClickable glue — rectangle button + click_bind toggles a flag_component in play mode
example-ofKittyFull 3D ECS scene editor showcase — meshes authored with ecs::Painter (box/sphere/...), rendered via ecs::drawMeshes()
Path / vector editing moved to its own addon: see ofxVectorKit and its example-pathEditor.

Wrap normal OF draws to mirror them into the runtime registry (v1: rectangle + path):

void ofApp::draw() {
    ofkitty::begin();
    ofDrawRectangle(x, y, 200, 200);
    myPath.draw(pathX, pathY);
    ofkitty::end();
}


Press Ctrl+E / Tab to toggle Edit mode, select captured entities in Scene, edit values in Properties.

---

Docs



FileTopic
CONTRIBUTING.mdContributing — where new code belongs
docs/supported-stack.mdofKitty stack inventory — spine, utilities, Kit addons
docs/addon-boundaries.mdAddon boundaries — four layers + Kit integration contract
docs/dirty-state.mdDirty state — dirty-only invalidate convention
docs/source-map.mdWhere the code lives — contributor index
docs/component-registry.mdComponentRegistry API, addon registration, picker
docs/scene-window.mdScene hierarchy tree, ofxNode traversal, selection
docs/layers-panel.mdLayersPanel tree, ReorderDragDrop, LayerSystem
docs/chain-editor.mdChainEditor — re-orderable step lists (FX, pipeline)
docs/status-bar.mdStatus bar layout and implementation notes
docs/preferences.mdApp Preferences window — all OF settings
docs/appearance.mdTheme/font integration with ofxImGuiStyle (ImTheme / ImFonts)
docs/rulers.mdRulers overlay — pixel coordinates + mouse tracking
docs/viewport-window.mdSecondary Viewport panel — FBO, camera controls
docs/from-openframeworks.mdFrom openFrameworks to ofKitty — friendly ECS translations
docs/tools.mdFile dialog, Gizmo, Code Editor
docs/dockspace.mdDockspace central node — passthrough vs opaque
docs/undo.mdUndoStack — commands, snapshots, coalesced drags
docs/shortcuts.mdShortcutManager — named actions including edit.undo
docs/menu-bar.mdMain menu bar — built-in Edit → Undo / Redo


---

Architecture notes



  • ofkitty::Runtime is a singleton that lives for the duration of the process
  • Implementation map (where to edit chrome code): docs/source-map.md
  • The runtime creates a default registry, but can inspect an app-owned registry passed at attach time
  • The overlay is rendered at OF_EVENT_ORDER_AFTER_APP so it always draws on top
  • ofxNode (in ofxEnTTKit) is the ECS-native node handle; ecs::TransformSystem propagates global transforms once per frame
---

Architecture



ofxKit is intended to stay addon-owned rather than requiring openFrameworks core patches:

openFrameworks app
  ├── main.cpp            — calls ofkitty::Runtime::attach(...)
  ├── ofxEnTTKit          — Relationship, LocalTransform, GlobalTransform, ofxNode, TransformSystem
  ├── ofxEnTTInspector    — per-component ImGui panels
  ├── ofxImGui            — ImGui window management
  └── ofxKit              — runtime singleton + Edit mode

Get this addon