QOL edits.

This commit is contained in:
2025-05-01 23:58:02 -05:00
parent 672429f736
commit bd8e9222de
7 changed files with 122 additions and 12 deletions

View File

@@ -1,8 +1,104 @@
//
// Created by dawsh on 8/1/24.
//
#pragma once
#ifndef JUI_COLORPICKERTOOL_HPP
#define JUI_COLORPICKERTOOL_HPP
#include <JUI/Widgets/Rect.hpp>
#include <JUI/Widgets/TextRect.hpp>
#include <JUI/Widgets/ListLayout.hpp>
#endif //JUI_COLORPICKERTOOL_HPP
namespace JUI {
/// A JUI Widget that displays a HSV color input dialog.
class ColorPicker : public Rect {
public:
Event<Color4> OnColorValueChanged;
void SetColorValue(const Color4& color);
Color4 GetColorValue() const;
JUI::TextRect* hex_label;
float hue = 0;
float sat = 1.f;
float bri = 1.f; // AKA val
ColorPicker() : Rect() {
Size({100_percent, 100_percent});
auto* row_layout = new JUI::VerticalListLayout(this);
row_layout->Padding(5_px);
hue_slider = new JUI::Slider(row_layout);
hue_slider->Size({100_percent, 28_px});
hue_slider->Minimum(0.f); hue_slider->Maximum(1.f);
hue_slider->Interval(1e-3f);
hue_slider->ValueChanged += [this] (float val) mutable {
hue_label->SetContent(std::format("Hue: {}", Math::FloorInt(val*360)));
hue = val * 360;
hue_slider->ScrubberColor(Color4::FromHSV(hue, 1.f, 1.f));
OnColorValueChanged.Invoke(Color4::FromHSV(hue, sat, bri));
};
hue_label = new JUI::Text(hue_slider);
hue_label->AlignCenterHorizontally();
hue_label->AlignTop();
hue_label->SetTextColor(Colors::Black);
hue_label->SetContent("Hue: 0");
sat_slider = new JUI::Slider(row_layout);
sat_slider->Size({100_percent, 28_px});
sat_slider->Minimum(0); sat_slider->Maximum(1);
sat_slider->Interval(1e-3f);
sat_slider->ValueChanged += [this] (float val) mutable {
sat_label->SetContent(std::format("Saturation: {}%", val*100.f));
sat = val;
OnColorValueChanged.Invoke(Color4::FromHSV(hue, sat, bri));
};
sat_label = new JUI::Text(sat_slider);
sat_label->AlignCenterHorizontally();
sat_label->AlignTop();
sat_label->SetTextColor(Colors::Black);
sat_label->SetContent("Saturation: 100%");
bri_slider = new JUI::Slider(row_layout);
bri_slider->Size({100_percent, 28_px});
bri_slider->Minimum(0); bri_slider->Maximum(1);
bri_slider->Interval(1e-3f);
bri_slider->ValueChanged += [this] (float val) mutable {
bri_label->SetContent(std::format("Brightness: {}%", val*100.f));
bri = val;
OnColorValueChanged.Invoke(Color4::FromHSV(hue, sat, bri));
};
bri_label = new JUI::Text(bri_slider);
bri_label->AlignCenterHorizontally();
bri_label->AlignTop();
bri_label->SetTextColor(Colors::Black);
bri_label->SetContent("Brightness: 100%");
auto* hue_box = new JUI::Rect();
}
explicit ColorPicker(Widget* parent) : ColorPicker() {
Parent(parent);
}
protected:
JUI::Slider* hue_slider;
JUI::Slider* sat_slider;
JUI::Slider* bri_slider;
JUI::Text* hue_label;
JUI::Text* sat_label;
JUI::Text* bri_label;
private:
};
}

View File

@@ -29,7 +29,7 @@ namespace JUI {
virtual ContextMenu* AddSubmenu(const std::string& text) = 0;
virtual TextButton* AddButton(const std::string& text) = 0;
virtual TextButton* AddButton(const std::string& text, const std::function<void()>& callback) = 0;
virtual Separator* AddSeparator() = 0;
virtual Separator* AddSeparator(const UDim& size = 5_px) = 0;
};
class RectStyleInterface {
@@ -81,7 +81,7 @@ namespace JUI {
TextButton* AddButton(const std::string &name) override;
TextButton* AddButton(const std::string& name, const std::function<void()> &callback) override;
Separator* AddSeparator() override;
Separator* AddSeparator(const UDim& size = 5_px) override;
ContextMenu* AddSubmenu(const std::string& name) override;

View File

@@ -37,7 +37,7 @@ namespace JUI
TextButton* AddButton(const std::string& name) override;
TextButton* AddButton(const std::string& name, const std::function<void()>& callback) override;
Separator* AddSeparator() override;
Separator* AddSeparator(const UDim& size = 5_px) override;
protected:
//std::vector<TextButton*> buttons;