Added text decoration modifiers, and icon toggle buttons for text modifiers
This commit is contained in:
parent
bc8bd93e3b
commit
644655544c
19 changed files with 373 additions and 51 deletions
|
|
@ -11,12 +11,14 @@ namespace GUIStuff {
|
|||
|
||||
template <typename T> class ColorPicker : public Element {
|
||||
public:
|
||||
void update(UpdateInputData& io, T* newData, bool newSelectAlpha, const std::function<void()>& elemUpdate) {
|
||||
bool update(UpdateInputData& io, T* newData, bool newSelectAlpha, const std::function<void()>& elemUpdate) {
|
||||
bool isChanged = false;
|
||||
|
||||
T* data = newData;
|
||||
selectAlpha = newSelectAlpha;
|
||||
|
||||
if(!data)
|
||||
return;
|
||||
return false;
|
||||
|
||||
force_update_colorpicker(data);
|
||||
|
||||
|
|
@ -39,6 +41,7 @@ template <typename T> class ColorPicker : public Element {
|
|||
Vector2f alphaBarDim = get_alpha_bar_dim();
|
||||
modifyingAlpha = SCollision::collide(SCollision::AABB<float>(alphaBarPos, alphaBarPos + alphaBarDim), io.mouse.pos);
|
||||
}
|
||||
isChanged = true;
|
||||
}
|
||||
if(selection.held && modifyingSv) {
|
||||
float svSelectionAreaSize = bb.width() - (BAR_GAP + BAR_WIDTH);
|
||||
|
|
@ -46,18 +49,21 @@ template <typename T> class ColorPicker : public Element {
|
|||
savedHsv.y() = newSv.x();
|
||||
savedHsv.z() = 1.0f - newSv.y();
|
||||
set_hsv(data, savedHsv);
|
||||
isChanged = true;
|
||||
}
|
||||
if(selection.held && modifyingHue) {
|
||||
Vector2f huePos = get_hue_bar_pos();
|
||||
Vector2f hueDim = get_hue_bar_dim();
|
||||
savedHsv.x() = (1.0f - std::clamp((io.mouse.pos.y() - huePos.y()) / hueDim.y(), 0.0f, 1.0f)) * 360.0f;
|
||||
set_hsv(data, savedHsv);
|
||||
isChanged = true;
|
||||
}
|
||||
if(selection.held && modifyingAlpha) {
|
||||
Vector2f alphaPos = get_alpha_bar_pos();
|
||||
Vector2f alphaDim = get_alpha_bar_dim();
|
||||
(*data)[3] = std::clamp((io.mouse.pos.x() - alphaPos.x()) / alphaDim.x(), 0.0f, 1.0f);
|
||||
oldData = *data;
|
||||
isChanged = true;
|
||||
}
|
||||
if(!selection.held) {
|
||||
modifyingSv = false;
|
||||
|
|
@ -67,6 +73,8 @@ template <typename T> class ColorPicker : public Element {
|
|||
if(elemUpdate)
|
||||
elemUpdate();
|
||||
}
|
||||
|
||||
return isChanged;
|
||||
}
|
||||
|
||||
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command) {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ void SVGIcon::update(UpdateInputData& io, const std::string& newSvgPath, bool ne
|
|||
else {
|
||||
io.svgData[newSvgPath] = newSvgDom;
|
||||
svgDom = newSvgDom;
|
||||
if(svgDom->containerSize().width() == 0 || svgDom->containerSize().height() == 0)
|
||||
svgDom->setContainerSize({1000, 1000});
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -275,6 +275,18 @@ void GUIManager::left_to_right_line_layout(const std::function<void()>& elemUpda
|
|||
left_to_right_layout(CLAY_SIZING_GROW(0), CLAY_SIZING_FIT(0), elemUpdate);
|
||||
}
|
||||
|
||||
void GUIManager::left_to_right_line_centered_layout(const std::function<void()>& elemUpdate) {
|
||||
CLAY({.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) },
|
||||
.childGap = io->theme->childGap1,
|
||||
.childAlignment = {.x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER},
|
||||
.layoutDirection = CLAY_LEFT_TO_RIGHT,
|
||||
}
|
||||
}) {
|
||||
elemUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void GUIManager::text_label_size(const std::string& val, float modifier) {
|
||||
CLAY_TEXT(strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4<Clay_Color>(io->theme->frontColor1), .fontSize = static_cast<uint16_t>(io->fontSize * modifier)}));
|
||||
}
|
||||
|
|
@ -360,9 +372,9 @@ bool GUIManager::radio_button_field(const std::string& id, const std::string& na
|
|||
return toRet;
|
||||
}
|
||||
|
||||
void GUIManager::input_color_component_255(const std::string& id, float* val, const std::function<void(SelectionHelper&)>& elemUpdate) {
|
||||
bool GUIManager::input_color_component_255(const std::string& id, float* val, const std::function<void(SelectionHelper&)>& elemUpdate) {
|
||||
push_id(id);
|
||||
insert_element<TextBox<float>>()->update(*io, val,
|
||||
bool isUpdating = insert_element<TextBox<float>>()->update(*io, val,
|
||||
[&](const std::string& str) {
|
||||
int roundTo255;
|
||||
std::stringstream ss;
|
||||
|
|
@ -377,6 +389,7 @@ void GUIManager::input_color_component_255(const std::string& id, float* val, co
|
|||
return ss.str();
|
||||
}, true, false, elemUpdate);
|
||||
pop_id();
|
||||
return isUpdating;
|
||||
}
|
||||
|
||||
void GUIManager::input_text(const std::string& id, std::string* val, const std::function<void(SelectionHelper&)>& elemUpdate) {
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ class GUIManager {
|
|||
void top_to_bottom_window_popup_layout(Clay_SizingAxis x, Clay_SizingAxis y, const std::function<void()>& elemUpdate);
|
||||
void left_to_right_layout(Clay_SizingAxis x, Clay_SizingAxis y, const std::function<void()>& elemUpdate);
|
||||
void left_to_right_line_layout(const std::function<void()>& elemUpdate);
|
||||
void left_to_right_line_centered_layout(const std::function<void()>& elemUpdate);
|
||||
|
||||
bool selectable_button(const std::string& id, const std::function<void(SelectionHelper&, bool)>& elemUpdate, GUIStuff::SelectableButton::DrawType drawType, bool isSelected);
|
||||
|
||||
|
|
@ -82,7 +83,7 @@ class GUIManager {
|
|||
void scroll_bar_area(const std::string& uniqueId, const std::function<void(float scrollContentHeight, float containerHeight, float scrollAmount)>& elemUpdate);
|
||||
void scroll_bar_many_entries_area(const std::string& uniqueId, float entryHeight, size_t entryCount, const std::function<void(size_t elementIndex, bool listHovered)>& entryUpdate, const std::function<void(float scrollContentHeight, float containerHeight, float scrollAmount)>& elemUpdate = nullptr);
|
||||
|
||||
void input_color_component_255(const std::string& id, float* val, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr);
|
||||
bool input_color_component_255(const std::string& id, float* val, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr);
|
||||
void input_text(const std::string& id, std::string* val, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr);
|
||||
|
||||
bool radio_button(const std::string& id, bool val, const std::function<void()>& elemUpdate = nullptr);
|
||||
|
|
@ -162,18 +163,20 @@ class GUIManager {
|
|||
|
||||
bool input_scalar(const std::string& id, uint8_t* val, uint8_t min, uint8_t max, int decimalPrecision, const std::function<void(SelectionHelper&)>& elemUpdate);
|
||||
|
||||
template <typename TContainer, typename T> void input_scalar_fields(const std::string& id, const std::string& name, TContainer* val, size_t elemCount, T min, T max, int decimalPrecision = 0, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr) {
|
||||
template <typename TContainer, typename T> bool input_scalar_fields(const std::string& id, const std::string& name, TContainer* val, size_t elemCount, T min, T max, int decimalPrecision = 0, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr) {
|
||||
bool isUpdating = false;
|
||||
push_id(id);
|
||||
left_to_right_line_layout([&]() {
|
||||
text_label(name);
|
||||
for(size_t i = 0; i < elemCount; i++)
|
||||
input_scalar<T>(std::to_string(i), &(*val)[i], min, max, decimalPrecision, elemUpdate);
|
||||
isUpdating |= input_scalar<T>(std::to_string(i), &(*val)[i], min, max, decimalPrecision, elemUpdate);
|
||||
});
|
||||
pop_id();
|
||||
return isUpdating;
|
||||
}
|
||||
|
||||
template <typename T> void input_color_hex(const std::string& id, T* val, bool selectAlpha, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr) {
|
||||
input_generic<T>(id, val,
|
||||
template <typename T> bool input_color_hex(const std::string& id, T* val, bool selectAlpha, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr) {
|
||||
return input_generic<T>(id, val,
|
||||
[&](const std::string& str) {
|
||||
T def = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
unsigned startIndex = 0;
|
||||
|
|
@ -209,10 +212,11 @@ class GUIManager {
|
|||
true, false, elemUpdate);
|
||||
}
|
||||
|
||||
template <typename T> void color_picker(const std::string& id, T* val, bool selectAlpha, const std::function<void()>& elemUpdate = nullptr) {
|
||||
template <typename T> bool color_picker(const std::string& id, T* val, bool selectAlpha, const std::function<void()>& elemUpdate = nullptr) {
|
||||
push_id(id);
|
||||
insert_element<ColorPicker<T>>()->update(*io, val, selectAlpha, elemUpdate);
|
||||
bool isUpdating = insert_element<ColorPicker<T>>()->update(*io, val, selectAlpha, elemUpdate);
|
||||
pop_id();
|
||||
return isUpdating;
|
||||
}
|
||||
|
||||
template <typename T> bool slider_scalar(const std::string& id, T* val, T min, T max, const std::function<void()>& elemUpdate = nullptr) {
|
||||
|
|
@ -264,7 +268,8 @@ class GUIManager {
|
|||
}, GUIStuff::SelectableButton::DrawType::TRANSPARENT_BORDER, isSelected);
|
||||
}
|
||||
|
||||
template <typename T> void color_picker_button(const std::string& id, T* val, bool selectAlpha, const std::function<void()>& elemUpdate = nullptr) {
|
||||
template <typename T> bool color_picker_button(const std::string& id, T* val, bool selectAlpha, const std::function<void()>& elemUpdate = nullptr) {
|
||||
bool isUpdating = false;
|
||||
push_id(id);
|
||||
bool& isOpen = insert_any_with_id<bool>(0, false);
|
||||
bool clicked;
|
||||
|
|
@ -275,41 +280,46 @@ class GUIManager {
|
|||
isOpen = true;
|
||||
if(isOpen) {
|
||||
top_to_bottom_window_popup_layout(CLAY_SIZING_FIT(300), CLAY_SIZING_FIT(0), [&]() {
|
||||
color_picker_items("c", val, selectAlpha);
|
||||
isUpdating = color_picker_items("c", val, selectAlpha);
|
||||
if(io->mouse.leftClick && !Clay_Hovered() && !clicked)
|
||||
isOpen = false;
|
||||
});
|
||||
}
|
||||
pop_id();
|
||||
return isUpdating;
|
||||
}
|
||||
|
||||
template <typename T> void color_picker_items(const std::string& id, T* val, bool selectAlpha) {
|
||||
template <typename T> bool color_picker_items(const std::string& id, T* val, bool selectAlpha) {
|
||||
bool isUpdating = false;
|
||||
push_id(id);
|
||||
color_picker("c", val, selectAlpha);
|
||||
isUpdating |= color_picker("c", val, selectAlpha);
|
||||
left_to_right_line_layout([&]() {
|
||||
text_label("R");
|
||||
input_color_component_255("r", &(*val)[0]);
|
||||
isUpdating |= input_color_component_255("r", &(*val)[0]);
|
||||
text_label("G");
|
||||
input_color_component_255("g", &(*val)[1]);
|
||||
isUpdating |= input_color_component_255("g", &(*val)[1]);
|
||||
text_label("B");
|
||||
input_color_component_255("b", &(*val)[2]);
|
||||
isUpdating |= input_color_component_255("b", &(*val)[2]);
|
||||
if(selectAlpha) {
|
||||
text_label("A");
|
||||
input_color_component_255("a", &(*val)[3]);
|
||||
isUpdating |= input_color_component_255("a", &(*val)[3]);
|
||||
}
|
||||
});
|
||||
left_to_right_line_layout([&]() {
|
||||
text_label("Hex");
|
||||
input_color_hex("h", val, selectAlpha);
|
||||
isUpdating |= input_color_hex("h", val, selectAlpha);
|
||||
});
|
||||
pop_id();
|
||||
return isUpdating;
|
||||
}
|
||||
|
||||
template <typename T> void color_picker_button_field(const std::string& id, const std::string& name, T* val, bool selectAlpha, const std::function<void()>& elemUpdate = nullptr) {
|
||||
template <typename T> bool color_picker_button_field(const std::string& id, const std::string& name, T* val, bool selectAlpha, const std::function<void()>& elemUpdate = nullptr) {
|
||||
bool isUpdating = false;
|
||||
left_to_right_line_layout([&]() {
|
||||
color_picker_button(id, val, selectAlpha, elemUpdate);
|
||||
isUpdating = color_picker_button(id, val, selectAlpha, elemUpdate);
|
||||
text_label(name);
|
||||
});
|
||||
return isUpdating;
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue