Added grid scroll area (has issues with many elements)
This commit is contained in:
parent
db6dffb4ee
commit
886fd313a4
5 changed files with 103 additions and 3 deletions
|
|
@ -125,6 +125,7 @@ set(sources "src/main.cpp"
|
|||
"src/GUIStuff/Elements/ScrollArea.cpp"
|
||||
"src/GUIStuff/Elements/PositionAdjustingPopupMenu.cpp"
|
||||
"src/GUIStuff/Elements/ColorPickerShaders.cpp"
|
||||
"src/GUIStuff/Elements/GridScrollArea.cpp"
|
||||
"src/GUIStuff/ElementHelpers/PopupHelpers.cpp"
|
||||
"src/GUIStuff/ElementHelpers/ButtonHelpers.cpp"
|
||||
"src/GUIStuff/ElementHelpers/LayoutHelpers.cpp"
|
||||
|
|
|
|||
46
src/GUIStuff/Elements/GridScrollArea.cpp
Normal file
46
src/GUIStuff/Elements/GridScrollArea.cpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include "GridScrollArea.hpp"
|
||||
#include "../ElementHelpers/ScrollAreaHelpers.hpp"
|
||||
#include "Helpers/ConvertVec.hpp"
|
||||
#include "../GUIManager.hpp"
|
||||
|
||||
namespace GUIStuff {
|
||||
|
||||
GridScrollArea::GridScrollArea(GUIManager& gui): Element(gui) {}
|
||||
|
||||
void GridScrollArea::layout(const Clay_ElementId& id, const Options& options) {
|
||||
using namespace ElementHelpers;
|
||||
|
||||
ScrollBarManyEntriesOptions opts;
|
||||
opts.clipHorizontal = true;
|
||||
opts.entryHeight = options.entryHeight;
|
||||
opts.innerContentExtraCallback = [&, extraCallback = options.innerContentExtraCallback] (const ScrollArea::InnerContentParameters& contParams) {
|
||||
rowWidth = std::fabs(contParams.containerDimensions.x());
|
||||
if(extraCallback) extraCallback(contParams);
|
||||
};
|
||||
size_t entriesPerRow = static_cast<size_t>(rowWidth / options.entryMaximumWidth) + 1;
|
||||
size_t rowCount = options.entryCount / entriesPerRow;
|
||||
float entryWidth = rowWidth == 0.0f ? 100.0f : (rowWidth / entriesPerRow);
|
||||
opts.entryCount = rowCount;
|
||||
opts.elementContent = [&] (size_t rowIndex) {
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(options.entryHeight)},
|
||||
.childAlignment = { .x = options.childAlignmentX}
|
||||
}
|
||||
}) {
|
||||
for(size_t i = 0; i < entriesPerRow; i++) {
|
||||
size_t entryNum = rowIndex * entriesPerRow + i;
|
||||
gui.new_id(static_cast<int64_t>(i), [&] {
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {.sizing = {.width = CLAY_SIZING_FIXED(entryWidth), .height = CLAY_SIZING_FIXED(options.entryHeight)}}
|
||||
}) {
|
||||
options.elementContent(entryNum);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
scroll_area_many_entries(gui, "scroll many area", opts);
|
||||
}
|
||||
|
||||
}
|
||||
26
src/GUIStuff/Elements/GridScrollArea.hpp
Normal file
26
src/GUIStuff/Elements/GridScrollArea.hpp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
#include "Element.hpp"
|
||||
#include "Helpers/ConvertVec.hpp"
|
||||
#include "ScrollArea.hpp"
|
||||
|
||||
namespace GUIStuff {
|
||||
|
||||
class GridScrollArea : public Element {
|
||||
public:
|
||||
GridScrollArea(GUIManager& gui);
|
||||
|
||||
struct Options {
|
||||
float entryMaximumWidth;
|
||||
Clay_LayoutAlignmentX childAlignmentX = CLAY_ALIGN_X_LEFT;
|
||||
float entryHeight;
|
||||
size_t entryCount;
|
||||
std::function<void(size_t elementIndex)> elementContent;
|
||||
std::function<void(const ScrollArea::InnerContentParameters&)> innerContentExtraCallback;
|
||||
};
|
||||
|
||||
void layout(const Clay_ElementId& id, const Options& options);
|
||||
private:
|
||||
float rowWidth = 0.0f;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ MainProgram::MainProgram():
|
|||
fonts(std::make_shared<FontData>()),
|
||||
g(*this)
|
||||
{
|
||||
screen = std::make_unique<DrawingProgramScreen>(*this);
|
||||
screen = std::make_unique<FileSelectScreen>(*this);
|
||||
Logger::get().add_log("WORLDFATAL", [&](const std::string& text) {
|
||||
*logFile << "[WORLDFATAL] " << text << std::endl;
|
||||
std::cout << "[WORLDFATAL] " << text << std::endl;
|
||||
|
|
|
|||
|
|
@ -2,16 +2,43 @@
|
|||
#include "../MainProgram.hpp"
|
||||
#include "../GUIHolder.hpp"
|
||||
#include "../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
|
||||
#include "Helpers/ConvertVec.hpp"
|
||||
#include "../GUIStuff/Elements/GridScrollArea.hpp"
|
||||
#include "../GUIStuff/ElementHelpers/ButtonHelpers.hpp"
|
||||
|
||||
FileSelectScreen::FileSelectScreen(MainProgram& m): Screen(m) {}
|
||||
|
||||
void FileSelectScreen::gui_layout_run() {
|
||||
using namespace GUIStuff;
|
||||
using namespace ElementHelpers;
|
||||
auto& gui = main.g.gui;
|
||||
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {}
|
||||
.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_FIXED(gui.io.windowSize.x()), .height = CLAY_SIZING_FIXED(gui.io.windowSize.y())},
|
||||
.childGap = 15,
|
||||
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP },
|
||||
.layoutDirection = CLAY_TOP_TO_BOTTOM,
|
||||
},
|
||||
}) {
|
||||
text_label(main.g.gui, "File select screen");
|
||||
text_label(gui, "Test grid");
|
||||
gui.element<GridScrollArea>("Test grid", GridScrollArea::Options{
|
||||
.entryMaximumWidth = 100.0f,
|
||||
.childAlignmentX = CLAY_ALIGN_X_LEFT,
|
||||
.entryHeight = 100.0f,
|
||||
.entryCount = 700,
|
||||
.elementContent = [&](size_t i) {
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
.sizing = { .width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
|
||||
.padding = CLAY_PADDING_ALL(2),
|
||||
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER },
|
||||
}
|
||||
}) {
|
||||
text_button_sized(gui, "button", "Square " + std::to_string(i), CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue