Added more settings and actions to phone version

This commit is contained in:
Yousef Khadadeh 2026-05-12 21:13:31 +03:00
parent fd2ce71db6
commit 1b99c64c1b
21 changed files with 388 additions and 179 deletions

View file

@ -19,6 +19,7 @@
#include "ButtonHelpers.hpp"
#include "../Elements/SVGIcon.hpp"
#include "../Elements/LayoutElement.hpp"
#include "Helpers/ConvertVec.hpp"
#include "TextLabelHelpers.hpp"
namespace GUIStuff { namespace ElementHelpers {
@ -37,7 +38,7 @@ void text_button(GUIManager& gui, const char* id, std::string_view text, const T
};
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = options.wide ? CLAY_SIZING_GROW(0) : CLAY_SIZING_FIT(0), .height = CLAY_SIZING_FIT(0) },
.sizing = {.width = options.wide ? CLAY_SIZING_GROW(0) : CLAY_SIZING_FIT(0), .height = options.growHeight ? CLAY_SIZING_GROW(0) : CLAY_SIZING_FIT(0) },
.childAlignment = {.x = options.centered ? CLAY_ALIGN_X_CENTER : CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER}
}
}) {

View file

@ -41,6 +41,7 @@ struct TextButtonOptions {
bool isSelected = false;
bool instantResponse = false;
bool wide = false;
bool growHeight = false;
bool centered = true;
std::function<void()> onClick;

View file

@ -18,12 +18,14 @@
#pragma once
#include "../GUIManager.hpp"
#include "Helpers/ConvertVec.hpp"
#include "TextBoxHelpers.hpp"
#include "../Elements/ColorPicker.hpp"
namespace GUIStuff { namespace ElementHelpers {
struct ColorPickerItemsOptions {
bool forceAspectRatioOnColorPicker = true;
bool hasAlpha = true;
std::function<void()> onEdit;
std::function<void()> onSelect;
@ -40,26 +42,28 @@ template <typename T> void color_picker_items(GUIManager& gui, const char* id, T
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}
},
.aspectRatio = {1.0f}
.aspectRatio = {options.forceAspectRatioOnColorPicker ? 1.0f : 0.0f}
}) {
gui.element<ColorPicker<T>>("c", val, options.hasAlpha, ColorPickerData{ .onChange = fullOnEdit, .onHold = options.onSelect, .onRelease = options.onDeselect });
}
left_to_right_line_layout(gui, [&]() {
text_label(gui, "R");
input_color_component_255(gui, "r", &(*val)[0], { .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect });
text_label(gui, "G");
input_color_component_255(gui, "g", &(*val)[1], { .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect });
text_label(gui, "B");
input_color_component_255(gui, "b", &(*val)[2], { .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect });
if(options.hasAlpha) {
text_label(gui, "A");
input_color_component_255(gui, "a", &(*val)[3], { .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect });
}
});
left_to_right_line_layout(gui, [&]() {
text_label(gui, "Hex");
input_color_hex(gui, "h", val, { .hasAlpha = options.hasAlpha, .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect });
});
if(!gui.io.isTouchDevice) {
left_to_right_line_layout(gui, [&]() {
text_label(gui, "R");
input_color_component_255(gui, "r", &(*val)[0], { .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect });
text_label(gui, "G");
input_color_component_255(gui, "g", &(*val)[1], { .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect });
text_label(gui, "B");
input_color_component_255(gui, "b", &(*val)[2], { .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect });
if(options.hasAlpha) {
text_label(gui, "A");
input_color_component_255(gui, "a", &(*val)[3], { .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect });
}
});
left_to_right_line_layout(gui, [&]() {
text_label(gui, "Hex");
input_color_hex(gui, "h", val, { .hasAlpha = options.hasAlpha, .onEdit = fullOnEdit, .onSelect = options.onSelect, .onDeselect = options.onDeselect });
});
}
});
}

View file

