Skip to content

Instantly share code, notes, and snippets.

@kudaba
kudaba / ImGuiStyleScope.h
Created October 3, 2019 05:48
Helper to set and forget imgui style changes.
//-------------------------------------------------------------------------------------------------
// Helper for managing style changes. Can set and forget.
// Usage 1: ImGuiStyleScope scope(ImGuiCol_Text, ImGuiColors::Red);
// Usage 2:
// ImGuiStyleScope scope;
// scope.Color(ImGuiCol_Text, ImGuiColors::Yellow)
// .Style(ImGuiStyleVar_Alpha, 0.4f);
//-------------------------------------------------------------------------------------------------
class ImGuiStyleScope : GC_NonCopyable
{
@kudaba
kudaba / imcanvas.cpp
Last active June 7, 2020 04:36
Virtual canvas utility class.
#include "ImguiCanvas.h"
#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui_internal.h>
// Not true epsilon, this one is much more useful
constexpr float ImEpsilonf = 0.00001f;
//-------------------------------------------------------------------------------------------------
// Return -1 or +1 (0 returns +1)
@kudaba
kudaba / iminputvalue.cpp
Last active April 9, 2020 06:40
Improved number editing control for ImGui
// WARNING: Revision 5+ Requires unreleased code from imgui, stick to 3 or 2 for now (don't look at revision 4)
#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui.h>
#include <imgui_internal.h>
#include "iminputvalue.h"
namespace ImGui
{
//-------------------------------------------------------------------------------------------------
@kudaba
kudaba / gh_actions_crash.md
Created November 12, 2019 05:11
Github actions: How to capture a crash dump

If an application is crashing during a github actions run then you can use this guide to capture the core as an artifact for debugging.

This guide was developed to debug Mac crashes specifically. It should mostly apply to Linux as well but getting dumps from Windows is unknown for now.

Mac / Linux

By default these systems will not be in a state where they are recording core dumps, and even when enabled you need to run with elevated permissions for a core to even be written. To capture dumps you need to do the following:

List of things to NOT try to implement on my own, always use existing solutions or defer to platform implementation:

  • Time: Only store UTC and use standard libs/platform code to decode/shift or otherwise manipulate.
  • Encryption: Beyond basic local hashing, don't try to handle this ever.
  • IME Keyboards: Use platform implementations, always.
namespace ImGui
{
ImVec2 const AlignedCenter(0.5f, 0.5f);
ImVec2 const AlignedLeft(0.0f, 0.5f);
ImVec2 const AlignedTop(0.5f, 0.0f);
ImVec2 const AlignedRight(1.0f, 0.5f);
ImVec2 const AlignedBottom(0.5f, 1.0f);
ImVec2 const AlignedTopLeft(0.0f, 0.0f);
@kudaba
kudaba / GC_Enum.cpp
Last active December 17, 2020 22:52
Better c++ enum
#include "GC_Enum.h"
//-------------------------------------------------------------------------------------------------
// Build enum metadata from generated enum string
//-------------------------------------------------------------------------------------------------
GC_EnumMetaData::GC_EnumMetaData(char const* aString, StringPart* someParts, uint aCount, int aStart, int aDefault)
: myEnumString(aString)
, myParts(someParts)
, myCount(aCount)
, myStartValue(aStart)
@kudaba
kudaba / Example.cpp
Created June 5, 2020 17:22
Helper and example to implement serializer for imgui style.
//-------------------------------------------------------------------------------------------------
// Serialization helpers
//-------------------------------------------------------------------------------------------------
template <typename T>
static T& locStyleAdapter(T& aValue) { return aValue; }
static GC_Vector2f& locStyleAdapter(ImVec2& aValue) { return *(GC_Vector2f*)&aValue; }
static GC_Vector2f const& locStyleAdapter(ImVec2 const& aValue) { return *(GC_Vector2f const*)&aValue; }
static GC_Vector4f& locStyleAdapter(ImVec4& aValue) { return *(GC_Vector4f*)&aValue; }
static GC_Vector4f const& locStyleAdapter(ImVec4 const& aValue) { return *(GC_Vector4f const*)&aValue; }
@kudaba
kudaba / ImStyleAdapter.inl
Last active July 14, 2020 15:05
Helper to serialize ImGui styles in your own engine
//-------------------------------------------------------------------------------------------------
// Helper to quickly adapt code to imgui styles
//-------------------------------------------------------------------------------------------------
IMPLEMENT_STYLE(Alpha )
IMPLEMENT_STYLE(WindowPadding )
IMPLEMENT_STYLE(WindowRounding )
IMPLEMENT_STYLE(WindowBorderSize )
IMPLEMENT_STYLE(WindowMinSize )
IMPLEMENT_STYLE(WindowTitleAlign )
@kudaba
kudaba / StructuredBindings.h
Last active August 26, 2020 17:05
Helper for adapting structured bindings
//-------------------------------------------------------------------------------------------------
// Leaving this here for safe keeping but not integrating into my code just yet. It basically
// requires you to upgrade to Clang 8+ and newer versions of vs 2019 to work without weird compiler bugs.
//-------------------------------------------------------------------------------------------------
#include <tuple>
//-------------------------------------------------------------------------------------------------
// Helper to simplify generating custom structured bindings
// Usage: