Elements detect when children are hovered over
This commit is contained in:
parent
e3af067972
commit
031c61146b
33 changed files with 153 additions and 185 deletions
|
|
@ -334,7 +334,7 @@ void DrawingProgram::toolbar_gui() {
|
||||||
auto& t = world.main.toolbar;
|
auto& t = world.main.toolbar;
|
||||||
|
|
||||||
gui.new_id("Drawing Program Toolbar GUI", [&] {
|
gui.new_id("Drawing Program Toolbar GUI", [&] {
|
||||||
gui.element<LayoutElement>("Drawing Program Toolbar GUI", [&] (const Clay_ElementId& lId) {
|
gui.element<LayoutElement>("Drawing Program Toolbar GUI", [&] (LayoutElement*, const Clay_ElementId& lId) {
|
||||||
CLAY(lId, {
|
CLAY(lId, {
|
||||||
.layout = {
|
.layout = {
|
||||||
.sizing = {.width = CLAY_SIZING_FIT(0), .height = CLAY_SIZING_FIT(0)},
|
.sizing = {.width = CLAY_SIZING_FIT(0), .height = CLAY_SIZING_FIT(0)},
|
||||||
|
|
@ -450,7 +450,7 @@ void DrawingProgram::selection_action_menu(Vector2f popupPos) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, LayoutElement::Callbacks{
|
}, LayoutElement::Callbacks{
|
||||||
.mouseButton = [&](const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
.mouseButton = [&](LayoutElement*, const InputManager::MouseButtonCallbackArgs& button) {
|
||||||
if(button.down && button.button != InputManager::MouseButton::RIGHT)
|
if(button.down && button.button != InputManager::MouseButton::RIGHT)
|
||||||
clear_right_click_popup();
|
clear_right_click_popup();
|
||||||
}
|
}
|
||||||
|
|
@ -473,7 +473,7 @@ void DrawingProgram::tool_options_gui() {
|
||||||
auto& io = gui.io;
|
auto& io = gui.io;
|
||||||
|
|
||||||
float minGUIWidth = drawTool->get_type() == DrawingProgramToolType::SCREENSHOT ? 300 : 200;
|
float minGUIWidth = drawTool->get_type() == DrawingProgramToolType::SCREENSHOT ? 300 : 200;
|
||||||
gui.element<LayoutElement>("Drawing program tool options gui", [&] (const Clay_ElementId& lId) {
|
gui.element<LayoutElement>("Drawing program tool options gui", [&] (LayoutElement*, const Clay_ElementId& lId) {
|
||||||
CLAY(lId, {
|
CLAY(lId, {
|
||||||
.layout = {
|
.layout = {
|
||||||
.sizing = {.width = CLAY_SIZING_FIT(minGUIWidth), .height = CLAY_SIZING_FIT(0)},
|
.sizing = {.width = CLAY_SIZING_FIT(minGUIWidth), .height = CLAY_SIZING_FIT(0)},
|
||||||
|
|
|
||||||
|
|
@ -41,14 +41,16 @@ 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) {
|
SelectableButton* svg_icon_button(GUIManager& gui, const char* id, const std::string& svgPath, const SVGButtonOptions& options) {
|
||||||
SelectableButton::Data d = selectable_button_options_to_data(options);
|
SelectableButton::Data d = selectable_button_options_to_data(options);
|
||||||
d.innerContent = [&gui, &svgPath] (const SelectableButton::InnerContentCallbackParameters& p) {
|
d.innerContent = [&gui, &svgPath] (const SelectableButton::InnerContentCallbackParameters& p) {
|
||||||
gui.element<SVGIcon>("icon", svgPath, p.isSelected || p.isHovering || p.isHeld);
|
gui.element<SVGIcon>("icon", svgPath, p.isSelected || p.isHovering || p.isHeld);
|
||||||
};
|
};
|
||||||
|
SelectableButton* toRet;
|
||||||
CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(options.size), .height = CLAY_SIZING_FIXED(options.size) } } }) {
|
CLAY_AUTO_ID({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(options.size), .height = CLAY_SIZING_FIXED(options.size) } } }) {
|
||||||
gui.element<SelectableButton>(id, d);
|
toRet = gui.element<SelectableButton>(id, d);
|
||||||
}
|
}
|
||||||
|
return toRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ struct FixedSizeColorButtonOptions {
|
||||||
|
|
||||||
void text_button(GUIManager& gui, const char* id, std::string_view text, const TextButtonOptions& options = {});
|
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 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 = {});
|
SelectableButton* 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 = {}) {
|
template <typename T> void color_button(GUIManager& gui, const char* id, T* val, const FixedSizeColorButtonOptions& options = {}) {
|
||||||
gui.new_id(id, [&] {
|
gui.new_id(id, [&] {
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
namespace GUIStuff { namespace ElementHelpers {
|
namespace GUIStuff { namespace ElementHelpers {
|
||||||
|
|
||||||
void top_to_bottom_window_popup_layout(GUIManager& gui, const char* id, Clay_SizingAxis x, Clay_SizingAxis y, const std::function<void()>& innerContent, const LayoutElement::Callbacks& callbacks) {
|
void top_to_bottom_window_popup_layout(GUIManager& gui, const char* id, Clay_SizingAxis x, Clay_SizingAxis y, const std::function<void(LayoutElement*)>& innerContent, const LayoutElement::Callbacks& callbacks) {
|
||||||
gui.element<LayoutElement>(id, [&] (const Clay_ElementId& lId) {
|
gui.element<LayoutElement>(id, [&] (LayoutElement* l, const Clay_ElementId& lId) {
|
||||||
CLAY(lId, {
|
CLAY(lId, {
|
||||||
.layout = {
|
.layout = {
|
||||||
.sizing = {.width = x, .height = y },
|
.sizing = {.width = x, .height = y },
|
||||||
|
|
@ -17,7 +17,7 @@ void top_to_bottom_window_popup_layout(GUIManager& gui, const char* id, Clay_Siz
|
||||||
.floating = { .zIndex = gui.get_z_index(), .attachTo = CLAY_ATTACH_TO_PARENT },
|
.floating = { .zIndex = gui.get_z_index(), .attachTo = CLAY_ATTACH_TO_PARENT },
|
||||||
.border = {.color = convert_vec4<Clay_Color>(gui.io.theme->fillColor2), .width = CLAY_BORDER_OUTSIDE(1)}
|
.border = {.color = convert_vec4<Clay_Color>(gui.io.theme->fillColor2), .width = CLAY_BORDER_OUTSIDE(1)}
|
||||||
}) {
|
}) {
|
||||||
innerContent();
|
innerContent(l);
|
||||||
}
|
}
|
||||||
}, callbacks);
|
}, callbacks);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
namespace GUIStuff { namespace ElementHelpers {
|
namespace GUIStuff { namespace ElementHelpers {
|
||||||
|
|
||||||
void top_to_bottom_window_popup_layout(GUIManager& gui, const char* id, Clay_SizingAxis x, Clay_SizingAxis y, const std::function<void()>& innerContent, const LayoutElement::Callbacks& callbacks);
|
void top_to_bottom_window_popup_layout(GUIManager& gui, const char* id, Clay_SizingAxis x, Clay_SizingAxis y, const std::function<void(LayoutElement*)>& innerContent, const LayoutElement::Callbacks& callbacks);
|
||||||
void left_to_right_layout(GUIManager& gui, Clay_SizingAxis x, Clay_SizingAxis y, const std::function<void()>& innerContent);
|
void left_to_right_layout(GUIManager& gui, Clay_SizingAxis x, Clay_SizingAxis y, const std::function<void()>& innerContent);
|
||||||
void left_to_right_line_layout(GUIManager& gui, const std::function<void()>& innerContent);
|
void left_to_right_line_layout(GUIManager& gui, const std::function<void()>& innerContent);
|
||||||
void left_to_right_line_centered_layout(GUIManager& gui, const std::function<void()>& innerContent);
|
void left_to_right_line_centered_layout(GUIManager& gui, const std::function<void()>& innerContent);
|
||||||
|
|
|
||||||
|
|
@ -20,16 +20,9 @@ void CheckBox::layout(const Clay_ElementId& id, const std::function<bool()>& isT
|
||||||
}) {}
|
}) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBox::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
void CheckBox::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||||
isHovering = mouseHovering;
|
if(mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down)
|
||||||
if(isHovering && button.button == InputManager::MouseButton::LEFT && button.down)
|
|
||||||
gui.set_post_callback_func([&](){if(onClick) onClick();});
|
gui.set_post_callback_func([&](){if(onClick) onClick();});
|
||||||
return Element::input_mouse_button_callback(button, mouseHovering);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckBox::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) {
|
|
||||||
isHovering = mouseHovering;
|
|
||||||
return Element::input_mouse_motion_callback(motion, mouseHovering);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckBox::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) {
|
void CheckBox::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) {
|
||||||
|
|
@ -50,7 +43,7 @@ void CheckBox::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderComma
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SkRect checkBox = SkRect::MakeLTRB(-0.45f, -0.45f, 0.45f, 0.45f);
|
SkRect checkBox = SkRect::MakeLTRB(-0.45f, -0.45f, 0.45f, 0.45f);
|
||||||
p.setColor4f(convert_vec4<SkColor4f>(isHovering ? io.theme->fillColor1 : io.theme->fillColor2));
|
p.setColor4f(convert_vec4<SkColor4f>(mouseHovering ? io.theme->fillColor1 : io.theme->fillColor2));
|
||||||
p.setStyle(SkPaint::kStroke_Style);
|
p.setStyle(SkPaint::kStroke_Style);
|
||||||
p.setStrokeWidth(0.15f);
|
p.setStrokeWidth(0.15f);
|
||||||
canvas->drawRoundRect(checkBox, 0.25f, 0.25f, p);
|
canvas->drawRoundRect(checkBox, 0.25f, 0.25f, p);
|
||||||
|
|
@ -77,7 +70,7 @@ void CheckBox::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderComma
|
||||||
|
|
||||||
static BezierEasing anim{0.445, -0.733, 0.575, 1.627};
|
static BezierEasing anim{0.445, -0.733, 0.575, 1.627};
|
||||||
|
|
||||||
float lerpTime2 = anim(smooth_two_way_time(hoverAnimation2, io.deltaTime, isHovering, CHECKBOX_ANIMATION_TIME));
|
float lerpTime2 = anim(smooth_two_way_time(hoverAnimation2, io.deltaTime, mouseHovering, CHECKBOX_ANIMATION_TIME));
|
||||||
|
|
||||||
std::array<Vector2f, 5> points;
|
std::array<Vector2f, 5> points;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,11 @@ class CheckBox : public Element {
|
||||||
CheckBox(GUIManager& gui);
|
CheckBox(GUIManager& gui);
|
||||||
|
|
||||||
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override;
|
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override;
|
||||||
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override;
|
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) override;
|
||||||
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override;
|
|
||||||
|
|
||||||
void layout(const Clay_ElementId& id, const std::function<bool()>& isTicked, const std::function<void()>& onClick);
|
void layout(const Clay_ElementId& id, const std::function<bool()>& isTicked, const std::function<void()>& onClick);
|
||||||
private:
|
private:
|
||||||
static constexpr float CHECKBOX_ANIMATION_TIME = 0.3;
|
static constexpr float CHECKBOX_ANIMATION_TIME = 0.3;
|
||||||
bool isHovering = false;
|
|
||||||
float hoverAnimation2 = 0.0;
|
float hoverAnimation2 = 0.0;
|
||||||
std::function<bool()> isTicked;
|
std::function<bool()> isTicked;
|
||||||
std::function<void()> onClick;
|
std::function<void()> onClick;
|
||||||
|
|
|
||||||
|
|
@ -63,8 +63,8 @@ template <typename T> class ColorPicker : public Element {
|
||||||
ColorPicker(GUIManager& gui);
|
ColorPicker(GUIManager& gui);
|
||||||
void layout(const Clay_ElementId& id, T* data, bool selectAlpha, const std::function<void()>& onChange);
|
void layout(const Clay_ElementId& id, T* data, bool selectAlpha, const std::function<void()>& onChange);
|
||||||
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA);
|
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA);
|
||||||
void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override;
|
void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) override;
|
||||||
void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override;
|
void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) override;
|
||||||
private:
|
private:
|
||||||
void update_color_picker_pos(const Vector2f& p);
|
void update_color_picker_pos(const Vector2f& p);
|
||||||
float get_sv_selection_area_size();
|
float get_sv_selection_area_size();
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ template <typename T> void ColorPicker<T>::clay_draw(SkCanvas* canvas, UpdateInp
|
||||||
canvas->restore();
|
canvas->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void ColorPicker<T>::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
template <typename T> void ColorPicker<T>::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||||
held = HeldBar::NONE;
|
held = HeldBar::NONE;
|
||||||
if(mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down && boundingBox.has_value()) {
|
if(mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down && boundingBox.has_value()) {
|
||||||
auto& bb = boundingBox.value();
|
auto& bb = boundingBox.value();
|
||||||
|
|
@ -103,12 +103,10 @@ template <typename T> void ColorPicker<T>::input_mouse_button_callback(const Inp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update_color_picker_pos(button.pos);
|
update_color_picker_pos(button.pos);
|
||||||
Element::input_mouse_button_callback(button, mouseHovering);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void ColorPicker<T>::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) {
|
template <typename T> void ColorPicker<T>::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) {
|
||||||
update_color_picker_pos(motion.pos);
|
update_color_picker_pos(motion.pos);
|
||||||
Element::input_mouse_motion_callback(motion, mouseHovering);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void ColorPicker<T>::update_color_picker_pos(const Vector2f& p) {
|
template <typename T> void ColorPicker<T>::update_color_picker_pos(const Vector2f& p) {
|
||||||
|
|
|
||||||
|
|
@ -19,18 +19,17 @@ template <typename T> void ColorPickerButton<T>::layout(const Clay_ElementId& id
|
||||||
});
|
});
|
||||||
if(isOpen) {
|
if(isOpen) {
|
||||||
gui.set_z_index(gui.get_z_index() + 1, [&] {
|
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]() {
|
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, {
|
ElementHelpers::color_picker_items(gui, "c", val, {
|
||||||
.hasAlpha = data.hasAlpha,
|
.hasAlpha = data.hasAlpha,
|
||||||
.onEdit = data.onEdit
|
.onEdit = data.onEdit
|
||||||
});
|
});
|
||||||
}, {
|
}, {
|
||||||
.mouseButton = [&](const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
.mouseButton = [&](LayoutElement* l, const InputManager::MouseButtonCallbackArgs& button) {
|
||||||
if(!mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down) {
|
if(!l->mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down) {
|
||||||
isOpen = false;
|
isOpen = false;
|
||||||
gui.set_to_layout();
|
gui.set_to_layout();
|
||||||
}
|
}
|
||||||
return mouseHovering;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ template <typename T> class DropDown : public Element {
|
||||||
|
|
||||||
if(isOpen) {
|
if(isOpen) {
|
||||||
gui.set_z_index(gui.get_z_index() + 1, [&] {
|
gui.set_z_index(gui.get_z_index() + 1, [&] {
|
||||||
gui.element<LayoutElement>("DROPDOWN", [&](const Clay_ElementId& lId) {
|
gui.element<LayoutElement>("DROPDOWN", [&](LayoutElement*, const Clay_ElementId& lId) {
|
||||||
Clay_ElementData dropdownElemData = Clay_GetElementData(lId);
|
Clay_ElementData dropdownElemData = Clay_GetElementData(lId);
|
||||||
float calculatedDropdownMaxHeight = 0.0f;
|
float calculatedDropdownMaxHeight = 0.0f;
|
||||||
if(dropdownElemData.found)
|
if(dropdownElemData.found)
|
||||||
|
|
@ -87,7 +87,7 @@ template <typename T> class DropDown : public Element {
|
||||||
.clipHorizontal = true,
|
.clipHorizontal = true,
|
||||||
.elementContent = [&](size_t i) {
|
.elementContent = [&](size_t i) {
|
||||||
bool selectedEntry = static_cast<size_t>(*data) == i;
|
bool selectedEntry = static_cast<size_t>(*data) == i;
|
||||||
gui.element<LayoutElement>("elem", [&] (const Clay_ElementId& lId) {
|
gui.element<LayoutElement>("elem", [&] (LayoutElement*, const Clay_ElementId& lId) {
|
||||||
CLAY(lId, {
|
CLAY(lId, {
|
||||||
.layout = {
|
.layout = {
|
||||||
.sizing = {.width = CLAY_SIZING_FIXED(250), .height = CLAY_SIZING_FIXED(18)},
|
.sizing = {.width = CLAY_SIZING_FIXED(250), .height = CLAY_SIZING_FIXED(18)},
|
||||||
|
|
@ -117,9 +117,9 @@ template <typename T> class DropDown : public Element {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, LayoutElement::Callbacks {
|
}, LayoutElement::Callbacks {
|
||||||
.mouseButton = [&, i](const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
.mouseButton = [&, i](LayoutElement* l, const InputManager::MouseButtonCallbackArgs& button) {
|
||||||
update_hovering_over(i, mouseHovering);
|
update_hovering_over(i, l->mouseHovering);
|
||||||
if(mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down) {
|
if(l->mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down) {
|
||||||
gui.set_post_callback_func([&, i] {
|
gui.set_post_callback_func([&, i] {
|
||||||
*d = i;
|
*d = i;
|
||||||
isOpen = false;
|
isOpen = false;
|
||||||
|
|
@ -127,11 +127,9 @@ template <typename T> class DropDown : public Element {
|
||||||
});
|
});
|
||||||
gui.set_to_layout();
|
gui.set_to_layout();
|
||||||
}
|
}
|
||||||
return mouseHovering;
|
|
||||||
},
|
},
|
||||||
.mouseMotion = [&, i](const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) {
|
.mouseMotion = [&, i](LayoutElement* l, const InputManager::MouseMotionCallbackArgs& motion) {
|
||||||
update_hovering_over(i, mouseHovering);
|
update_hovering_over(i, l->mouseHovering);
|
||||||
return mouseHovering;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ namespace GUIStuff {
|
||||||
|
|
||||||
void Element::tick_update() {}
|
void Element::tick_update() {}
|
||||||
|
|
||||||
void Element::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { }
|
void Element::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) { }
|
||||||
void Element::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) { }
|
void Element::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) { }
|
||||||
void Element::input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering) { }
|
void Element::input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel) { }
|
||||||
void Element::input_key_callback(const InputManager::KeyCallbackArgs& key) {}
|
void Element::input_key_callback(const InputManager::KeyCallbackArgs& key) {}
|
||||||
|
|
||||||
void Element::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) {}
|
void Element::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) {}
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,17 @@ namespace GUIStuff {
|
||||||
virtual ~Element() = default;
|
virtual ~Element() = default;
|
||||||
|
|
||||||
int16_t zIndex;
|
int16_t zIndex;
|
||||||
|
bool mouseHovering = false;
|
||||||
|
bool childMouseHovering = false;
|
||||||
|
|
||||||
|
Element* parent = nullptr;
|
||||||
|
|
||||||
virtual void tick_update();
|
virtual void tick_update();
|
||||||
|
|
||||||
// Return true when mouse obstructs what's behind it
|
// Return true when mouse obstructs what's behind it
|
||||||
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering);
|
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button);
|
||||||
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering);
|
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion);
|
||||||
virtual void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering);
|
virtual void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel);
|
||||||
virtual void input_key_callback(const InputManager::KeyCallbackArgs& key);
|
virtual void input_key_callback(const InputManager::KeyCallbackArgs& key);
|
||||||
protected:
|
protected:
|
||||||
static SCollision::AABB<float> get_bb_from_command(Clay_RenderCommand* command);
|
static SCollision::AABB<float> get_bb_from_command(Clay_RenderCommand* command);
|
||||||
|
|
|
||||||
|
|
@ -5,28 +5,25 @@ namespace GUIStuff {
|
||||||
|
|
||||||
LayoutElement::LayoutElement(GUIManager& gui): Element(gui) {}
|
LayoutElement::LayoutElement(GUIManager& gui): Element(gui) {}
|
||||||
|
|
||||||
void LayoutElement::layout(const Clay_ElementId& id, const std::function<void(const Clay_ElementId&)>& layout, const Callbacks& c) {
|
void LayoutElement::layout(const Clay_ElementId& id, const std::function<void(LayoutElement*, const Clay_ElementId&)>& layout, const Callbacks& c) {
|
||||||
this->c = c;
|
this->c = c;
|
||||||
layout(id);
|
layout(this, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutElement::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
void LayoutElement::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||||
if(c.mouseButton) c.mouseButton(button, mouseHovering);
|
if(c.mouseButton) c.mouseButton(this, button);
|
||||||
return Element::input_mouse_button_callback(button, mouseHovering);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutElement::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) {
|
void LayoutElement::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) {
|
||||||
if(c.mouseMotion) c.mouseMotion(motion, mouseHovering);
|
if(c.mouseMotion) c.mouseMotion(this, motion);
|
||||||
return Element::input_mouse_motion_callback(motion, mouseHovering);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutElement::input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering) {
|
void LayoutElement::input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel) {
|
||||||
if(c.mouseWheel) c.mouseWheel(wheel, mouseHovering);
|
if(c.mouseWheel) c.mouseWheel(this, wheel);
|
||||||
return Element::input_mouse_wheel_callback(wheel, mouseHovering);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutElement::input_key_callback(const InputManager::KeyCallbackArgs& key) {
|
void LayoutElement::input_key_callback(const InputManager::KeyCallbackArgs& key) {
|
||||||
if(c.key) c.key(key);
|
if(c.key) c.key(this, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,15 @@ class LayoutElement : public Element {
|
||||||
public:
|
public:
|
||||||
LayoutElement(GUIManager& gui);
|
LayoutElement(GUIManager& gui);
|
||||||
struct Callbacks {
|
struct Callbacks {
|
||||||
std::function<void(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering)> mouseButton;
|
std::function<void(LayoutElement* l, const InputManager::MouseButtonCallbackArgs& button)> mouseButton;
|
||||||
std::function<void(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering)> mouseMotion;
|
std::function<void(LayoutElement* l, const InputManager::MouseMotionCallbackArgs& motion)> mouseMotion;
|
||||||
std::function<void(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering)> mouseWheel;
|
std::function<void(LayoutElement* l, const InputManager::MouseWheelCallbackArgs& wheel)> mouseWheel;
|
||||||
std::function<void(const InputManager::KeyCallbackArgs& key)> key;
|
std::function<void(LayoutElement* l, const InputManager::KeyCallbackArgs& key)> key;
|
||||||
};
|
};
|
||||||
void layout(const Clay_ElementId& id, const std::function<void(const Clay_ElementId&)>& layout, const Callbacks& c = {});
|
void layout(const Clay_ElementId& id, const std::function<void(LayoutElement*, const Clay_ElementId&)>& layout, const Callbacks& c = {});
|
||||||
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override;
|
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) override;
|
||||||
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override;
|
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) override;
|
||||||
virtual void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering) override;
|
virtual void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel) override;
|
||||||
virtual void input_key_callback(const InputManager::KeyCallbackArgs& key) override;
|
virtual void input_key_callback(const InputManager::KeyCallbackArgs& key) override;
|
||||||
private:
|
private:
|
||||||
Callbacks c;
|
Callbacks c;
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ template <typename T> class NumberSlider : public Element {
|
||||||
canvas->save();
|
canvas->save();
|
||||||
canvas->translate(bb.min.x(), bb.min.y());
|
canvas->translate(bb.min.x(), bb.min.y());
|
||||||
|
|
||||||
float lerpTimeHover = smooth_two_way_time(hoverAnimation, io.deltaTime, isHovering, io.theme->hoverExpandTime);
|
float lerpTimeHover = smooth_two_way_time(hoverAnimation, io.deltaTime, mouseHovering, io.theme->hoverExpandTime);
|
||||||
|
|
||||||
static BezierEasing easeHeight(0.68, -1.55, 0.265, 2.55);
|
static BezierEasing easeHeight(0.68, -1.55, 0.265, 2.55);
|
||||||
|
|
||||||
|
|
@ -73,19 +73,15 @@ template <typename T> class NumberSlider : public Element {
|
||||||
|
|
||||||
canvas->restore();
|
canvas->restore();
|
||||||
}
|
}
|
||||||
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override {
|
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) override {
|
||||||
isHovering = mouseHovering;
|
isHeld = mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down;
|
||||||
isHeld = isHovering && button.button == InputManager::MouseButton::LEFT && button.down;
|
|
||||||
if(isHeld && boundingBox.has_value())
|
if(isHeld && boundingBox.has_value())
|
||||||
update_slider_pos(button.pos);
|
update_slider_pos(button.pos);
|
||||||
Element::input_mouse_button_callback(button, mouseHovering);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override {
|
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) override {
|
||||||
isHovering = mouseHovering;
|
|
||||||
if(isHeld && boundingBox.has_value())
|
if(isHeld && boundingBox.has_value())
|
||||||
update_slider_pos(motion.pos);
|
update_slider_pos(motion.pos);
|
||||||
Element::input_mouse_motion_callback(motion, mouseHovering);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -98,7 +94,6 @@ template <typename T> class NumberSlider : public Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isHeld = false;
|
bool isHeld = false;
|
||||||
bool isHovering = false;
|
|
||||||
T* data = nullptr;
|
T* data = nullptr;
|
||||||
T minData = 0.0;
|
T minData = 0.0;
|
||||||
T maxData = 1.0;
|
T maxData = 1.0;
|
||||||
|
|
|
||||||
|
|
@ -30,27 +30,23 @@ bool PaintCircleMenu::collides_with_point(const Vector2f& p) const {
|
||||||
return boundingBox.has_value() && SCollision::collide(SCollision::Circle<float>(boundingBox.value().center(), CIRCLE_END), p) && !SCollision::collide(SCollision::Circle<float>(boundingBox.value().center(), PALETTE_START), p);
|
return boundingBox.has_value() && SCollision::collide(SCollision::Circle<float>(boundingBox.value().center(), CIRCLE_END), p) && !SCollision::collide(SCollision::Circle<float>(boundingBox.value().center(), PALETTE_START), p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaintCircleMenu::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
void PaintCircleMenu::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||||
if(d.mouseButton) d.mouseButton(button, mouseHovering);
|
if(d.mouseButton) d.mouseButton(button, mouseHovering);
|
||||||
isHovering = mouseHovering;
|
isHeld = mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down;
|
||||||
isHeld = isHovering && button.button == InputManager::MouseButton::LEFT && button.down;
|
|
||||||
update_paint_circle_menu_mouse_hover(button.pos);
|
update_paint_circle_menu_mouse_hover(button.pos);
|
||||||
isRotateBarHeld = isRotateBarHovered && isHeld;
|
isRotateBarHeld = isRotateBarHovered && isHeld;
|
||||||
update_paint_circle_menu_mouse(button.pos, button.button == InputManager::MouseButton::LEFT && button.down);
|
update_paint_circle_menu_mouse(button.pos, button.button == InputManager::MouseButton::LEFT && button.down);
|
||||||
Element::input_mouse_button_callback(button, mouseHovering);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaintCircleMenu::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) {
|
void PaintCircleMenu::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) {
|
||||||
isHovering = mouseHovering;
|
|
||||||
update_paint_circle_menu_mouse_hover(motion.pos);
|
update_paint_circle_menu_mouse_hover(motion.pos);
|
||||||
update_paint_circle_menu_mouse(motion.pos, false);
|
update_paint_circle_menu_mouse(motion.pos, false);
|
||||||
Element::input_mouse_motion_callback(motion, mouseHovering);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaintCircleMenu::update_paint_circle_menu_mouse_hover(const Vector2f& p) {
|
void PaintCircleMenu::update_paint_circle_menu_mouse_hover(const Vector2f& p) {
|
||||||
float distFromCenter = vec_distance(p, boundingBox.value().center());
|
float distFromCenter = vec_distance(p, boundingBox.value().center());
|
||||||
isRotateBarHovered = isHovering && distFromCenter > ROTATE_START && distFromCenter < CIRCLE_END;
|
isRotateBarHovered = mouseHovering && distFromCenter > ROTATE_START && distFromCenter < CIRCLE_END;
|
||||||
isColorBarHovered = isHovering && distFromCenter > PALETTE_START && distFromCenter < ROTATE_START;
|
isColorBarHovered = mouseHovering && distFromCenter > PALETTE_START && distFromCenter < ROTATE_START;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaintCircleMenu::update_paint_circle_menu_mouse(const Vector2f& p, bool leftClicked) {
|
void PaintCircleMenu::update_paint_circle_menu_mouse(const Vector2f& p, bool leftClicked) {
|
||||||
|
|
|
||||||
|
|
@ -17,14 +17,13 @@ class PaintCircleMenu : public Element {
|
||||||
void layout(const Clay_ElementId& id, const Data& data);
|
void layout(const Clay_ElementId& id, const Data& data);
|
||||||
virtual bool collides_with_point(const Vector2f& p) const override;
|
virtual bool collides_with_point(const Vector2f& p) const override;
|
||||||
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override;
|
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override;
|
||||||
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override;
|
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) override;
|
||||||
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override;
|
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) override;
|
||||||
private:
|
private:
|
||||||
void draw_rotate_bar(SkCanvas* canvas, UpdateInputData& io, bool skiaAA);
|
void draw_rotate_bar(SkCanvas* canvas, UpdateInputData& io, bool skiaAA);
|
||||||
void draw_palette_bar(SkCanvas* canvas, UpdateInputData& io, bool skiaAA);
|
void draw_palette_bar(SkCanvas* canvas, UpdateInputData& io, bool skiaAA);
|
||||||
Data d;
|
Data d;
|
||||||
unsigned colorSelectionIndex = 0;
|
unsigned colorSelectionIndex = 0;
|
||||||
bool isHovering = false;
|
|
||||||
bool isRotateBarHeld = false;
|
bool isRotateBarHeld = false;
|
||||||
bool isRotateBarHovered = false;
|
bool isRotateBarHovered = false;
|
||||||
bool isColorBarHovered = false;
|
bool isColorBarHovered = false;
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ void PositionAdjustingPopupMenu::layout(const Clay_ElementId& id, Vector2f popup
|
||||||
popupPos.x() -= bb.width();
|
popupPos.x() -= bb.width();
|
||||||
}
|
}
|
||||||
|
|
||||||
layoutElement = gui.element<LayoutElement>("popup", [&] (const Clay_ElementId& lId) {
|
layoutElement = gui.element<LayoutElement>("popup", [&] (LayoutElement*, const Clay_ElementId& lId) {
|
||||||
CLAY(lId, {
|
CLAY(lId, {
|
||||||
.layout = {
|
.layout = {
|
||||||
.sizing = {.width = CLAY_SIZING_FIT(100), .height = CLAY_SIZING_FIT(0)},
|
.sizing = {.width = CLAY_SIZING_FIT(100), .height = CLAY_SIZING_FIT(0)},
|
||||||
|
|
|
||||||
|
|
@ -18,16 +18,9 @@ void RadioButton::layout(const Clay_ElementId& id, const std::function<bool()>&
|
||||||
}) {}
|
}) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadioButton::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
void RadioButton::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||||
isHovering = mouseHovering;
|
if(mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down)
|
||||||
if(isHovering && button.button == InputManager::MouseButton::LEFT && button.down)
|
|
||||||
gui.set_post_callback_func([&] { if(onClick) onClick(); });
|
gui.set_post_callback_func([&] { if(onClick) onClick(); });
|
||||||
Element::input_mouse_button_callback(button, mouseHovering);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RadioButton::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) {
|
|
||||||
isHovering = mouseHovering;
|
|
||||||
Element::input_mouse_motion_callback(motion, mouseHovering);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadioButton::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) {
|
void RadioButton::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) {
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,7 @@ class RadioButton : public Element {
|
||||||
public:
|
public:
|
||||||
RadioButton(GUIManager& gui);
|
RadioButton(GUIManager& gui);
|
||||||
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override;
|
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override;
|
||||||
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override;
|
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) override;
|
||||||
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override;
|
|
||||||
|
|
||||||
void layout(const Clay_ElementId& id, const std::function<bool()>& isTicked, const std::function<void()>& onClick);
|
void layout(const Clay_ElementId& id, const std::function<bool()>& isTicked, const std::function<void()>& onClick);
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -34,25 +34,23 @@ float RotateWheel::wheel_end() {
|
||||||
return boundingBox.value().width() * 0.5f;
|
return boundingBox.value().width() * 0.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotateWheel::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
void RotateWheel::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||||
isHovering = mouseHovering;
|
isHeld = mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down;
|
||||||
isHeld = isHovering && button.button == InputManager::MouseButton::LEFT && button.down;
|
|
||||||
update_rotate_wheel_mouse_hover(button.pos);
|
update_rotate_wheel_mouse_hover(button.pos);
|
||||||
isRotateBarHeld = isRotateBarHovered && isHeld;
|
isRotateBarHeld = isRotateBarHovered && isHeld;
|
||||||
update_rotate_wheel_mouse(button.pos);
|
update_rotate_wheel_mouse(button.pos);
|
||||||
Element::input_mouse_button_callback(button, mouseHovering);
|
Element::input_mouse_button_callback(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotateWheel::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) {
|
void RotateWheel::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) {
|
||||||
isHovering = mouseHovering;
|
|
||||||
update_rotate_wheel_mouse_hover(motion.pos);
|
update_rotate_wheel_mouse_hover(motion.pos);
|
||||||
update_rotate_wheel_mouse(motion.pos);
|
update_rotate_wheel_mouse(motion.pos);
|
||||||
Element::input_mouse_motion_callback(motion, mouseHovering);
|
Element::input_mouse_motion_callback(motion);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotateWheel::update_rotate_wheel_mouse_hover(const Vector2f& p) {
|
void RotateWheel::update_rotate_wheel_mouse_hover(const Vector2f& p) {
|
||||||
float distFromCenter = vec_distance(p, boundingBox.value().center());
|
float distFromCenter = vec_distance(p, boundingBox.value().center());
|
||||||
isRotateBarHovered = isHovering && distFromCenter > wheel_start() && distFromCenter < wheel_end();
|
isRotateBarHovered = mouseHovering && distFromCenter > wheel_start() && distFromCenter < wheel_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotateWheel::update_rotate_wheel_mouse(const Vector2f& p) {
|
void RotateWheel::update_rotate_wheel_mouse(const Vector2f& p) {
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ class RotateWheel : public Element {
|
||||||
RotateWheel(GUIManager& gui);
|
RotateWheel(GUIManager& gui);
|
||||||
void layout(const Clay_ElementId& id, double* rotateAngle, const std::function<void()>& onChange);
|
void layout(const Clay_ElementId& id, double* rotateAngle, const std::function<void()>& onChange);
|
||||||
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override;
|
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override;
|
||||||
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override;
|
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) override;
|
||||||
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override;
|
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float wheel_start();
|
float wheel_start();
|
||||||
|
|
@ -18,7 +18,6 @@ class RotateWheel : public Element {
|
||||||
|
|
||||||
double* rotateAngle = nullptr;
|
double* rotateAngle = nullptr;
|
||||||
bool isHeld = false;
|
bool isHeld = false;
|
||||||
bool isHovering = false;
|
|
||||||
bool isRotateBarHeld = false;
|
bool isRotateBarHeld = false;
|
||||||
bool isRotateBarHovered = false;
|
bool isRotateBarHovered = false;
|
||||||
std::function<void()> onChange;
|
std::function<void()> onChange;
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ void ScrollArea::layout(const Clay_ElementId& id, const Options& options) {
|
||||||
float scrollerPos = std::fabs(scrollOffset.y() / scrollPosMax);
|
float scrollerPos = std::fabs(scrollOffset.y() / scrollPosMax);
|
||||||
float areaAboveScrollerSize = scrollerPos * (sAreaDim - scrollerSize);
|
float areaAboveScrollerSize = scrollerPos * (sAreaDim - scrollerSize);
|
||||||
|
|
||||||
gui.element<LayoutElement>("scroll bar", [&] (const Clay_ElementId& lId) {
|
gui.element<LayoutElement>("scroll bar", [&] (LayoutElement*, const Clay_ElementId& lId) {
|
||||||
CLAY(lId, {
|
CLAY(lId, {
|
||||||
.layout = {
|
.layout = {
|
||||||
.sizing = {.width = CLAY_SIZING_FIXED(12), .height = CLAY_SIZING_GROW(0)},
|
.sizing = {.width = CLAY_SIZING_FIXED(12), .height = CLAY_SIZING_GROW(0)},
|
||||||
|
|
@ -71,28 +71,27 @@ void ScrollArea::layout(const Clay_ElementId& id, const Options& options) {
|
||||||
}
|
}
|
||||||
}) {}
|
}) {}
|
||||||
|
|
||||||
gui.element<LayoutElement>("scroller", [&] (const Clay_ElementId& lId2) {
|
gui.element<LayoutElement>("scroller", [&] (LayoutElement*, const Clay_ElementId& lId2) {
|
||||||
CLAY(lId2, {
|
CLAY(lId2, {
|
||||||
.layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(scrollerSize)}},
|
.layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(scrollerSize)}},
|
||||||
.backgroundColor = convert_vec4<Clay_Color>(scrollerColor),
|
.backgroundColor = convert_vec4<Clay_Color>(scrollerColor),
|
||||||
.cornerRadius = CLAY_CORNER_RADIUS(3),
|
.cornerRadius = CLAY_CORNER_RADIUS(3),
|
||||||
}) {}
|
}) {}
|
||||||
}, LayoutElement::Callbacks{
|
}, LayoutElement::Callbacks{
|
||||||
.mouseMotion = [&] (const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) {
|
.mouseMotion = [&] (LayoutElement* t, const InputManager::MouseMotionCallbackArgs& motion) {
|
||||||
if(isHoveringOverScrollerY != mouseHovering) {
|
if(isHoveringOverScrollerY != t->mouseHovering) {
|
||||||
isHoveringOverScrollerY = mouseHovering;
|
isHoveringOverScrollerY = t->mouseHovering;
|
||||||
gui.set_to_layout();
|
gui.set_to_layout();
|
||||||
}
|
}
|
||||||
return mouseHovering;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
CLAY_AUTO_ID({ .layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}}) {}
|
CLAY_AUTO_ID({ .layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}}) {}
|
||||||
}
|
}
|
||||||
}, LayoutElement::Callbacks{
|
}, LayoutElement::Callbacks{
|
||||||
.mouseButton = [&, scrollPosMax, sAreaStart, sAreaDim, scrollerSize, areaAboveScrollerSize](const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
.mouseButton = [&, scrollPosMax, sAreaStart, sAreaDim, scrollerSize, areaAboveScrollerSize](LayoutElement* t, const InputManager::MouseButtonCallbackArgs& button) {
|
||||||
if(button.button == InputManager::MouseButton::LEFT) {
|
if(button.button == InputManager::MouseButton::LEFT) {
|
||||||
if(button.down && mouseHovering) {
|
if(button.down && t->mouseHovering) {
|
||||||
isScrollbarHeldY = true;
|
isScrollbarHeldY = true;
|
||||||
if(isHoveringOverScrollerY)
|
if(isHoveringOverScrollerY)
|
||||||
scrollerStartPosY = sAreaStart + areaAboveScrollerSize + scrollerSize * 0.5f;
|
scrollerStartPosY = sAreaStart + areaAboveScrollerSize + scrollerSize * 0.5f;
|
||||||
|
|
@ -112,11 +111,10 @@ void ScrollArea::layout(const Clay_ElementId& id, const Options& options) {
|
||||||
gui.set_to_layout();
|
gui.set_to_layout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mouseHovering;
|
|
||||||
},
|
},
|
||||||
.mouseMotion = [&, scrollPosMax, sAreaStart, sAreaDim, scrollerSize](const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) {
|
.mouseMotion = [&, scrollPosMax, sAreaStart, sAreaDim, scrollerSize](LayoutElement* t, const InputManager::MouseMotionCallbackArgs& motion) {
|
||||||
if(isScrollbarHoveredY != mouseHovering) {
|
if(isScrollbarHoveredY != t->mouseHovering) {
|
||||||
isScrollbarHoveredY = mouseHovering;
|
isScrollbarHoveredY = t->mouseHovering;
|
||||||
gui.set_to_layout();
|
gui.set_to_layout();
|
||||||
}
|
}
|
||||||
if(isScrollbarHeldY) {
|
if(isScrollbarHeldY) {
|
||||||
|
|
@ -131,7 +129,6 @@ void ScrollArea::layout(const Clay_ElementId& id, const Options& options) {
|
||||||
if(oldScrollOffset != scrollOffset.y())
|
if(oldScrollOffset != scrollOffset.y())
|
||||||
gui.set_to_layout();
|
gui.set_to_layout();
|
||||||
}
|
}
|
||||||
return mouseHovering;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -147,7 +144,7 @@ void ScrollArea::clamp_scroll() {
|
||||||
scrollOffset.y() = std::clamp(scrollOffset.y(), -std::max(0.0f, contentDimensions.y() - containerDimensions.y()), 0.0f);
|
scrollOffset.y() = std::clamp(scrollOffset.y(), -std::max(0.0f, contentDimensions.y() - containerDimensions.y()), 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollArea::input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering) {
|
void ScrollArea::input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel) {
|
||||||
if(mouseHovering) {
|
if(mouseHovering) {
|
||||||
Vector2f oldScrollOffset = scrollOffset;
|
Vector2f oldScrollOffset = scrollOffset;
|
||||||
|
|
||||||
|
|
@ -160,7 +157,6 @@ void ScrollArea::input_mouse_wheel_callback(const InputManager::MouseWheelCallba
|
||||||
if(oldScrollOffset != scrollOffset)
|
if(oldScrollOffset != scrollOffset)
|
||||||
gui.set_to_layout();
|
gui.set_to_layout();
|
||||||
}
|
}
|
||||||
Element::input_mouse_wheel_callback(wheel, mouseHovering);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ class ScrollArea : public Element {
|
||||||
void layout(const Clay_ElementId& id, const Options& options);
|
void layout(const Clay_ElementId& id, const Options& options);
|
||||||
void reset_scroll();
|
void reset_scroll();
|
||||||
|
|
||||||
virtual void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering) override;
|
virtual void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel) override;
|
||||||
private:
|
private:
|
||||||
Options opts;
|
Options opts;
|
||||||
bool isScrollbarHeldY = false;
|
bool isScrollbarHeldY = false;
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ void SelectableButton::layout(const Clay_ElementId& id, const Data& d) {
|
||||||
|
|
||||||
onClick = d.onClick;
|
onClick = d.onClick;
|
||||||
|
|
||||||
if(isHeld || ((d.isSelected || isHovering) && d.drawType == DrawType::TRANSPARENT_BORDER))
|
if(isHeld || ((d.isSelected || mouseHovering) && d.drawType == DrawType::TRANSPARENT_BORDER))
|
||||||
borderColor = io.theme->fillColor1;
|
borderColor = io.theme->fillColor1;
|
||||||
else if(d.drawType == DrawType::TRANSPARENT_BORDER)
|
else if(d.drawType == DrawType::TRANSPARENT_BORDER)
|
||||||
borderColor = io.theme->backColor2;
|
borderColor = io.theme->backColor2;
|
||||||
|
|
@ -25,7 +25,7 @@ void SelectableButton::layout(const Clay_ElementId& id, const Data& d) {
|
||||||
|
|
||||||
if(d.isSelected)
|
if(d.isSelected)
|
||||||
backgroundColorHighlight = color_mul_alpha(io.theme->fillColor1, 0.4f);
|
backgroundColorHighlight = color_mul_alpha(io.theme->fillColor1, 0.4f);
|
||||||
else if(isHovering || isHeld)
|
else if(mouseHovering || isHeld)
|
||||||
backgroundColorHighlight = color_mul_alpha(io.theme->fillColor1, 0.2f);
|
backgroundColorHighlight = color_mul_alpha(io.theme->fillColor1, 0.2f);
|
||||||
else
|
else
|
||||||
backgroundColorHighlight = {0.0f, 0.0f, 0.0f, 0.0f};
|
backgroundColorHighlight = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||||
|
|
@ -58,31 +58,27 @@ void SelectableButton::layout(const Clay_ElementId& id, const Data& d) {
|
||||||
.cornerRadius = CLAY_CORNER_RADIUS(4)
|
.cornerRadius = CLAY_CORNER_RADIUS(4)
|
||||||
}) {
|
}) {
|
||||||
if(d.innerContent)
|
if(d.innerContent)
|
||||||
d.innerContent({.isSelected = d.isSelected, .isHovering = isHovering, .isHeld = isHeld});
|
d.innerContent({.isSelected = d.isSelected, .isHovering = mouseHovering, .isHeld = isHeld});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectableButton::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
void SelectableButton::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||||
bool oldIsHovering = isHovering;
|
|
||||||
bool oldIsHeld = isHeld;
|
bool oldIsHeld = isHeld;
|
||||||
isHovering = mouseHovering;
|
isHeld = mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down;
|
||||||
isHeld = isHovering && button.button == InputManager::MouseButton::LEFT && button.down;
|
|
||||||
if(isHeld) {
|
if(isHeld) {
|
||||||
gui.set_post_callback_func([&]{ if(onClick) onClick(); });
|
gui.set_post_callback_func([&]{ if(onClick) onClick(); });
|
||||||
gui.set_to_layout();
|
gui.set_to_layout();
|
||||||
}
|
}
|
||||||
else if(isHovering != oldIsHovering || isHeld != oldIsHeld)
|
else if(mouseHovering != oldIsHovering || isHeld != oldIsHeld)
|
||||||
gui.set_to_layout();
|
gui.set_to_layout();
|
||||||
Element::input_mouse_button_callback(button, mouseHovering);
|
oldIsHovering = mouseHovering;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectableButton::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) {
|
void SelectableButton::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) {
|
||||||
bool oldIsHovering = isHovering;
|
if(mouseHovering != oldIsHovering)
|
||||||
isHovering = mouseHovering;
|
|
||||||
if(isHovering != oldIsHovering)
|
|
||||||
gui.set_to_layout();
|
gui.set_to_layout();
|
||||||
Element::input_mouse_motion_callback(motion, mouseHovering);
|
oldIsHovering = mouseHovering;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,12 @@ class SelectableButton : public Element {
|
||||||
|
|
||||||
SelectableButton(GUIManager& gui);
|
SelectableButton(GUIManager& gui);
|
||||||
void layout(const Clay_ElementId& id, const Data& d);
|
void layout(const Clay_ElementId& id, const Data& d);
|
||||||
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override;
|
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) override;
|
||||||
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override;
|
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool isHovering = false;
|
|
||||||
bool isHeld = false;
|
bool isHeld = false;
|
||||||
|
bool oldIsHovering = false;
|
||||||
std::function<void()> onClick;
|
std::function<void()> onClick;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ template <typename T> class TextBox : public Element {
|
||||||
|
|
||||||
void layout(const Clay_ElementId& id, const TextBoxData<T>& userInfo);
|
void layout(const Clay_ElementId& id, const TextBoxData<T>& userInfo);
|
||||||
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override;
|
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override;
|
||||||
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override;
|
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) override;
|
||||||
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override;
|
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) override;
|
||||||
virtual void input_key_callback(const InputManager::KeyCallbackArgs& key) override;
|
virtual void input_key_callback(const InputManager::KeyCallbackArgs& key) override;
|
||||||
~TextBox();
|
~TextBox();
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ template <typename T> void TextBox<T>::clay_draw(SkCanvas* canvas, UpdateInputDa
|
||||||
canvas->restore();
|
canvas->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void TextBox<T>::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
template <typename T> void TextBox<T>::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||||
auto& io = gui.io;
|
auto& io = gui.io;
|
||||||
|
|
||||||
if(button.button == InputManager::MouseButton::LEFT && boundingBox.has_value()) {
|
if(button.button == InputManager::MouseButton::LEFT && boundingBox.has_value()) {
|
||||||
|
|
@ -84,13 +84,11 @@ template <typename T> void TextBox<T>::input_mouse_button_callback(const InputMa
|
||||||
textbox->process_mouse_left_button(*cur, button.pos - boundingBox.value().min, 0, false, gui.io.input->key(InputManager::KEY_TEXT_SHIFT).held);
|
textbox->process_mouse_left_button(*cur, button.pos - boundingBox.value().min, 0, false, gui.io.input->key(InputManager::KEY_TEXT_SHIFT).held);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Element::input_mouse_button_callback(button, mouseHovering);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void TextBox<T>::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) {
|
template <typename T> void TextBox<T>::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) {
|
||||||
if(boundingBox.has_value())
|
if(boundingBox.has_value())
|
||||||
textbox->process_mouse_left_button(*cur, motion.pos - boundingBox.value().min, 0, gui.io.input->mouse.leftDown, gui.io.input->key(InputManager::KEY_TEXT_SHIFT).held);
|
textbox->process_mouse_left_button(*cur, motion.pos - boundingBox.value().min, 0, gui.io.input->mouse.leftDown, gui.io.input->key(InputManager::KEY_TEXT_SHIFT).held);
|
||||||
Element::input_mouse_motion_callback(motion, mouseHovering);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> void TextBox<T>::input_key_callback(const InputManager::KeyCallbackArgs& key) {
|
template <typename T> void TextBox<T>::input_key_callback(const InputManager::KeyCallbackArgs& key) {
|
||||||
|
|
|
||||||
|
|
@ -353,31 +353,42 @@ void GUIManager::input_key_callback(const InputManager::KeyCallbackArgs& key) {
|
||||||
|
|
||||||
void GUIManager::input_mouse_button_callback(InputManager::MouseButtonCallbackArgs button) {
|
void GUIManager::input_mouse_button_callback(InputManager::MouseButtonCallbackArgs button) {
|
||||||
button.pos *= io.guiScaleMultiplier;
|
button.pos *= io.guiScaleMultiplier;
|
||||||
mouse_callback(button.pos, [&button] (ElementContainer* e, bool mouseHovering) { e->elem->input_mouse_button_callback(button, mouseHovering); });
|
mouse_callback(button.pos, [&button] (ElementContainer* e) { e->elem->input_mouse_button_callback(button); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIManager::input_mouse_motion_callback(InputManager::MouseMotionCallbackArgs motion) {
|
void GUIManager::input_mouse_motion_callback(InputManager::MouseMotionCallbackArgs motion) {
|
||||||
motion.pos *= io.guiScaleMultiplier;
|
motion.pos *= io.guiScaleMultiplier;
|
||||||
mouse_callback(motion.pos, [&motion] (ElementContainer* e, bool mouseHovering) { e->elem->input_mouse_motion_callback(motion, mouseHovering); });
|
mouse_callback(motion.pos, [&motion] (ElementContainer* e) { e->elem->input_mouse_motion_callback(motion); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIManager::input_mouse_wheel_callback(InputManager::MouseWheelCallbackArgs wheel) {
|
void GUIManager::input_mouse_wheel_callback(InputManager::MouseWheelCallbackArgs wheel) {
|
||||||
wheel.mousePos *= io.guiScaleMultiplier;
|
wheel.mousePos *= io.guiScaleMultiplier;
|
||||||
mouse_callback(wheel.mousePos, [&wheel] (ElementContainer* e, bool mouseHovering) { e->elem->input_mouse_wheel_callback(wheel, mouseHovering); });
|
mouse_callback(wheel.mousePos, [&wheel] (ElementContainer* e) { e->elem->input_mouse_wheel_callback(wheel); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIManager::mouse_callback(const Vector2f& mousePos, const std::function<void(ElementContainer*, bool)>& f) {
|
void GUIManager::mouse_callback(const Vector2f& mousePos, const std::function<void(ElementContainer*)>& f) {
|
||||||
cursorObstructed = false;
|
cursorObstructed = false;
|
||||||
int16_t zIndexObstructed = 0;
|
int16_t zIndexObstructed = 0;
|
||||||
|
|
||||||
|
for(ElementContainer* e : orderedElements)
|
||||||
|
e->elem->childMouseHovering = false;
|
||||||
|
|
||||||
for(ElementContainer* e : orderedElements) {
|
for(ElementContainer* e : orderedElements) {
|
||||||
if((!cursorObstructed || zIndexObstructed == e->elem->zIndex) && e->elem->collides_with_point(mousePos)) {
|
if((!cursorObstructed || zIndexObstructed == e->elem->zIndex) && e->elem->collides_with_point(mousePos)) {
|
||||||
zIndexObstructed = e->elem->zIndex;
|
zIndexObstructed = e->elem->zIndex;
|
||||||
cursorObstructed = true;
|
cursorObstructed = true;
|
||||||
f(e, true);
|
e->elem->mouseHovering = true;
|
||||||
|
Element* nextParent = e->elem->parent;
|
||||||
|
while(nextParent)
|
||||||
|
nextParent->childMouseHovering |= true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
f(e, false);
|
e->elem->mouseHovering = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(ElementContainer* e : orderedElements)
|
||||||
|
f(e);
|
||||||
|
|
||||||
run_post_callback_func();
|
run_post_callback_func();
|
||||||
layout_if_necessary();
|
layout_if_necessary();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,18 +37,23 @@ class GUIManager {
|
||||||
|
|
||||||
template <typename ElementType, typename... Args> ElementType* element(const char* id, const Args&... a) {
|
template <typename ElementType, typename... Args> ElementType* element(const char* id, const Args&... a) {
|
||||||
push_id(id);
|
push_id(id);
|
||||||
|
Element* oldParent = parentElement;
|
||||||
ElementType* elem = insert_element<ElementType>();
|
ElementType* elem = insert_element<ElementType>();
|
||||||
|
elem->parent = parentElement;
|
||||||
Clay_ElementId clayId = strArena.elem_id_from_id_stack(idStack);
|
Clay_ElementId clayId = strArena.elem_id_from_id_stack(idStack);
|
||||||
elem->set_parent_clipping_region(clippingRegion);
|
elem->set_parent_clipping_region(clippingRegion);
|
||||||
elem->layout(clayId, a...);
|
elem->layout(clayId, a...);
|
||||||
elem->set_bounding_box_from_elem_data(Clay_GetElementData(clayId)); // Setting bounding box after layout ensures that the element will have its bounding box set if it's set to be drawn.
|
elem->set_bounding_box_from_elem_data(Clay_GetElementData(clayId)); // Setting bounding box after layout ensures that the element will have its bounding box set if it's set to be drawn.
|
||||||
|
parentElement = oldParent;
|
||||||
pop_id();
|
pop_id();
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ElementType, typename... Args> ElementType* clipping_element(const char* id, const Args&... a) {
|
template <typename ElementType, typename... Args> ElementType* clipping_element(const char* id, const Args&... a) {
|
||||||
push_id(id);
|
push_id(id);
|
||||||
|
Element* oldParent = parentElement;
|
||||||
ElementType* elem = insert_element<ElementType>();
|
ElementType* elem = insert_element<ElementType>();
|
||||||
|
elem->parent = parentElement;
|
||||||
Clay_ElementId clayId = strArena.elem_id_from_id_stack(idStack);
|
Clay_ElementId clayId = strArena.elem_id_from_id_stack(idStack);
|
||||||
elem->set_parent_clipping_region(clippingRegion);
|
elem->set_parent_clipping_region(clippingRegion);
|
||||||
auto oldClippingRegion = clippingRegion;
|
auto oldClippingRegion = clippingRegion;
|
||||||
|
|
@ -61,6 +66,7 @@ class GUIManager {
|
||||||
elem->layout(clayId, a...);
|
elem->layout(clayId, a...);
|
||||||
elem->set_bounding_box_from_elem_data(Clay_GetElementData(clayId));
|
elem->set_bounding_box_from_elem_data(Clay_GetElementData(clayId));
|
||||||
clippingRegion = oldClippingRegion;
|
clippingRegion = oldClippingRegion;
|
||||||
|
parentElement = oldParent;
|
||||||
pop_id();
|
pop_id();
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
|
|
@ -79,7 +85,7 @@ class GUIManager {
|
||||||
void layout_end();
|
void layout_end();
|
||||||
void single_layout_run();
|
void single_layout_run();
|
||||||
|
|
||||||
void mouse_callback(const Vector2f& mousePos, const std::function<void(ElementContainer*, bool)>& f);
|
void mouse_callback(const Vector2f& mousePos, const std::function<void(ElementContainer*)>& f);
|
||||||
|
|
||||||
GUIManagerIDStack idStack;
|
GUIManagerIDStack idStack;
|
||||||
std::vector<ElementContainer*> orderedElements;
|
std::vector<ElementContainer*> orderedElements;
|
||||||
|
|
@ -104,6 +110,7 @@ class GUIManager {
|
||||||
void pop_id();
|
void pop_id();
|
||||||
|
|
||||||
int16_t zIndex = 0;
|
int16_t zIndex = 0;
|
||||||
|
Element* parentElement = nullptr;
|
||||||
std::optional<SCollision::AABB<float>> clippingRegion;
|
std::optional<SCollision::AABB<float>> clippingRegion;
|
||||||
|
|
||||||
std::function<void()> postCallbackFunc;
|
std::function<void()> postCallbackFunc;
|
||||||
|
|
|
||||||
|
|
@ -453,7 +453,7 @@ void Toolbar::top_toolbar() {
|
||||||
auto& gui = main.g.gui;
|
auto& gui = main.g.gui;
|
||||||
auto& io = gui.io;
|
auto& io = gui.io;
|
||||||
|
|
||||||
gui.element<LayoutElement>("top menu bar", [&] (const Clay_ElementId& lId) {
|
gui.element<LayoutElement>("top menu bar", [&] (LayoutElement*, const Clay_ElementId& lId) {
|
||||||
CLAY(lId, {
|
CLAY(lId, {
|
||||||
.layout = {
|
.layout = {
|
||||||
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) },
|
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) },
|
||||||
|
|
@ -471,19 +471,15 @@ void Toolbar::top_toolbar() {
|
||||||
bool layerMenuPopUpJustOpen = false;
|
bool layerMenuPopUpJustOpen = false;
|
||||||
|
|
||||||
auto icon_button_top_toolbar = [&](const char* id, const std::string& svgPath, bool isSelected, const std::function<void()>& onClick) {
|
auto icon_button_top_toolbar = [&](const char* id, const std::string& svgPath, bool isSelected, const std::function<void()>& onClick) {
|
||||||
svg_icon_button(gui, id, svgPath, {
|
return svg_icon_button(gui, id, svgPath, {
|
||||||
.drawType = SelectableButton::DrawType::TRANSPARENT_ALL,
|
.drawType = SelectableButton::DrawType::TRANSPARENT_ALL,
|
||||||
.isSelected = isSelected,
|
.isSelected = isSelected,
|
||||||
.onClick = onClick
|
.onClick = onClick
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
menuPopupOpenFlipped = false;
|
Element* mainMenuButton = icon_button_top_toolbar("Main Menu Button", "data/icons/menu.svg", menuPopUpOpen, [&] {
|
||||||
icon_button_top_toolbar("Main Menu Button", "data/icons/menu.svg", menuPopUpOpen, [&] {
|
menuPopUpOpen = !menuPopUpOpen;
|
||||||
if(!menuPopupOpenFlipped) {
|
|
||||||
menuPopUpOpen = !menuPopUpOpen;
|
|
||||||
menuPopupOpenFlipped = false;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -562,7 +558,7 @@ void Toolbar::top_toolbar() {
|
||||||
}
|
}
|
||||||
if(menuPopUpOpen) {
|
if(menuPopUpOpen) {
|
||||||
gui.set_z_index(5, [&] {
|
gui.set_z_index(5, [&] {
|
||||||
gui.element<LayoutElement>("main menu popup", [&] (const Clay_ElementId& id) {
|
gui.element<LayoutElement>("main menu popup", [&] (LayoutElement*, const Clay_ElementId& id) {
|
||||||
CLAY(id, {
|
CLAY(id, {
|
||||||
.layout = {
|
.layout = {
|
||||||
.sizing = {.width = CLAY_SIZING_FIT(100), .height = CLAY_SIZING_FIT(0) },
|
.sizing = {.width = CLAY_SIZING_FIT(100), .height = CLAY_SIZING_FIT(0) },
|
||||||
|
|
@ -657,10 +653,9 @@ void Toolbar::top_toolbar() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}, LayoutElement::Callbacks {
|
}, LayoutElement::Callbacks {
|
||||||
.mouseButton = [&](const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
.mouseButton = [&, mainMenuButton](LayoutElement* l, const InputManager::MouseButtonCallbackArgs& button) {
|
||||||
if(!mouseHovering && button.down && !menuPopupOpenFlipped) {
|
if(!l->mouseHovering && button.down && !mainMenuButton->mouseHovering) {
|
||||||
menuPopUpOpen = false;
|
menuPopUpOpen = false;
|
||||||
menuPopupOpenFlipped = true;
|
|
||||||
gui.set_to_layout();
|
gui.set_to_layout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1225,7 +1220,7 @@ void Toolbar::color_picker_window(const char* id, Vector4f** color, bool* colorJ
|
||||||
.padding = {.top = 40, .bottom = 40}
|
.padding = {.top = 40, .bottom = 40}
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
main.g.gui.element<LayoutElement>(id, [&](const Clay_ElementId& lId) {
|
main.g.gui.element<LayoutElement>(id, [&](LayoutElement*, const Clay_ElementId& lId) {
|
||||||
CLAY(lId, {
|
CLAY(lId, {
|
||||||
.layout = {
|
.layout = {
|
||||||
.sizing = {.width = CLAY_SIZING_FIT(300), .height = CLAY_SIZING_FIT(0)},
|
.sizing = {.width = CLAY_SIZING_FIT(300), .height = CLAY_SIZING_FIT(0)},
|
||||||
|
|
@ -1237,17 +1232,14 @@ void Toolbar::color_picker_window(const char* id, Vector4f** color, bool* colorJ
|
||||||
.backgroundColor = convert_vec4<Clay_Color>(gui.io.theme->backColor1),
|
.backgroundColor = convert_vec4<Clay_Color>(gui.io.theme->backColor1),
|
||||||
.cornerRadius = CLAY_CORNER_RADIUS(gui.io.theme->windowCorners1)
|
.cornerRadius = CLAY_CORNER_RADIUS(gui.io.theme->windowCorners1)
|
||||||
}) {
|
}) {
|
||||||
//template <typename T> void color_picker_items(GUIManager& gui, const char* id, T* val, const ColorPickerItemsOptions& options = {}) {
|
|
||||||
color_picker_items(gui, "colorpicker", *color, {
|
color_picker_items(gui, "colorpicker", *color, {
|
||||||
.onEdit = onChange
|
.onEdit = onChange
|
||||||
});
|
});
|
||||||
//isUpdatingColorLeft |= color_palette("colorpickerleftpalette", colorLeft, hoveringOnDropdown);
|
color_palette("colorpickerleftpalette", colorLeft, onChange);
|
||||||
//if(!Clay_Hovered() && !justAssignedColorLeft && !hoveringOnDropdown && io.mouse.leftClick)
|
|
||||||
// colorLeft = nullptr;
|
|
||||||
}
|
}
|
||||||
}, LayoutElement::Callbacks{
|
}, LayoutElement::Callbacks{
|
||||||
.mouseButton = [&, colorJustDisabled](const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
.mouseButton = [&, colorJustDisabled](LayoutElement* l, const InputManager::MouseButtonCallbackArgs& button) {
|
||||||
if(!mouseHovering && button.down) {
|
if(!l->mouseHovering && button.down) {
|
||||||
*colorJustDisabled = true;
|
*colorJustDisabled = true;
|
||||||
main.g.gui.set_to_layout();
|
main.g.gui.set_to_layout();
|
||||||
}
|
}
|
||||||
|
|
@ -1256,7 +1248,7 @@ void Toolbar::color_picker_window(const char* id, Vector4f** color, bool* colorJ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Toolbar::color_palette(const char* id, Vector4f* color, bool& hoveringOnDropdown) {
|
bool Toolbar::color_palette(const char* id, Vector4f* color, const std::function<void()>& onChange) {
|
||||||
auto& gui = main.g.gui;
|
auto& gui = main.g.gui;
|
||||||
auto& io = gui.io;
|
auto& io = gui.io;
|
||||||
|
|
||||||
|
|
@ -1528,7 +1520,7 @@ void Toolbar::center_obstructing_window_gui(const char* id, Clay_SizingAxis x, C
|
||||||
auto& io = gui.io;
|
auto& io = gui.io;
|
||||||
|
|
||||||
gui.set_z_index(100, [&] {
|
gui.set_z_index(100, [&] {
|
||||||
gui.element<LayoutElement>(id, [&] (const Clay_ElementId& id) {
|
gui.element<LayoutElement>(id, [&] (LayoutElement*, const Clay_ElementId& id) {
|
||||||
CLAY(id, {
|
CLAY(id, {
|
||||||
.layout = {
|
.layout = {
|
||||||
.sizing = {.width = x, .height = y },
|
.sizing = {.width = x, .height = y },
|
||||||
|
|
@ -2123,7 +2115,7 @@ void Toolbar::file_picker_gui() {
|
||||||
.elementContent = [&] (size_t i) {
|
.elementContent = [&] (size_t i) {
|
||||||
const std::filesystem::path& entry = filePicker.entries[i];
|
const std::filesystem::path& entry = filePicker.entries[i];
|
||||||
bool selectedEntry = filePicker.currentSelectedPath == entry;
|
bool selectedEntry = filePicker.currentSelectedPath == entry;
|
||||||
gui.element<LayoutElement>("elem", [&] (const Clay_ElementId& lId) {
|
gui.element<LayoutElement>("elem", [&] (LayoutElement*, const Clay_ElementId& lId) {
|
||||||
CLAY(lId, {
|
CLAY(lId, {
|
||||||
.layout = {
|
.layout = {
|
||||||
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(entryHeight)},
|
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(entryHeight)},
|
||||||
|
|
@ -2146,8 +2138,8 @@ void Toolbar::file_picker_gui() {
|
||||||
text_label(gui, entry.filename().string());
|
text_label(gui, entry.filename().string());
|
||||||
}
|
}
|
||||||
}, LayoutElement::Callbacks {
|
}, LayoutElement::Callbacks {
|
||||||
.mouseButton = [&, selectedEntry, entry](const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) {
|
.mouseButton = [&, selectedEntry, entry](LayoutElement* l, const InputManager::MouseButtonCallbackArgs& button) {
|
||||||
if(mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down) {
|
if(l->mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down) {
|
||||||
gui.set_post_callback_func([&, button, selectedEntry, entry] {
|
gui.set_post_callback_func([&, button, selectedEntry, entry] {
|
||||||
if(selectedEntry && button.clicks >= 2) {
|
if(selectedEntry && button.clicks >= 2) {
|
||||||
if(std::filesystem::is_directory(entry)) {
|
if(std::filesystem::is_directory(entry)) {
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ class Toolbar {
|
||||||
bool colorLeftJustDisabled = false;
|
bool colorLeftJustDisabled = false;
|
||||||
Vector4f* colorLeftJustEnabled = nullptr;
|
Vector4f* colorLeftJustEnabled = nullptr;
|
||||||
std::function<void()> onColorLeftChange;
|
std::function<void()> onColorLeftChange;
|
||||||
|
|
||||||
Vector4f* colorRight = nullptr;
|
Vector4f* colorRight = nullptr;
|
||||||
bool colorRightJustDisabled = false;
|
bool colorRightJustDisabled = false;
|
||||||
Vector4f* colorRightJustEnabled = nullptr;
|
Vector4f* colorRightJustEnabled = nullptr;
|
||||||
|
|
@ -89,7 +90,7 @@ class Toolbar {
|
||||||
void file_picker_gui();
|
void file_picker_gui();
|
||||||
void performance_metrics();
|
void performance_metrics();
|
||||||
void color_picker_window(const char* id, Vector4f** color, bool* colorJustDisabled, const std::function<void()>& onChange);
|
void color_picker_window(const char* id, Vector4f** color, bool* colorJustDisabled, const std::function<void()>& onChange);
|
||||||
bool color_palette(const char* id, Vector4f* color, bool& hoveringOnDropdown);
|
bool color_palette(const char* id, Vector4f* color, const std::function<void()>& onChange);
|
||||||
void open_world_file(bool isClient, const std::string& netSource, const std::string& serverLocalID);
|
void open_world_file(bool isClient, const std::string& netSource, const std::string& serverLocalID);
|
||||||
void load_default_palette();
|
void load_default_palette();
|
||||||
void load_default_theme();
|
void load_default_theme();
|
||||||
|
|
@ -151,7 +152,6 @@ class Toolbar {
|
||||||
bool showPerformance = false;
|
bool showPerformance = false;
|
||||||
|
|
||||||
bool menuPopUpOpen = false;
|
bool menuPopUpOpen = false;
|
||||||
bool menuPopupOpenFlipped = false;
|
|
||||||
bool optionsMenuOpen = false;
|
bool optionsMenuOpen = false;
|
||||||
bool playerMenuOpen = false;
|
bool playerMenuOpen = false;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue