Test of Link Widget, brings me back around to several old issues that still need resolved.
This commit is contained in:
105
include/JUI/Widgets/Link.hpp
Normal file
105
include/JUI/Widgets/Link.hpp
Normal file
@@ -0,0 +1,105 @@
|
||||
/// 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) 2025 Redacted Software
|
||||
/// This work is dedicated to the public domain.
|
||||
|
||||
/// @file Link.hpp
|
||||
/// @desc Special category of text-objects that model a clickable link in HTML.
|
||||
/// @edit 2025-06-11
|
||||
|
||||
#pragma once
|
||||
#include <JUI/Widgets/Text.hpp>
|
||||
|
||||
#include "JUI/Mixins/Clickable.hpp"
|
||||
|
||||
|
||||
namespace JUI {
|
||||
class Link : public Text, public Clickable, public Hoverable {
|
||||
public:
|
||||
Event<> Clicked;
|
||||
Link() : Text(), Clickable(), Hoverable() {}
|
||||
explicit Link(const std::string& content) : Link() {
|
||||
this->Content(content);
|
||||
}
|
||||
explicit Link(Widget* parent) : Link() {
|
||||
this->Parent(parent);
|
||||
}
|
||||
|
||||
|
||||
void OnHover(const Vector2 &MousePos) override {
|
||||
TextColor(Colors::Blues::CornflowerBlue);
|
||||
}
|
||||
|
||||
void OnExit(const Vector2 &MousePos) override {
|
||||
TextColor(Colors::Blues::DeepSkyBlue);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void OnClick(const Vector2& mouse_pos, const MouseButton& btn) override {
|
||||
if (disabled)
|
||||
return;
|
||||
|
||||
Clickable::OnClick(mouse_pos, btn);
|
||||
|
||||
TextColor(Colors::White);
|
||||
|
||||
if (!fire_on_release) {
|
||||
Clicked.Invoke();
|
||||
already_clicked = true;
|
||||
}
|
||||
}
|
||||
|
||||
void OnRelease(const J3ML::LinearAlgebra::Vector2 &mouse_pos, const JUI::MouseButton &btn,
|
||||
bool still_hovering) override {
|
||||
|
||||
if (disabled)
|
||||
return;
|
||||
|
||||
Clickable::OnRelease(mouse_pos, btn, still_hovering);
|
||||
|
||||
TextColor(Colors::Black);
|
||||
if (fire_on_release) {
|
||||
Clicked.Invoke();
|
||||
already_clicked = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Update(float delta) override {
|
||||
|
||||
Text::Update(delta);
|
||||
|
||||
// TODO: Why does hovered not handle this?
|
||||
hovered = IsMouseInside();
|
||||
|
||||
Hoverable::Update(last_known_mouse_pos, delta);
|
||||
|
||||
// TODO: This is duplicated between here and Window.cpp
|
||||
// Will be abstracted away into Clickable shortly.
|
||||
// OMFG
|
||||
if (IsHovered() && mb_state && !prev_mb_state)
|
||||
{
|
||||
OnClick(last_known_mouse_pos, mbtn);
|
||||
}
|
||||
|
||||
if (IsClicked() && !mb_state)
|
||||
{
|
||||
OnRelease(last_known_mouse_pos, mbtn, IsHovered());
|
||||
}
|
||||
}
|
||||
protected:
|
||||
Color4 already_clicked_color;
|
||||
Color4 hovered_color;
|
||||
Color4 clicked_color;
|
||||
|
||||
bool disabled = false;
|
||||
|
||||
bool already_clicked = false;
|
||||
|
||||
bool fire_on_release;
|
||||
private:
|
||||
};
|
||||
}
|
@@ -5,9 +5,6 @@
|
||||
|
||||
namespace JUI {
|
||||
|
||||
|
||||
|
||||
|
||||
/// The Separator Widget Class.
|
||||
/// Fills space, and renders a single line through it, based on the given orientation.
|
||||
/// Dashed, dotted, and solid lines of varying thickness are supported.
|
||||
|
8
main.cpp
8
main.cpp
@@ -36,6 +36,7 @@
|
||||
|
||||
#include "JUI/Widgets/ColorPicker.hpp"
|
||||
#include "JUI/Widgets/FpsGraph.hpp"
|
||||
#include "JUI/Widgets/Link.hpp"
|
||||
|
||||
using namespace JUI;
|
||||
|
||||
@@ -330,6 +331,13 @@ JUI::Rect* CreateWidgetList(JUI::Widget* root) {
|
||||
auto* radio_c_btn = new Checkbox(radio_btn_set_layout);
|
||||
radio_c_btn->Size({20_px, 20_px});
|
||||
|
||||
auto* linkbox = new Rect(collapsible->ContentBox());
|
||||
linkbox->Size({100_percent, 30_px});
|
||||
linkbox->Position({0_px, 20_px});
|
||||
|
||||
|
||||
auto* link = new JUI::Link(linkbox);
|
||||
link->Content("This Dick");
|
||||
// What the FUCK?
|
||||
|
||||
/*auto* radio_c_label = new TextRect(radio_btn_set_layout);
|
||||
|
Reference in New Issue
Block a user