QOL edits.
This commit is contained in:
@@ -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:
|
||||
};
|
||||
|
||||
}
|
@@ -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;
|
||||
|
||||
|
||||
|
@@ -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;
|
||||
|
5
main.cpp
5
main.cpp
@@ -9,6 +9,10 @@
|
||||
/// @desc Demo Program Entry Point
|
||||
/// @edit 2024-07-11
|
||||
|
||||
|
||||
/// This is a guided tour through creating, designing, and using a JUI
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <JGL/JGL.h>
|
||||
#include <JUI/Widgets/Rect.hpp>
|
||||
@@ -116,6 +120,7 @@ JUI::UtilityBar* CreateUtilityBar(JUI::Widget* root) {
|
||||
auto* test_sub = demos->AddSubmenu("Fruit"); {
|
||||
test_sub->AddButton("Apples");
|
||||
test_sub->AddButton("Bananas");
|
||||
test_sub->AddSeparator(20_px);
|
||||
auto* berries = test_sub->AddSubmenu("Berries");
|
||||
{
|
||||
berries->AddButton("Grapes");
|
||||
|
3
src/JUI/Widgets/ColorPicker.cpp
Normal file
3
src/JUI/Widgets/ColorPicker.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
//
|
||||
// Created by dawsh on 5/1/25.
|
||||
//
|
@@ -60,8 +60,10 @@ namespace JUI {
|
||||
return btn;
|
||||
}
|
||||
|
||||
Separator * ContextMenu::AddSeparator() {
|
||||
return new Separator(layout);
|
||||
Separator * ContextMenu::AddSeparator(const UDim& size) {
|
||||
auto* separator = new Separator(layout);
|
||||
separator->Size({100_percent, size});
|
||||
return separator;
|
||||
}
|
||||
|
||||
ContextMenu * ContextMenu::AddSubmenu(const std::string &name) {
|
||||
|
@@ -67,7 +67,11 @@ namespace JUI {
|
||||
return button;
|
||||
}
|
||||
|
||||
Separator * UtilityBar::AddSeparator() {
|
||||
Separator * UtilityBar::AddSeparator(const UDim& size) {
|
||||
auto* separator = new Separator(layout);
|
||||
|
||||
separator->Size({100_percent, size});
|
||||
|
||||
|
||||
return new Separator(layout);
|
||||
}
|
||||
|
Reference in New Issue
Block a user