More improvements to GUI

This commit is contained in:
Yousef Khadadeh 2025-11-01 20:47:34 +03:00
parent 30f7856815
commit 86e0999a5c
11 changed files with 72 additions and 91 deletions

View file

@ -23,7 +23,7 @@ namespace GUIStuff {
std::shared_ptr<Theme> get_default_dark_mode() {
std::shared_ptr<Theme> theme(std::make_shared<Theme>());
theme->fillColor1 = {0.65f, 0.64f, 1.0f, 1.0f};
theme->fillColor2 = {0.31f, 0.31f, 0.48f, 1.0f};
theme->fillColor2 = {0.6f, 0.6f, 0.785f, 1.0f};
theme->backColor1 = {0.156f, 0.156f, 0.18f, 1.0f};
theme->backColor2 = {0.24f, 0.24f, 0.29f, 1.0f};
theme->frontColor1 = {0.87f, 0.87f, 0.87f, 1.0f};

View file

@ -62,9 +62,8 @@ struct Theme {
uint16_t childGap1 = 10;
uint16_t padding1 = 8;
float windowCorners1 = 8;
uint16_t windowBorders1 = 0;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Theme, fillColor1, fillColor2, backColor1, backColor2, frontColor1, frontColor2, hoverExpandTime, childGap1, padding1, windowCorners1, windowBorders1)
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Theme, fillColor1, fillColor2, backColor1, backColor2, frontColor1, frontColor2, errorColor, warningColor, hoverExpandTime, childGap1, padding1, windowCorners1)
};
std::shared_ptr<Theme> get_default_dark_mode();

View file

