2026-03-27 09:51:53 +03:00
|
|
|
#pragma once
|
|
|
|
|
#include "../GUIManager.hpp"
|
|
|
|
|
#include "../Elements/SelectableButton.hpp"
|
|
|
|
|
#include "../Elements/ColorRectangleDisplay.hpp"
|
|
|
|
|
|
|
|
|
|
namespace GUIStuff { namespace ElementHelpers {
|
|
|
|
|
|
|
|
|
|
constexpr static float BIG_BUTTON_SIZE = 30;
|
|
|
|
|
constexpr static float SMALL_BUTTON_SIZE = 20;
|
|
|
|
|
|
|
|
|
|
template <typename OptT> SelectableButton::Data selectable_button_options_to_data(const OptT& options) {
|
|
|
|
|
SelectableButton::Data toRet;
|
|
|
|
|
toRet.onClick = options.onClick;
|
|
|
|
|
toRet.isSelected = options.isSelected;
|
|
|
|
|
toRet.drawType = options.drawType;
|
|
|
|
|
return toRet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct TextButtonOptions {
|
|
|
|
|
SelectableButton::DrawType drawType = SelectableButton::DrawType::FILLED;
|
|
|
|
|
bool isSelected = false;
|
|
|
|
|
bool wide = false;
|
|
|
|
|
bool centered = true;
|
|
|
|
|
|
|
|
|
|
std::function<void()> onClick;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SVGButtonOptions {
|
|
|
|
|
SelectableButton::DrawType drawType = SelectableButton::DrawType::FILLED;
|
|
|
|
|
bool isSelected = false;
|
|
|
|
|
float size = BIG_BUTTON_SIZE;
|
|
|
|
|
|
|
|
|
|
std::function<void()> onClick;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct FixedSizeColorButtonOptions {
|
|
|
|
|
SelectableButton::DrawType drawType = SelectableButton::DrawType::FILLED;
|
|
|
|
|
bool isSelected = false;
|
|
|
|
|
bool hasAlpha = true;
|
|
|
|
|
float size = BIG_BUTTON_SIZE;
|
|
|
|
|
|
|
|
|
|
std::function<void()> onClick;
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-29 20:23:38 +03:00
|
|
|
void text_button(GUIManager& gui, const char* id, std::string_view text, const TextButtonOptions& options = {});
|
|
|
|
|
void text_button_sized(GUIManager& gui, const char* id, std::string_view text, Clay_SizingAxis x, Clay_SizingAxis y, const TextButtonOptions& options = {});
|
|
|
|
|
void svg_icon_button(GUIManager& gui, const char* id, const std::string& svgPath, const SVGButtonOptions& options = {});
|
2026-03-27 09:51:53 +03:00
|
|
|
|
2026-03-29 20:23:38 +03:00
|
|
|
template <typename T> void color_button(GUIManager& gui, const char* id, T* val, const FixedSizeColorButtonOptions& options = {}) {
|
2026-03-30 18:51:14 +03:00
|
|
|
gui.new_id(id, [&] {
|
|
|
|
|
SelectableButton::Data d = selectable_button_options_to_data(options);
|
|
|
|
|
d.innerContent = [&] (const SelectableButton::InnerContentCallbackParameters&) {
|
|
|
|
|
gui.element<ColorRectangleDisplay>("color display", [val, hasAlpha = options.hasAlpha] {
|
|
|
|
|
if(hasAlpha)
|
|
|
|
|
return SkColor4f{(*val)[0], (*val)[1], (*val)[2], (*val)[3]};
|
2026-04-02 18:23:36 +03:00
|
|
|
else
|
|
|
|
|
return SkColor4f{(*val)[0], (*val)[1], (*val)[2], 1.0f};
|
2026-03-30 18:51:14 +03:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(options.size), .height = CLAY_SIZING_FIXED(options.size) } } }) {
|
|
|
|
|
gui.element<SelectableButton>("button", d);
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-03-27 09:51:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}}
|