More GUI code moved to events, code now compiles but application doesn't run
This commit is contained in:
parent
3566b7e563
commit
b4c35124c3
37 changed files with 913 additions and 879 deletions
|
|
@ -15,7 +15,7 @@ void text_button(GUIManager& gui, const char* id, std::string_view text, const T
|
|||
.childAlignment = {.x = options.centered ? CLAY_ALIGN_X_CENTER : CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER}
|
||||
}
|
||||
}) {
|
||||
gui.element<SelectableButton>(id, options);
|
||||
gui.element<SelectableButton>(id, d);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ void text_button_sized(GUIManager& gui, const char* id, std::string_view text, C
|
|||
.childAlignment = {.x = options.centered ? CLAY_ALIGN_X_CENTER : CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER}
|
||||
}
|
||||
}) {
|
||||
gui.element<SelectableButton>(id, options);
|
||||
gui.element<SelectableButton>(id, d);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ void svg_icon_button(GUIManager& gui, const char* id, const std::string& svgPath
|
|||
gui.element<SVGIcon>("icon", svgPath, p.isSelected || p.isHovering || p.isHeld);
|
||||
};
|
||||
CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(options.size), .height = CLAY_SIZING_FIXED(options.size) } } }) {
|
||||
gui.element<SelectableButton>(id, options);
|
||||
gui.element<SelectableButton>(id, d);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,9 +47,10 @@ void text_button_sized(GUIManager& gui, const char* id, std::string_view text, C
|
|||
void svg_icon_button(GUIManager& gui, const char* id, const std::string& svgPath, const SVGButtonOptions& options = {});
|
||||
|
||||
template <typename T> void color_button(GUIManager& gui, const char* id, T* val, const FixedSizeColorButtonOptions& options = {}) {
|
||||
gui.push_id(id);
|
||||
SelectableButton::Data d = selectable_button_options_to_data(options);
|
||||
d.innerContent = [&] (const SelectableButton::InnerContentCallbackParameters&) {
|
||||
gui.element<ColorRectangleDisplay>([val, hasAlpha = options.hasAlpha] {
|
||||
gui.element<ColorRectangleDisplay>("color display", [val, hasAlpha = options.hasAlpha] {
|
||||
if(hasAlpha)
|
||||
return SkColor4f{(*val)[0], (*val)[1], (*val)[2], 1.0f};
|
||||
else
|
||||
|
|
@ -57,8 +58,9 @@ template <typename T> void color_button(GUIManager& gui, const char* id, T* val,
|
|||
});
|
||||
};
|
||||
CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(options.size), .height = CLAY_SIZING_FIXED(options.size) } } }) {
|
||||
gui.element<SelectableButton>(id, options);
|
||||
gui.element<SelectableButton>("button", d);
|
||||
}
|
||||
gui.pop_id();
|
||||
}
|
||||
|
||||
}}
|
||||
|
|
|
|||
|
|
@ -1,44 +1,11 @@
|
|||
#pragma once
|
||||
#include "../GUIManager.hpp"
|
||||
#include "TextBoxHelpers.hpp"
|
||||
#include "../Elements/ColorPicker.hpp"
|
||||
#include "../Elements/ColorPickerButton.decl.hpp"
|
||||
#include "ColorPickerItemsHelpers.hpp"
|
||||
#include "../Elements/ColorPickerButton.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 = {}) {
|
||||
gui.push_id(id);
|
||||
auto fullOnEdit = [&gui, oE = options.onEdit, val]() {
|
||||
oE();
|
||||
gui.set_to_layout();
|
||||
};
|
||||
gui.element<ColorPicker>("c", val, options.hasAlpha, fullOnEdit);
|
||||
left_to_right_line_layout([&]() {
|
||||
text_label(gui, "R");
|
||||
input_color_component_255("r", &(*val)[0], { .onEdit = fullOnEdit });
|
||||
text_label(gui, "G");
|
||||
input_color_component_255("g", &(*val)[1], { .onEdit = fullOnEdit });
|
||||
text_label(gui, "B");
|
||||
input_color_component_255("b", &(*val)[2], { .onEdit = fullOnEdit });
|
||||
if(options.hasAlpha) {
|
||||
text_label(gui, "A");
|
||||
input_color_component_255("a", &(*val)[3], { .onEdit = fullOnEdit });
|
||||
}
|
||||
});
|
||||
left_to_right_line_layout([&]() {
|
||||
text_label(gui, "Hex");
|
||||
input_color_hex("h", val, { .onEdit = fullOnEdit, .hasAlpha = options.hasAlpha });
|
||||
});
|
||||
gui.pop_id();
|
||||
}
|
||||
|
||||
template <typename T> void color_picker_button_field(GUIManager& gui, const char* id, std::string_view name, T* val, const ColorPickerButtonData& options = {}) {
|
||||
left_to_right_line_layout([&]() {
|
||||
left_to_right_line_layout(gui, [&]() {
|
||||
gui.element<ColorPickerButton<T>>(id, val, options);
|
||||
text_label(gui, name);
|
||||
});
|
||||
|
|
|
|||
39
src/GUIStuff/ElementHelpers/ColorPickerItemsHelpers.hpp
Normal file
39
src/GUIStuff/ElementHelpers/ColorPickerItemsHelpers.hpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#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 = {}) {
|
||||
gui.push_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 });
|
||||
});
|
||||
gui.pop_id();
|
||||
}
|
||||
|
||||
} }
|
||||
|
|
@ -4,15 +4,15 @@
|
|||
#include "../Elements/NumberSlider.hpp"
|
||||
|
||||
namespace GUIStuff { namespace ElementHelpers {
|
||||
template <typename T> bool slider_scalar_field(GUIManager& gui, const char* id, std::string_view name, T* val, T min, T max, TextBoxScalarOptions options = {}) {
|
||||
template <typename T> void slider_scalar_field(GUIManager& gui, const char* id, std::string_view name, T* val, T min, T max, TextBoxScalarOptions options = {}) {
|
||||
gui.push_id(id);
|
||||
options.onEdit = [&, oE = options.onEdit] {
|
||||
oE();
|
||||
gui.set_to_layout();
|
||||
};
|
||||
left_to_right_line_layout([&]() {
|
||||
left_to_right_line_layout(gui, [&]() {
|
||||
text_label(gui, name);
|
||||
input_scalar("textbox", val, min, max, options);
|
||||
input_scalar(gui, "textbox", val, min, max, options);
|
||||
});
|
||||
gui.element<NumberSlider<T>>("slider", val, min, max, options.onEdit);
|
||||
gui.pop_id();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include "TextBoxHelpers.hpp"
|
||||
#include "../Elements/TextBox.impl.hpp"
|
||||
#include "LayoutHelpers.hpp"
|
||||
|
||||
namespace GUIStuff { namespace ElementHelpers {
|
||||
|
|
@ -29,7 +28,7 @@ void input_color_component_255(GUIManager& gui, const char* id, float* val, cons
|
|||
return ss.str();
|
||||
};
|
||||
|
||||
gui.element<TextBox<std::string>>(id, d);
|
||||
gui.element<TextBox<float>>(id, d);
|
||||
}
|
||||
|
||||
void input_text(GUIManager& gui, const char* id, std::string* val, const TextBoxOptions& options) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
#include "../GUIManager.hpp"
|
||||
#include "../Elements/TextBox.decl.hpp"
|
||||
#include "../Elements/TextBox.hpp"
|
||||
#include "TextLabelHelpers.hpp"
|
||||
#include "LayoutHelpers.hpp"
|
||||
|
||||
|
|
@ -83,10 +83,10 @@ template <typename T> void input_scalar(GUIManager& gui, const char* id, T* val,
|
|||
std::stringstream ss;
|
||||
if(std::is_floating_point<T>()) {
|
||||
ss.precision(decimalPrecision);
|
||||
ss << std::fixed << *a;
|
||||
ss << std::fixed << a;
|
||||
}
|
||||
else
|
||||
ss << *a;
|
||||
ss << a;
|
||||
return ss.str();
|
||||
};
|
||||
|
||||
|
|
@ -95,7 +95,7 @@ template <typename T> void input_scalar(GUIManager& gui, const char* id, T* val,
|
|||
|
||||
template <typename TContainer, typename T> void input_scalars_field(GUIManager& gui, const char* id, std::string_view name, TContainer* val, size_t elemCount, T minVal, T maxVal, const TextBoxScalarOptions& options = {}) {
|
||||
gui.push_id(id);
|
||||
left_to_right_line_layout([&]() {
|
||||
left_to_right_line_layout(gui, [&]() {
|
||||
text_label(gui, name);
|
||||
for(size_t i = 0; i < elemCount; i++) {
|
||||
gui.push_id(i);
|
||||
|
|
@ -107,7 +107,7 @@ template <typename TContainer, typename T> void input_scalars_field(GUIManager&
|
|||
}
|
||||
|
||||
template <typename T> void input_scalar_field(GUIManager& gui, const char* id, std::string_view name, T* val, T minVal, T maxVal, const TextBoxScalarOptions& options = {}) {
|
||||
left_to_right_line_layout([&]() {
|
||||
left_to_right_line_layout(gui, [&]() {
|
||||
text_label(gui, name);
|
||||
input_scalar<T>(gui, id, val, minVal, maxVal, options);
|
||||
});
|
||||
|
|
@ -125,7 +125,12 @@ template <typename T> void input_color_hex(GUIManager& gui, const char* id, T* v
|
|||
TextBoxData<T> d = textbox_options_to_data<T>(options);
|
||||
d.textInputProps = textInputProps;
|
||||
d.fromStr = [hasAlpha = options.hasAlpha](const std::string& a) {
|
||||
T def = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
T def;
|
||||
def[0] = 0.0f;
|
||||
def[1] = 0.0f;
|
||||
def[2] = 0.0f;
|
||||
if(hasAlpha)
|
||||
def[3] = 1.0f;
|
||||
unsigned startIndex = 0;
|
||||
if(a.empty())
|
||||
return def;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue