Implement Pinnable mixin class: Currently works something like a debounce for ContextMenus, but will be extended to lock widgets in-place.

This commit is contained in:
2025-05-01 00:12:41 -05:00
parent eab4165417
commit d807faea58
2 changed files with 65 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
/// Josh's User Interface Library
/// A C++20 Library for creating, styling, and rendering of a UI/UX widgets.
/// Developed and Maintained by Josh O'Leary @ Redacted Software
/// Special Thanks to William Tomasine II and Maxine Hayes.
/// (c) 2024 Redacted Software
/// This work is dedicated to the public domain.
/// @file Pinnable.hpp
/// @desc A mixin class that provides a widget with the ability to be "pinned": locked open and fixed in place.
/// @edit 2025-04-30
#pragma once
#include <Event.h>
#include <JUI/UDim2.hpp>
namespace JUI {
class Pinnable {
public:
Pinnable() = default;
virtual ~Pinnable() = default;
Event<> OnPin;
Event<> OnUnpin;
/// Sets the object as "Pinned". Position and visibility status will be locked.
void Pin();
void Unpin();
void SetPinned(bool pinned);
bool Pinned() const;
protected:
bool pinned = false;
// TODO: Implement position pinning, both relative to parent and global.
bool pin_point_is_relative = true;
UDim2 pinned_point_relative{};
Vector2 pinned_point_global{};
bool pinned_visibility = false;
private:
};
}

View File

@@ -0,0 +1,20 @@
#include <JUI/Mixins/Pinnable.hpp>
namespace JUI {
void Pinnable::Pin() { SetPinned(true); }
void Pinnable::Unpin() { SetPinned(false); }
bool Pinnable::Pinned() const { return pinned; }
void Pinnable::SetPinned(bool pinned) {
bool prev_pinned_state = this->pinned;
this->pinned = pinned;
if (prev_pinned_state != pinned) {
if (pinned)
OnPin();
else
OnUnpin();
}
}
}