2026-03-27 09:51:53 +03:00
|
|
|
#include "ColorPickerButton.decl.hpp"
|
2026-03-30 17:05:24 +03:00
|
|
|
#include "../ElementHelpers/ColorPickerItemsHelpers.hpp"
|
2026-03-27 09:51:53 +03:00
|
|
|
#include "../ElementHelpers/ButtonHelpers.hpp"
|
2026-03-30 17:05:24 +03:00
|
|
|
#include "../ElementHelpers/LayoutHelpers.hpp"
|
2026-03-27 09:51:53 +03:00
|
|
|
|
|
|
|
|
namespace GUIStuff {
|
|
|
|
|
|
|
|
|
|
template <typename T> ColorPickerButton<T>::ColorPickerButton(GUIManager& gui): Element(gui) {}
|
|
|
|
|
|
2026-03-31 17:33:09 +03:00
|
|
|
template <typename T> void ColorPickerButton<T>::layout(const Clay_ElementId& id, T* val, const ColorPickerButtonData& d) {
|
2026-03-27 09:51:53 +03:00
|
|
|
this->data = d;
|
|
|
|
|
|
|
|
|
|
GUIStuff::ElementHelpers::color_button(gui, "Color Picker Button", val, {
|
|
|
|
|
.isSelected = isOpen,
|
|
|
|
|
.onClick = [&]{
|
|
|
|
|
isOpen = !isOpen;
|
|
|
|
|
gui.set_to_layout();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if(isOpen) {
|
2026-03-31 20:52:46 +03:00
|
|
|
gui.zIndex++;
|
2026-03-30 17:05:24 +03:00
|
|
|
ElementHelpers::top_to_bottom_window_popup_layout(gui, "Color Picker", CLAY_SIZING_FIT(300), CLAY_SIZING_FIT(0), [&, val, data = data]() {
|
2026-03-27 09:51:53 +03:00
|
|
|
ElementHelpers::color_picker_items(gui, "c", val, {
|
|
|
|
|
.hasAlpha = data.hasAlpha,
|
|
|
|
|
.onEdit = data.onEdit
|
|
|
|
|
});
|
|
|
|
|
}, {
|
|
|
|
|
.mouseButton = [&](const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
2026-03-31 20:52:46 +03:00
|
|
|
if(!mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down) {
|
2026-03-27 09:51:53 +03:00
|
|
|
isOpen = false;
|
2026-03-31 20:52:46 +03:00
|
|
|
gui.set_to_layout();
|
|
|
|
|
}
|
2026-03-27 09:51:53 +03:00
|
|
|
return mouseHovering;
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-03-31 20:52:46 +03:00
|
|
|
gui.zIndex--;
|
2026-03-27 09:51:53 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|