Repository navigation
Utils
Some utilities.
Simple clipboard implementation:
Clipboard::Copy("Some string to put into the clipboard");
std::string value = Clipboard::Paste();Simple color class, can be initialized using rgba values, or with hex. Also works with structured bindings. And it contains a lerping method to morph colors.
Color _c1{ 255, 128, 64 }; // RGB
Color _c2{ 255, 128, 64, 255 }; // RGBA
Color _c3{ 0xFF8040 }; // Hex (without alpha)
auto[r, g, b, a] = _c1; // Structured binding
Color _c4 = _c1.Lerp(_c2, 0.25); // Lerp 25% in the direction of _c2Simple way to create a right-click menu, or dropdown menu.
Menu menu;
// Open the menu inside of a separate borderless window at the given position
// Will be opened relative to the current window.
ContextMenu::Open(menu, position);
// Close this menu, also closes any potential sub-contextmenus.
ContextMenu::Close(menu);Simple dimensions struct, contains a min/max size, position, size, and z-index. The Component class extends this struct.
Component c;
c.width == c.size.width;
c.height == c.dimensions.height;
c.x == c.position.x;
c.zIndex = 0; // Used to order components inside another component, so it isn't a global depth index.
c.max.width = 100; // Min/max size is used by the Panel layouting.Fast general function class, basically a replacement for std::function, but it also works with member functions. This function class is also used in the Parser for callbacks, where it is able to take the first n arguments of a function in-code, and the remaining arguments will be parsed from a string.
Function<int(int)> fun = { &Object::fun, objInstance }; // Member functionWrapper for a raw pointer, basically acts as a shared pointer, except it is also able to hold a pointer that shouldn't be deleted. It mostly acts how you'd think a pointer would act, it contains operator overloads for -> and *, and it contains a Get() to obtain the contained pointer, and it contains a conversion to bool to check if it's nullptr.
Object _local;
Pointer<Object> _ptr = _local; // Pointer is initialized using a reference, so it will never call 'delete' on it.
Pointer<Object> _ptr2 = new Object{}; // Pointer is initialized using a pointer, it will call delete when ref count == 0.
Pointer<Object> _ptr3{ 1 }; // Pointer is constructed using constructor arguments of type Object, it will construct an instance of Object in-place.
Object& _obj = _ptr; // Implicit conversion to a reference of Object, or any derived/base of Object.
Object* _objptr = _ptr; // Implicit conversion to a pointer of Object, or any derived/base of Object, will return nullptr if dynamic_cast failed.State dependant coloring. Useful class for linking a component's state to certain colors. It also has a transition time setting.
Component c;
StateColor color{ {
.link = &c, // Link to a component.
.base = { 0, 0, 0 }, // The color to return if no state is set
} };
// Link colors to a state, first registered has priority if both states are set.
color.State(Pressed) = { 100, 100, 100 };
color.State(Hovering) = { 128, 128, 128 };
color.transition = 100; // Transition time in milliseconds.
color.Current(); // Get the current color.Utils.hpp contains general utility functions and templates.
Simple templated Vec2, Vec3, and Vec4 class. Vec2 is often used for position/size/range, and thus contains some helper functions like Inside(const Vec4&) to determine if a position is inside of a rectangle, InRange(float) to determine if the float is in the range of this Vec2. Vec4 is often used as a rectangle, with x, y, width, and height. And thus it contains some helper functions like Overlap(Vec4) which contains the overlapping rectangle between the 2 Vec4s, Overlaps(Vec4) which returns true if there is any overlap in the rectangles, Translate(Vec2) which translates this rectangle, Contains(Vec2) which returns true if the position is inside this rectangle. All of these also support structured bindings.