Skip to content

Latest commit

 

History

History
56 lines (43 loc) · 1.54 KB

File metadata and controls

56 lines (43 loc) · 1.54 KB

imgui_entt_entity_editor

A drop-in, single-file entity editor for EnTT, with ImGui as graphical backend.

demo-code (live)

example usage

struct Transform {
	float x = 0.f;
	float y = 0.f;
};

struct Velocity {
	float x = 0.f;
	float y = 0.f;
};

namespace Widgets {
	void Velocity(::Velocity& v) {
		ImGui::DragFloat("x##Velocity", &v.x, 0.1f);
		ImGui::DragFloat("y##Velocity", &v.y, 0.1f);
	}
} // Widgets

entt::registry reg;

MM::ImGuiEntityEditor<decltype(reg)> editor;

// "registerTrivial" registers the type, name, create and destroy functions for trivialy costructable(and destroyable) types.
// you just need to provide a "widget" function if you use this method.
editor.registerTrivial<Transform>(reg, "Transform");
editor.registerTrivial<Velocity>(reg, "Velocity");

editor.registerComponentWidgetFn(
	reg.type<Transform>(),
	[](entt::registry& reg, auto e) {
		auto& t = reg.get<Transform>(e);

		// the "##Transform" ensures that you can use the name "x" in multiple lables
		ImGui::DragFloat("x##Transform", &t.x, 0.1f);
		ImGui::DragFloat("y##Transform", &t.y, 0.1f);
	});

editor.registerComponentWidgetFn(
	reg.type<Velocity>(),
	[](entt::registry& reg, auto e) {
		auto& v = reg.get<Velocity>(e);
		Widgets::Velocity(v);
	});

dependencies

The editor uses (the latest) EnTTv3.1.0 interface and ImGui 1.72b but should work with prior versions. (tested with ImGui 1.68) To use it with EnTTv3.0.0, use the dedicated branch.