@ -245,7 +245,7 @@ void bottom_offset_setup(GUIManager& gui, float dropdownHeight, Clay_FloatingEle
floatConfig = {
.offset = {
.x = xOffset,
.y = bb.max.y() + d.dropdownOffset
.y = bb.max.y() + d.popupOffset
},
.zIndex = gui.get_z_index(),
.attachPoints = {
@ -255,7 +255,7 @@ void bottom_offset_setup(GUIManager& gui, float dropdownHeight, Clay_FloatingEle
.attachTo = CLAY_ATTACH_TO_ROOT
};
maxHeight = std::max(gui.io.safeWindowRect.max.y() - bb.max.y() - d.dropdownOffset, 0.0f);
maxHeight = std::max(gui.io.safeWindowRect.max.y() - bb.max.y() - d.popupOffset, 0.0f);
}
void top_offset_setup(GUIManager& gui, float dropdownHeight, Clay_FloatingElementConfig& floatConfig, float& maxHeight, const DropDownPopupLayout& d) {
@ -271,7 +271,7 @@ void top_offset_setup(GUIManager& gui, float dropdownHeight, Clay_FloatingElemen
floatConfig = {
.offset = {
.x = xOffset,
.y = bb.min.y() - d.dropdownOffset
.y = bb.min.y() - d.popupOffset
},
.zIndex = gui.get_z_index(),
.attachPoints = {
@ -281,7 +281,7 @@ void top_offset_setup(GUIManager& gui, float dropdownHeight, Clay_FloatingElemen
.attachTo = CLAY_ATTACH_TO_ROOT
};
maxHeight = std::max(bb.min.y() - gui.io.safeWindowRect.min.y() - d.dropdownOffset, 0.0f);
maxHeight = std::max(bb.min.y() - gui.io.safeWindowRect.min.y() - d.popupOffset, 0.0f);
}
void left_right_offset_setup(GUIManager& gui, float dropdownHeight, Clay_FloatingElementConfig& floatConfig, float& maxHeight, bool isRightSide, const DropDownPopupLayout& d) {
@ -293,9 +293,9 @@ void left_right_offset_setup(GUIManager& gui, float dropdownHeight, Clay_Floatin
offsetY -= (offsetY + dropdownHeight) - gui.io.safeWindowRect.max.y();
float offsetX = 0.0f;
if(isRightSide)
offsetX = bb.max.x() + d.dropdownOffset;
offsetX = bb.max.x() + d.popupOffset;
else
offsetX = bb.min.x() - d.entrySize.x() - d.dropdownOffset;
offsetX = bb.min.x() - d.entrySize.x() - d.popupOffset;
floatConfig = {
.offset = {
.x = offsetX,
@ -314,9 +314,9 @@ void left_right_offset_setup(GUIManager& gui, float dropdownHeight, Clay_Floatin
void dropdown_many_element_popup_layout(GUIManager& gui, const char* id, DropDownPopupLayout d) {
if(!d.button->get_bb().has_value())
return;
d.entrySize.x() = std::min(d.entrySize.x(), gui.io.windowSize.x());
d.entrySize.x() = std::min(d.entrySize.x(), gui.io.safeWindowRect.width());
gui.element<LayoutElement>(id, [&](LayoutElement* l, const Clay_ElementId& lId) {
float dropdownHeight = d.entrySize.y() * d.entryCount + d.dropdownOffset;
float dropdownHeight = d.entrySize.y() * d.entryCount + d.popupOffset;
Clay_FloatingElementConfig floatConfig;
float maxHeight = gui.io.safeWindowRect.height();
auto& buttonBB = d.button->get_bb().value();
@ -356,9 +356,88 @@ void dropdown_many_element_popup_layout(GUIManager& gui, const char* id, DropDow
}
}, LayoutElement::Callbacks {
.onClick = [&, d](LayoutElement* l, const InputManager::MouseButtonCallbackArgs& m) {
if(!l->mouseHovering && !l->childMouseHovering && m.down && !d.button->mouseHovering && d.isOpen) {
*d.isOpen = false;
gui.set_to_layout();
if(!l->mouseHovering && !l->childMouseHovering && !d.button->mouseHovering) {
if(m.down && d.clickAwayCallback) {
d.clickAwayCallback();
gui.set_to_layout();
}
if(!m.down && d.clickUpAwayCallback) {
d.clickUpAwayCallback();
gui.set_to_layout();
}
}
}
});
}
void attach_to_button_popup_layout(GUIManager& gui, const char* id, AttachToButtonPopupLayout d) {
if(!d.button->get_bb().has_value())
return;
d.popupSize.x() = std::min(d.popupSize.x(), std::abs(gui.io.safeWindowRect.width() - 10.0f));
d.popupSize.y() = std::min(d.popupSize.y(), std::abs(gui.io.safeWindowRect.height() - 10.0f));
float maxHeight = d.popupSize.y();
gui.element<LayoutElement>(id, [&](LayoutElement* l, const Clay_ElementId& lId) {
Clay_FloatingElementConfig floatConfig;
auto& buttonBB = d.button->get_bb().value();
if(buttonBB.max.y() + d.popupSize.y() > gui.io.safeWindowRect.max.y()) {
float rightSideWidth = gui.io.safeWindowRect.max.x() - buttonBB.max.x();
float leftSideWidth = buttonBB.min.x() - gui.io.safeWindowRect.min.x();
if(rightSideWidth > d.popupSize.x() || leftSideWidth > d.popupSize.x())
left_right_offset_setup(gui, d.popupSize.y(), floatConfig, maxHeight, rightSideWidth >= leftSideWidth, {
.popupOffset = d.popupOffset,
.button = d.button,
.entrySize = d.popupSize
});
else {
if(gui.io.safeWindowRect.max.y() - buttonBB.max.y() >= buttonBB.min.y() - gui.io.safeWindowRect.min.y())
bottom_offset_setup(gui, d.popupSize.y(), floatConfig, maxHeight, {
.popupOffset = d.popupOffset,
.button = d.button,
.entrySize = d.popupSize
});
else
top_offset_setup(gui, d.popupSize.y(), floatConfig, maxHeight, {
.popupOffset = d.popupOffset,
.button = d.button,
.entrySize = d.popupSize
});
}
}
else
bottom_offset_setup(gui, d.popupSize.y(), floatConfig, maxHeight, {
.popupOffset = d.popupOffset,
.button = d.button,
.entrySize = d.popupSize
});
if(maxHeight < d.popupSize.y())
d.popupSize.y() = maxHeight;
CLAY(lId, {
.layout = {
.sizing = {.width = CLAY_SIZING_FIXED(d.popupSize.x()), .height = CLAY_SIZING_FIXED(d.popupSize.y())},
.childGap = 0
},
.backgroundColor = convert_vec4<Clay_Color>(gui.io.theme->backColor1),
.cornerRadius = CLAY_CORNER_RADIUS(4),
.floating = floatConfig,
.border = {
.color = convert_vec4<Clay_Color>(gui.io.theme->fillColor2),
.width = CLAY_BORDER_OUTSIDE(1)
}
}) {
d.innerLayout();
}
}, LayoutElement::Callbacks {
.onClick = [&, d](LayoutElement* l, const InputManager::MouseButtonCallbackArgs& m) {
if(!l->mouseHovering && !l->childMouseHovering && !d.button->mouseHovering) {
if(m.down && d.clickAwayCallback) {
d.clickAwayCallback();
gui.set_to_layout();
}
if(!m.down && d.clickUpAwayCallback) {
d.clickUpAwayCallback();
gui.set_to_layout();
}
}
}
});

View file

@ -42,14 +42,25 @@ void window_fill_side_bar(GUIManager& gui, const WindowFillSideBarConfig& config
void window_gap_side_bar(GUIManager& gui, const WindowFillSideBarConfig::Direction& dir);
struct DropDownPopupLayout {
float dropdownOffset = 4.0f;
float popupOffset = 4.0f;
Element* button = nullptr;
bool* isOpen;
std::function<void()> clickAwayCallback;
std::function<void()> clickUpAwayCallback;
Vector2f entrySize;
size_t entryCount;
std::function<void(size_t i)> entryLayout;
};
struct AttachToButtonPopupLayout {
float popupOffset = 4.0f;
Element* button = nullptr;
std::function<void()> clickAwayCallback;
std::function<void()> clickUpAwayCallback;
Vector2f popupSize;
std::function<void()> innerLayout;
};
void attach_to_button_popup_layout(GUIManager& gui, const char* id, AttachToButtonPopupLayout d);
void dropdown_many_element_popup_layout(GUIManager& gui, const char* id, DropDownPopupLayout d);
}}

View file

@ -20,6 +20,7 @@
#include "../ElementHelpers/ColorPickerItemsHelpers.hpp"
#include "../ElementHelpers/ButtonHelpers.hpp"
#include "../ElementHelpers/LayoutHelpers.hpp"
#include "Helpers/ConvertVec.hpp"
namespace GUIStuff {
@ -28,7 +29,7 @@ template <typename T> ColorPickerButton<T>::ColorPickerButton(GUIManager& gui):
template <typename T> void ColorPickerButton<T>::layout(const Clay_ElementId& id, T* val, const ColorPickerButtonData& d) {
this->data = d;
GUIStuff::ElementHelpers::color_button(gui, "Color Picker Button", val, {
Element* button = GUIStuff::ElementHelpers::color_button(gui, "Color Picker Button", val, {
.isSelected = isOpen,
.hasAlpha = data.hasAlpha,
.onClick = [&]{
@ -38,18 +39,26 @@ template <typename T> void ColorPickerButton<T>::layout(const Clay_ElementId& id
});
if(isOpen) {
gui.set_z_index(gui.get_z_index() + 1, [&] {
ElementHelpers::top_to_bottom_window_popup_layout(gui, "Color Picker", CLAY_SIZING_FIT(300), CLAY_SIZING_FIT(0), [&, val, data = data](LayoutElement*) {
ElementHelpers::color_picker_items(gui, "c", val, {
.hasAlpha = data.hasAlpha,
.onEdit = data.onEdit,
.onSelect = data.onSelect,
.onDeselect = data.onDeselect
});
}, {
.mouseButton = [&](LayoutElement* l, const InputManager::MouseButtonCallbackArgs& button) {
if(!l->mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down) {
isOpen = false;
gui.set_to_layout();
ElementHelpers::attach_to_button_popup_layout(gui, "Color Picker", {
.button = button,
.clickAwayCallback = [&] { isOpen = false; },
.popupSize = {300.0f, 300.0f},
.innerLayout = [&] {
CLAY_AUTO_ID({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
.padding = CLAY_PADDING_ALL(gui.io.theme->padding1),
.childGap = gui.io.theme->childGap1,
.layoutDirection = CLAY_TOP_TO_BOTTOM
},
}) {
ElementHelpers::color_picker_items(gui, "c", val, {
.forceAspectRatioOnColorPicker = false,
.hasAlpha = data.hasAlpha,
.onEdit = data.onEdit,
.onSelect = data.onSelect,
.onDeselect = data.onDeselect
});
}
}
});

View file

@ -94,7 +94,7 @@ template <typename T> class DropDown : public Element {
gui.set_z_index(gui.get_z_index() + 1, [&] {
dropdown_many_element_popup_layout(gui, "DROPDOWN", {
.button = this,
.isOpen = &isOpen,
.clickAwayCallback = [&] { isOpen = false; },
.entrySize = boundingBox.value().dim(),
.entryCount = selections.size(),
.entryLayout = [&](size_t i) {