Expand Documentation for class Pinnable.

This commit is contained in:
2025-05-02 02:31:34 -05:00
parent c183cae173
commit c538937c07
2 changed files with 26 additions and 13 deletions

View File

@@ -16,23 +16,34 @@
namespace JUI {
/// The pinnable mixin class. Designates a widget as "pinned" or not, which, depending on the derived classes' semantics, may lock it open or in it's current place.
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();
/// Sets the object as "Pinned". Depending on the widget, position and visibility status will be locked.
/// @see Unpin(), SetPinned().
virtual void Pin();
/// Sets the object as "Unpinned".
/// @see Pin(), SetPinned().
virtual void Unpin();
/// Sets the objects pinned status manually.
void SetPinned(bool pinned);
/// Called when the pinned status changes, and triggers callback event signals.
virtual void OnPinStatusChanged(bool new_status);
bool Pinned() const;
protected:
bool pinned = false;
// TODO: Implement position pinning, both relative to parent and global.
bool pin_point_is_relative = true;
@@ -41,5 +52,6 @@ namespace JUI {
bool pinned_visibility = false;
private:
bool pinned = false;
};
}

View File

@@ -5,16 +5,17 @@ namespace JUI {
void Pinnable::Unpin() { SetPinned(false); }
bool Pinnable::Pinned() const { return pinned; }
void Pinnable::OnPinStatusChanged(bool now_pinned) {
if (now_pinned)
OnPin();
else
OnUnpin();
}
void Pinnable::SetPinned(bool pinned) {
bool prev_pinned_state = this->pinned;
this->pinned = pinned;
if (prev_pinned_state != pinned) {
if (pinned)
OnPin();
else
OnUnpin();
if (pinned != this->pinned) {
OnPinStatusChanged(pinned);
this->pinned = pinned;
}
}
}