infinipaint/src/GUIStuff/ElementHelpers/ColorPickerItemsHelpers.hpp

40 lines
1.4 KiB
C++
Raw Normal View History

#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;
};
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, [&] {
auto fullOnEdit = [&gui, oE = options.onEdit, val]() {
oE();
gui.set_to_layout();
};
gui.element<ColorPicker<T>>("c", val, options.hasAlpha, fullOnEdit);
left_to_right_line_layout(gui, [&]() {
text_label(gui, "R");
input_color_component_255(gui, "r", &(*val)[0], { .onEdit = fullOnEdit });
text_label(gui, "G");
input_color_component_255(gui, "g", &(*val)[1], { .onEdit = fullOnEdit });
text_label(gui, "B");
input_color_component_255(gui, "b", &(*val)[2], { .onEdit = fullOnEdit });
if(options.hasAlpha) {
text_label(gui, "A");
input_color_component_255(gui, "a", &(*val)[3], { .onEdit = fullOnEdit });
}
});
left_to_right_line_layout(gui, [&]() {
text_label(gui, "Hex");
input_color_hex(gui, "h", val, { .hasAlpha = options.hasAlpha, .onEdit = fullOnEdit });
});
});
}
} }