2026-03-30 17:05:24 +03:00
|
|
|
#pragma once
|
|
|
|
|
#include "../GUIManager.hpp"
|
|
|
|
|
#include "TextBoxHelpers.hpp"
|
|
|
|
|
#include "../Elements/ColorPicker.hpp"
|
|
|
|
|
|
|
|
|
|
namespace GUIStuff { namespace ElementHelpers {
|
|
|
|
|
|
|
|
|
|
struct ColorPickerItemsOptions {
|
|
|
|
|
bool hasAlpha = true;
|
|
|
|
|
std::function<void()> onEdit;
|
2026-04-04 19:53:45 +03:00
|
|
|
std::function<void()> onSelect;
|
|
|
|
|
std::function<void()> onDeselect;
|
2026-03-30 17:05:24 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename T> void color_picker_items(GUIManager& gui, const char* id, T* val, const ColorPickerItemsOptions& options = {}) {
|
2026-03-30 18:51:14 +03:00
|
|
|
gui.new_id(id, [&] {
|
2026-04-12 17:31:32 +03:00
|
|
|
auto fullOnEdit = [&gui, oE = options.onEdit]() {
|
2026-03-31 17:33:09 +03:00
|
|
|
if(oE) oE();
|
2026-03-30 18:51:14 +03:00
|
|
|
gui.set_to_layout();
|
|
|
|
|
};
|
2026-04-04 19:53:45 +03:00
|
|
|
gui.element<ColorPicker<T>>("c", val, options.hasAlpha, ColorPickerData{ .onChange = fullOnEdit, .onHold = options.onSelect, .onRelease = options.onDeselect });
|
2026-03-30 18:51:14 +03:00
|
|
|
left_to_right_line_layout(gui, [&]() {
|
|
|
|
|
text_label(gui, "R");
|
2026-04-04 19:53:45 +03:00
|
|
|
input_color_component_255(gui, "r", &(*val)[0], { .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect });
|
2026-03-30 18:51:14 +03:00
|
|
|
text_label(gui, "G");
|
2026-04-04 19:53:45 +03:00
|
|
|
input_color_component_255(gui, "g", &(*val)[1], { .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect });
|
2026-03-30 18:51:14 +03:00
|
|
|
text_label(gui, "B");
|
2026-04-04 19:53:45 +03:00
|
|
|
input_color_component_255(gui, "b", &(*val)[2], { .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect });
|
2026-03-30 18:51:14 +03:00
|
|
|
if(options.hasAlpha) {
|
|
|
|
|
text_label(gui, "A");
|
2026-04-04 19:53:45 +03:00
|
|
|
input_color_component_255(gui, "a", &(*val)[3], { .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect });
|
2026-03-30 18:51:14 +03:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
left_to_right_line_layout(gui, [&]() {
|
|
|
|
|
text_label(gui, "Hex");
|
2026-04-04 19:53:45 +03:00
|
|
|
input_color_hex(gui, "h", val, { .hasAlpha = options.hasAlpha, .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect });
|
2026-03-30 18:51:14 +03:00
|
|
|
});
|
2026-03-30 17:05:24 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} }
|