Skip to content

Instantly share code, notes, and snippets.

@kudaba
kudaba / ImGuiTextWithEllipsis.cpp
Created November 5, 2020 17:51
ImGui helper to draw text that will cut off and add an elipsis character
bool IsSpace(char aCharacter)
{
// all space characters are values 32 or less (space is 32)
// so we can convert them to a bitmask and use a single condition
const int mask = (1 << (' ' - 1)) | (1 << ('\f' - 1)) | (1 << ('\n' - 1)) | (1 << ('\r' - 1)) | (1 << ('\t' - 1)) | (1 << ('\v' - 1));
return (mask & (1 << ((aCharacter && aCharacter <= 32) * (aCharacter - 1)))) != 0;
}
//-------------------------------------------------------------------------------------------------
// Todo: Add support for soft-hyphens when using word boundaries?
namespace ImGui
{
// Copy of BeginMenuBar except it's at the bottom
bool BeginMainStatusBar()
{
ImGuiContext& g = *GImGui;
ImGuiViewport* viewport = g.Viewports[0];
float height = g.NextWindowData.MenuBarOffsetMinVal.y + g.FontSize + g.Style.FramePadding.y * 2;
g.NextWindowData.MenuBarOffsetMinVal = ImVec2(g.Style.DisplaySafeAreaPadding.x, ImMax(g.Style.DisplaySafeAreaPadding.y - g.Style.FramePadding.y, 0.0f));
SetNextWindowPos(ImVec2(viewport->Pos.x, viewport->Pos.y + viewport->Size.y - height));
[20200909 00:21:54.280] ZIP: Can't locate [version] in zip, error -100.
[20200909 00:21:54.284] Configuration from file "/opt/rslsync/etc/rslsync.conf" has been applied
[20200909 00:21:54.349] test sha1: AE5BD8EFEA5322C4D9986D06680A781392F9A642
[20200909 00:21:54.349] test sha2: 630DCD2966C4336691125448BBB25B4FF412A49C732DB2C8ABC1B8581BD710DD
[20200909 00:21:54.350] test aes: 0A940BB5416EF045F1C39458C653EA5A07FEEF74E1D5036E900EEE118E949293
[20200909 00:21:54.350] DISKIO[0x0271f9ec]: Create diskio pool for drive with id 18446744073709551614, path: , type: 0, size: 1
[20200909 00:21:54.350] WORKER[0x0271fcb0]: created
[20200909 00:21:54.351] DISKIO[0x0271f9ec]: created
[20200909 00:21:54.351] DISK_WORKER[0x0271fcb0]: diskio thread start, drive_id = 18446744073709551614, priority = normal
[20200909 00:21:54.352] WORKER[0x027105d4]: created
@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:
@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 / 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 / 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)
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);

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.
@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: