infinipaint/src/GUIStuff/Elements/MovableTabList.cpp

81 lines
4.2 KiB
C++
Raw Normal View History

2025-07-06 20:43:53 +03:00
#include "MovableTabList.hpp"
#include "Helpers/ConvertVec.hpp"
2025-11-01 20:47:34 +03:00
#include "../GUIManager.hpp"
2025-07-06 20:43:53 +03:00
#include <iostream>
namespace GUIStuff {
void MovableTabList::update(UpdateInputData& io, const std::vector<std::pair<std::string, std::string>>& tabNames, size_t& selectedTab, std::optional<size_t>& closedTab, const std::function<void()>& elemUpdate) {
size_t currentSelectedTab = selectedTab;
if(tabNames != oldTabNames) {
buttons = std::vector<SelectableButton>(tabNames.size());
closeButtons = std::vector<SelectableButton>(tabNames.size());
closeIcons = std::vector<SVGIcon>(tabNames.size());
tabIcons = std::vector<SVGIcon>(tabNames.size());
oldTabNames = tabNames;
}
CLAY({.layout = {
2025-11-01 20:47:34 +03:00
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(GUIStuff::GUIManager::BIG_BUTTON_SIZE)},
.padding = CLAY_PADDING_ALL(0),
.childGap = 4,
2025-07-06 20:43:53 +03:00
.childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER },
.layoutDirection = CLAY_LEFT_TO_RIGHT
},
.clip = {.horizontal = true, .childOffset = Clay_GetScrollOffset()}
}) {
selection.update(Clay_Hovered(), io.mouse.leftClick, io.mouse.leftHeld);
if(elemUpdate)
elemUpdate();
for(size_t i = 0; i < buttons.size(); i++) {
CLAY({.layout = {
2025-11-01 20:47:34 +03:00
.sizing = {.width = CLAY_SIZING_FIT(200), .height = CLAY_SIZING_GROW(0)},
2025-07-06 20:43:53 +03:00
}
}) {
buttons[i].update(io, SelectableButton::DrawType::FILLED, [&](SelectionHelper& s, bool iS) {
2025-07-06 20:43:53 +03:00
CLAY({.layout = {
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
.padding = CLAY_PADDING_ALL(0),
2025-11-01 18:07:39 +03:00
.childGap = 4,
2025-07-06 20:43:53 +03:00
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER },
.layoutDirection = CLAY_LEFT_TO_RIGHT
}
}) {
if(!tabNames[i].first.empty()) {
CLAY({.layout = {
2025-11-01 20:47:34 +03:00
.sizing = {.width = CLAY_SIZING_FIXED(GUIStuff::GUIManager::SMALL_BUTTON_SIZE), .height = CLAY_SIZING_FIXED(GUIStuff::GUIManager::SMALL_BUTTON_SIZE)},
2025-07-06 20:43:53 +03:00
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER },
.layoutDirection = CLAY_LEFT_TO_RIGHT
}
}) {
tabIcons[i].update(io, tabNames[i].first, iS, nullptr);
}
}
CLAY_TEXT(io.strArena->std_str_to_clay_str(tabNames[i].second), CLAY_TEXT_CONFIG({.textColor = convert_vec4<Clay_Color>(io.theme->frontColor1), .fontSize = io.fontSize }));
if(s.clicked)
selectedTab = i;
CLAY({.layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}}) {}
CLAY({.layout = {
2025-11-01 20:47:34 +03:00
.sizing = {.width = CLAY_SIZING_FIXED(GUIStuff::GUIManager::SMALL_BUTTON_SIZE), .height = CLAY_SIZING_FIXED(GUIStuff::GUIManager::SMALL_BUTTON_SIZE)},
2025-07-06 20:43:53 +03:00
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER },
.layoutDirection = CLAY_LEFT_TO_RIGHT
}
}) {
closeButtons[i].update(io, SelectableButton::DrawType::TRANSPARENT, [&](SelectionHelper& s, bool iS) {
2025-07-06 20:43:53 +03:00
if(s.clicked)
closedTab = i;
closeIcons[i].update(io, "data/icons/close.svg", s.held || s.hovered, nullptr);
}, false);
}
}
}, currentSelectedTab == i);
}
}
}
}
void MovableTabList::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command) {
}
}