From 9d200bc8f749f8d64e4f1e630ddf3a797b9b8fe1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 15 Mar 2025 13:50:51 +0000 Subject: Add operator to get ImTextureID from an Icon --- ui/icon.cpp | 8 ++++++++ ui/icon.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/ui/icon.cpp b/ui/icon.cpp index c3b5078..847b117 100644 --- a/ui/icon.cpp +++ b/ui/icon.cpp @@ -28,3 +28,11 @@ Icon::Bind() const glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_texture); } + +ImTextureID +Icon::operator*() const +{ + static_assert(sizeof(m_texture) <= sizeof(ImTextureID)); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast,performance-no-int-to-ptr) This is how ImGui works + return reinterpret_cast(*m_texture); +} diff --git a/ui/icon.h b/ui/icon.h index 76cd3ae..5f3a812 100644 --- a/ui/icon.h +++ b/ui/icon.h @@ -1,5 +1,6 @@ #pragma once +#include "imgui_wrap.h" #include #include #include @@ -13,6 +14,7 @@ public: void Bind() const; const glm::vec2 size; + ImTextureID operator*() const; private: glTexture m_texture; -- cgit v1.2.3