@ -1,5 +1,6 @@
#include "MovableTabList.hpp"
#include "Helpers/ConvertVec.hpp"
#include "../GUIManager.hpp"
#include <iostream>
namespace GUIStuff {
@ -15,7 +16,7 @@ void MovableTabList::update(UpdateInputData& io, const std::vector<std::pair<std
}
CLAY({.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(35)},
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(GUIStuff::GUIManager::BIG_BUTTON_SIZE)},
.padding = CLAY_PADDING_ALL(0),
.childGap = 4,
.childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER },
@ -28,7 +29,7 @@ void MovableTabList::update(UpdateInputData& io, const std::vector<std::pair<std
elemUpdate();
for(size_t i = 0; i < buttons.size(); i++) {
CLAY({.layout = {
.sizing = {.width = CLAY_SIZING_FIT(250), .height = CLAY_SIZING_GROW(0)},
.sizing = {.width = CLAY_SIZING_FIT(200), .height = CLAY_SIZING_GROW(0)},
}
}) {
buttons[i].update(io, SelectableButton::DrawType::FILLED, [&](SelectionHelper& s, bool iS) {
@ -42,7 +43,7 @@ void MovableTabList::update(UpdateInputData& io, const std::vector<std::pair<std
}) {
if(!tabNames[i].first.empty()) {
CLAY({.layout = {
.sizing = {.width = CLAY_SIZING_FIXED(25), .height = CLAY_SIZING_FIXED(25)},
.sizing = {.width = CLAY_SIZING_FIXED(GUIStuff::GUIManager::SMALL_BUTTON_SIZE), .height = CLAY_SIZING_FIXED(GUIStuff::GUIManager::SMALL_BUTTON_SIZE)},
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER },
.layoutDirection = CLAY_LEFT_TO_RIGHT
}
@ -55,7 +56,7 @@ void MovableTabList::update(UpdateInputData& io, const std::vector<std::pair<std
selectedTab = i;
CLAY({.layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}}) {}
CLAY({.layout = {
.sizing = {.width = CLAY_SIZING_FIXED(25), .height = CLAY_SIZING_FIXED(25)},
.sizing = {.width = CLAY_SIZING_FIXED(GUIStuff::GUIManager::SMALL_BUTTON_SIZE), .height = CLAY_SIZING_FIXED(GUIStuff::GUIManager::SMALL_BUTTON_SIZE)},
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER },
.layoutDirection = CLAY_LEFT_TO_RIGHT
}

View file

@ -99,9 +99,9 @@ void PaintCircleMenu::draw_rotate_bar(SkCanvas* canvas, UpdateInputData& io) {
if(rotateBarSelect.held)
rotateBarHolderFill.setColor4f(io.theme->fillColor1);
else if(rotateBarSelect.hovered)
rotateBarHolderFill.setColor4f(io.theme->fillColor1);
rotateBarHolderFill.setColor4f(io.theme->fillColor2);
else
rotateBarHolderFill.setColor4f(io.theme->frontColor2);
rotateBarHolderFill.setColor4f(io.theme->frontColor1);
float rotateBarHolderRadius = (CIRCLE_END - ROTATE_START) / 2.0f;
Vector2f rotateBarHolderPos{std::cos(rotationAngle) * rotateBarMiddleRadius, -std::sin(rotationAngle) * rotateBarMiddleRadius};
canvas->drawCircle(rotateBarHolderPos.x(), rotateBarHolderPos.y(), rotateBarHolderRadius, rotateBarHolderFill);

View file

@ -3,7 +3,7 @@
namespace GUIStuff {
constexpr float WHEEL_WIDTH = 15.0f;
constexpr float WHEEL_WIDTH = 10.0f;
constexpr double ROTATE_BAR_SNAP_DISTANCE = 0.3;
constexpr double ROTATE_BAR_SNAP_DISTRIBUTION = std::numbers::pi * 0.25;
@ -75,7 +75,7 @@ void RotateWheel::draw_rotate_wheel(SkCanvas* canvas, UpdateInputData& io) {
for(double snapPos = 0.0; snapPos < std::numbers::pi * 2.0; snapPos += ROTATE_BAR_SNAP_DISTRIBUTION) {
Vector2f lineDir{std::cos(snapPos), -std::sin(snapPos)};
SkPaint p(snapPos == 0.0 ? io.theme->fillColor1 : io.theme->frontColor2);
p.setStrokeWidth(2.0f);
p.setStrokeWidth(1.0f);
canvas->drawLine(lineDir.x() * wheelStart, lineDir.y() * wheelStart, lineDir.x() * wheelEnd, lineDir.y() * wheelEnd, p);
}
}
@ -84,7 +84,7 @@ void RotateWheel::draw_rotate_wheel(SkCanvas* canvas, UpdateInputData& io) {
if(selection.held)
rotateBarHolderFill.setColor4f(io.theme->fillColor1);
else if(selection.hovered)
rotateBarHolderFill.setColor4f(io.theme->fillColor1);
rotateBarHolderFill.setColor4f(io.theme->fillColor2);
else
rotateBarHolderFill.setColor4f(io.theme->frontColor2);
float rotateBarHolderRadius = (wheelEnd - wheelStart) / 2.0f;
@ -97,7 +97,7 @@ void RotateWheel::draw_rotate_wheel(SkCanvas* canvas, UpdateInputData& io) {
SkPaint rotateBarOutline(io.theme->frontColor2);
rotateBarOutline.setStroke(true);
rotateBarOutline.setStrokeWidth(2.0f);
rotateBarOutline.setStrokeWidth(1.0f);
canvas->drawCircle(0.0f, 0.0f, wheelStart, rotateBarOutline);
canvas->drawCircle(0.0f, 0.0f, wheelEnd, rotateBarOutline);
}

View file

@ -210,7 +210,7 @@ void GUIManager::draw(SkCanvas* canvas) {
}
case CLAY_RENDER_COMMAND_TYPE_SCISSOR_START: {
canvas->save();
SkRect clipRect = SkRect::MakeXYWH(bb.x, bb.y, bb.width, bb.height);
SkRect clipRect = SkRect::MakeXYWH(bb.x - 1.0f, bb.y - 1.0f, bb.width + 1.0f, bb.height + 1.0f);
canvas->clipRect(clipRect);
break;
}
@ -241,7 +241,7 @@ void GUIManager::top_to_bottom_window_popup_layout(Clay_SizingAxis x, Clay_Sizin
.backgroundColor = convert_vec4<Clay_Color>(io->theme->backColor1),
.cornerRadius = CLAY_CORNER_RADIUS(10),
.floating = { .attachTo = CLAY_ATTACH_TO_PARENT },
.border = {.color = convert_vec4<Clay_Color>(io->theme->backColor2), .width = CLAY_BORDER_OUTSIDE(2)}
.border = {.color = convert_vec4<Clay_Color>(io->theme->fillColor2), .width = CLAY_BORDER_OUTSIDE(1)}
}) {
if(Clay_Hovered())
io->hoverObstructed = true;
@ -556,10 +556,8 @@ void GUIManager::dropdown_select(const std::string& id, size_t* val, const std::
CLAY({
.layout = {
.sizing = {.width = CLAY_SIZING_FIXED(width), .height = CLAY_SIZING_FIT(0)},
.padding = {.left = 2, .right = 2},
.childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP},
.layoutDirection = CLAY_TOP_TO_BOTTOM
},
.backgroundColor = convert_vec4<Clay_Color>(io->theme->backColor1),
.cornerRadius = CLAY_CORNER_RADIUS(4),
.floating = {
.offset = {
@ -572,35 +570,44 @@ void GUIManager::dropdown_select(const std::string& id, size_t* val, const std::
.attachTo = CLAY_ATTACH_TO_PARENT
},
.border = {
.color = convert_vec4<Clay_Color>(io->theme->backColor2),
.width = CLAY_BORDER_OUTSIDE(4)
.color = convert_vec4<Clay_Color>(io->theme->fillColor2),
.width = CLAY_BORDER_OUTSIDE(1)
}
}) {
obstructing_window();
for(size_t i = 0; i < selections.size(); i++) {
bool selectedEntry = *val == i;
CLAY({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0)},
},
}) {
SkColor4f entryColor;
if(selectedEntry)
entryColor = io->theme->backColor2;
else if(Clay_Hovered())
entryColor = io->theme->backColor2;
else
entryColor = io->theme->backColor1;
CLAY({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0)},
.childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP},
.layoutDirection = CLAY_TOP_TO_BOTTOM
}
}) {
for(size_t i = 0; i < selections.size(); i++) {
bool selectedEntry = *val == i;
CLAY({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0)},
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0)}
},
.backgroundColor = convert_vec4<Clay_Color>(entryColor)
}) {
text_label(selections[i]);
if(io->mouse.leftClick && Clay_Hovered()) {
*val = i;
dropDownOpen = false;
SkColor4f entryColor;
if(selectedEntry)
entryColor = io->theme->backColor2;
else if(Clay_Hovered())
entryColor = io->theme->backColor2;
else
entryColor = io->theme->backColor1;
CLAY({
.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0)},
.padding = {.left = 2, .right = 2},
},
.backgroundColor = convert_vec4<Clay_Color>(entryColor)
}) {
text_label(selections[i]);
if(io->mouse.leftClick && Clay_Hovered()) {
*val = i;
dropDownOpen = false;
}
}
}
}
@ -677,7 +684,7 @@ void GUIManager::scroll_bar_area(const std::string& uniqueId, const std::functio
if(sD.isMoving)
scrollerColor = io->theme->fillColor1;
else if(Clay_Hovered())
scrollerColor = io->theme->fillColor1;
scrollerColor = io->theme->fillColor2;
else
scrollerColor = io->theme->backColor2;

View file

@ -25,6 +25,7 @@ namespace GUIStuff {
class GUIManager {
public:
constexpr static float BIG_BUTTON_SIZE = 30;
constexpr static float SMALL_BUTTON_SIZE = 20;
struct ElementContainer {
std::unique_ptr<Element> elem;