63 lines
1.8 KiB
C++
63 lines
1.8 KiB
C++
/// 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 Resizable.hpp
|
|
/// @desc Resizable Mixin Helper class
|
|
/// @edit 2024-10-11
|
|
|
|
#pragma once
|
|
|
|
#include <Event.h>
|
|
#include <J3ML/LinearAlgebra/Vector2.hpp>
|
|
|
|
namespace JUI
|
|
{
|
|
/// A mixin helper class that enables a widget to be resized by the mouse.
|
|
class Focusable {
|
|
public:
|
|
Event<> OnGrabFocus;
|
|
Event<> OnDropFocus;
|
|
|
|
[[nodiscard]] bool Focused() const;
|
|
|
|
[[nodiscard]] bool IsFocused() const { return focused;}
|
|
[[nodiscard]] bool HasFocus() const { return focused;}
|
|
virtual void GrabFocus() { SetFocused(true);}
|
|
virtual void DropFocus(const Vector2& point) {
|
|
if (do_focus_cooldown_hack && focus_hack_cooldown > time_focused)
|
|
return;
|
|
|
|
SetFocused(false);
|
|
}
|
|
virtual void SetFocused(bool value) {
|
|
focused = value;
|
|
if (do_focus_cooldown_hack && value) time_focused = 0;
|
|
}
|
|
|
|
virtual void Update(float delta) {
|
|
if (do_focus_cooldown_hack)
|
|
time_focused += delta;
|
|
}
|
|
|
|
void DoFocusHackCooldown(bool value) { do_focus_cooldown_hack = value; }
|
|
bool DoFocusHackCooldown() const { return do_focus_cooldown_hack; }
|
|
|
|
float FocusHackCooldown() const { return focus_hack_cooldown; }
|
|
void FocusHackCooldown(float value) {
|
|
focus_hack_cooldown = value;
|
|
}
|
|
|
|
protected:
|
|
bool focused = false;
|
|
float time_focused = 0;
|
|
|
|
bool do_focus_cooldown_hack = false;
|
|
float focus_hack_cooldown = 0.1f;
|
|
};
|
|
}
|
|
|