Fixed many element scroll area and added color palette picker
This commit is contained in:
parent
c90c09b169
commit
c1cd3e4e49
14 changed files with 156 additions and 124 deletions
|
|
@ -1,72 +0,0 @@
|
|||
#include "ScrollAreaHelpers.hpp"
|
||||
#include "../GUIManager.hpp"
|
||||
#include "Helpers/ConvertVec.hpp"
|
||||
|
||||
namespace GUIStuff { namespace ElementHelpers {
|
||||
|
||||
ScrollArea* scroll_area_many_entries(GUIManager& gui, const char* id, const ScrollBarManyEntriesOptions& options) {
|
||||
return gui.clipping_element<ScrollArea>(id, ScrollArea::Options{
|
||||
.scrollVertical = true,
|
||||
.clipHorizontal = options.clipHorizontal,
|
||||
.clipVertical = true,
|
||||
.scrollbarY = options.scrollbar,
|
||||
.xAlign = options.xAlign,
|
||||
.yAlign = CLAY_ALIGN_Y_TOP,
|
||||
.innerContent = [&](const ScrollArea::InnerContentParameters& params) {
|
||||
if(options.innerContentExtraCallback) options.innerContentExtraCallback(params);
|
||||
|
||||
if(params.containerDimensions.y() == 0.0f) {
|
||||
if(options.growing) {
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(1)},
|
||||
}
|
||||
}) { }
|
||||
}
|
||||
else {
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
|
||||
}
|
||||
}) { }
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
float absScrollAmount = std::fabs(params.scrollOffset->y());
|
||||
size_t startPoint = absScrollAmount / options.entryHeight;
|
||||
size_t elementsContainable = (params.containerDimensions.y() / options.entryHeight) + 2; // Displaying 2 more elements ensures that there isn't any empty space in the container
|
||||
size_t endPoint = std::min(options.entryCount, startPoint + elementsContainable);
|
||||
|
||||
if(startPoint != 0) {
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(startPoint * options.entryHeight)},
|
||||
}
|
||||
}) { }
|
||||
}
|
||||
|
||||
gui.new_id("many element list", [&] {
|
||||
for(size_t i = startPoint; i < endPoint; i++) {
|
||||
gui.new_id(i - startPoint, [&] {
|
||||
CLAY_AUTO_ID({
|
||||
.layout = { .sizing = {.width = options.xElementSize, .height = CLAY_SIZING_FIXED(options.entryHeight)}}
|
||||
}) {
|
||||
options.elementContent(i);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if(endPoint != options.entryCount) {
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED((options.entryCount - endPoint) * options.entryHeight)},
|
||||
}
|
||||
}) { }
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
#pragma once
|
||||
#include "../Elements/ScrollArea.hpp"
|
||||
#include "Helpers/ConvertVec.hpp"
|
||||
|
||||
namespace GUIStuff { namespace ElementHelpers {
|
||||
|
||||
struct ScrollBarManyEntriesOptions {
|
||||
float entryHeight;
|
||||
size_t entryCount;
|
||||
bool clipHorizontal = false;
|
||||
bool growing = false; // If set to false, this element has a fixed size. Otherwise, is a growing element.
|
||||
Clay_LayoutAlignmentX xAlign = CLAY_ALIGN_X_LEFT;
|
||||
Clay_SizingAxis xElementSize = CLAY_SIZING_GROW(0);
|
||||
ScrollArea::ScrollbarType scrollbar = ScrollArea::ScrollbarType::NORMAL;
|
||||
std::function<void(size_t elementIndex)> elementContent;
|
||||
std::function<void(const ScrollArea::InnerContentParameters&)> innerContentExtraCallback;
|
||||
};
|
||||
|
||||
ScrollArea* scroll_area_many_entries(GUIManager& gui, const char* id, const ScrollBarManyEntriesOptions& options);
|
||||
|
||||
}}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
#include "Element.hpp"
|
||||
#include "ManyElementScrollArea.hpp"
|
||||
#include "SelectableButton.hpp"
|
||||
#include "../ElementHelpers/ScrollAreaHelpers.hpp"
|
||||
#include "../ElementHelpers/LayoutHelpers.hpp"
|
||||
#include "../ElementHelpers/TextLabelHelpers.hpp"
|
||||
#include "../ElementHelpers/ButtonHelpers.hpp"
|
||||
|
|
@ -81,11 +81,10 @@ template <typename T> class DropDown : public Element {
|
|||
.width = CLAY_BORDER_OUTSIDE(1)
|
||||
}
|
||||
}) {
|
||||
ElementHelpers::scroll_area_many_entries(gui, "dropdown scroll area", {
|
||||
gui.element<ManyElementScrollArea>("dropdown scroll area", ManyElementScrollArea::Options{
|
||||
.entryHeight = 18.0f,
|
||||
.entryCount = selections.size(),
|
||||
.clipHorizontal = true,
|
||||
.growing = true,
|
||||
.elementContent = [&](size_t i) {
|
||||
bool selectedEntry = static_cast<size_t>(*data) == i;
|
||||
gui.element<LayoutElement>("elem", [&] (LayoutElement*, const Clay_ElementId& lId) {
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
#include "../GUIManager.hpp"
|
||||
|
||||
#include "../ElementHelpers/ButtonHelpers.hpp"
|
||||
#include "../ElementHelpers/ScrollAreaHelpers.hpp"
|
||||
#include "../ElementHelpers/TextBoxHelpers.hpp"
|
||||
#include "TextParagraph.hpp"
|
||||
#include "ManyElementScrollArea.hpp"
|
||||
|
||||
std::vector<std::string> sortedFontList;
|
||||
std::vector<std::string> sortedFontListLowercase;
|
||||
|
|
@ -120,11 +120,10 @@ void FontPicker::layout(const Clay_ElementId& id, std::string* newFontName, cons
|
|||
.width = CLAY_BORDER_OUTSIDE(1)
|
||||
}
|
||||
}) {
|
||||
ElementHelpers::scroll_area_many_entries(gui, "dropdown scroll area", {
|
||||
gui.element<ManyElementScrollArea>("dropdown scroll area", ManyElementScrollArea::Options{
|
||||
.entryHeight = ENTRY_HEIGHT,
|
||||
.entryCount = sortedFontList.size(),
|
||||
.clipHorizontal = true,
|
||||
.growing = true,
|
||||
.elementContent = [&](size_t i) {
|
||||
bool selectedEntry = val == i;
|
||||
gui.element<LayoutElement>("elem", [&] (LayoutElement*, const Clay_ElementId& lId) {
|
||||
|
|
|
|||
|
|
@ -1,21 +1,19 @@
|
|||
#include "GridScrollArea.hpp"
|
||||
#include "../ElementHelpers/ScrollAreaHelpers.hpp"
|
||||
#include "Helpers/ConvertVec.hpp"
|
||||
#include "../GUIManager.hpp"
|
||||
#include "ManyElementScrollArea.hpp"
|
||||
|
||||
namespace GUIStuff {
|
||||
|
||||
GridScrollArea::GridScrollArea(GUIManager& gui): Element(gui) {}
|
||||
|
||||
void GridScrollArea::layout(const Clay_ElementId& id, const Options& o) {
|
||||
using namespace ElementHelpers;
|
||||
|
||||
options = o;
|
||||
|
||||
if(boundingBox.has_value())
|
||||
rowWidth = boundingBox.value().width(); // Use grid element bounding box instead of inner content width because row width will decide whether a scroll bar appears or not, which will change the inner content width (circular dependency)
|
||||
|
||||
ScrollBarManyEntriesOptions opts;
|
||||
ManyElementScrollArea::Options opts;
|
||||
opts.clipHorizontal = true;
|
||||
opts.entryHeight = options.entryHeight;
|
||||
opts.innerContentExtraCallback = [&, extraCallback = options.innerContentExtraCallback] (const ScrollArea::InnerContentParameters& contParams) {
|
||||
|
|
@ -72,7 +70,7 @@ void GridScrollArea::layout(const Clay_ElementId& id, const Options& o) {
|
|||
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}
|
||||
}
|
||||
}) {
|
||||
scrollArea = scroll_area_many_entries(gui, "scroll many area", opts);
|
||||
gui.element<ManyElementScrollArea>("scroll many area", opts);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
62
src/GUIStuff/Elements/ManyElementScrollArea.cpp
Normal file
62
src/GUIStuff/Elements/ManyElementScrollArea.cpp
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#include "ManyElementScrollArea.hpp"
|
||||
#include "../GUIManager.hpp"
|
||||
|
||||
namespace GUIStuff {
|
||||
|
||||
ManyElementScrollArea::ManyElementScrollArea(GUIManager& gui): Element(gui) {}
|
||||
|
||||
void ManyElementScrollArea::layout(const Clay_ElementId& id, const Options& opts) {
|
||||
options = opts;
|
||||
CLAY(id, {
|
||||
.layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}
|
||||
}) {
|
||||
if(boundingBox.has_value()) {
|
||||
scrollArea = gui.clipping_element<ScrollArea>("scroll area", ScrollArea::Options{
|
||||
.scrollVertical = true,
|
||||
.clipHorizontal = options.clipHorizontal,
|
||||
.clipVertical = true,
|
||||
.scrollbarY = options.scrollbar,
|
||||
.xAlign = options.xAlign,
|
||||
.yAlign = CLAY_ALIGN_Y_TOP,
|
||||
.innerContent = [&](const ScrollArea::InnerContentParameters& params) {
|
||||
if(options.innerContentExtraCallback) options.innerContentExtraCallback(params);
|
||||
|
||||
float absScrollAmount = std::fabs(params.scrollOffset->y());
|
||||
size_t startPoint = absScrollAmount / options.entryHeight;
|
||||
size_t elementsContainable = (boundingBox.value().height() / options.entryHeight) + 2; // Displaying 2 more elements ensures that there isn't any empty space in the container
|
||||
size_t endPoint = std::min(options.entryCount, startPoint + elementsContainable);
|
||||
|
||||
if(startPoint != 0) {
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(startPoint * options.entryHeight)},
|
||||
}
|
||||
}) { }
|
||||
}
|
||||
|
||||
gui.new_id("many element list", [&] {
|
||||
for(size_t i = startPoint; i < endPoint; i++) {
|
||||
gui.new_id(i - startPoint, [&] {
|
||||
CLAY_AUTO_ID({
|
||||
.layout = { .sizing = {.width = options.xElementSize, .height = CLAY_SIZING_FIXED(options.entryHeight)}}
|
||||
}) {
|
||||
options.elementContent(i);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if(endPoint != options.entryCount) {
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED((options.entryCount - endPoint) * options.entryHeight)},
|
||||
}
|
||||
}) { }
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
30
src/GUIStuff/Elements/ManyElementScrollArea.hpp
Normal file
30
src/GUIStuff/Elements/ManyElementScrollArea.hpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
#include "Element.hpp"
|
||||
#include "Helpers/ConvertVec.hpp"
|
||||
#include "ScrollArea.hpp"
|
||||
|
||||
namespace GUIStuff {
|
||||
|
||||
class ManyElementScrollArea : public Element {
|
||||
public:
|
||||
ManyElementScrollArea(GUIManager& gui);
|
||||
|
||||
struct Options {
|
||||
float entryHeight;
|
||||
size_t entryCount;
|
||||
bool clipHorizontal = false;
|
||||
Clay_LayoutAlignmentX xAlign = CLAY_ALIGN_X_LEFT;
|
||||
Clay_SizingAxis xElementSize = CLAY_SIZING_GROW(0);
|
||||
ScrollArea::ScrollbarType scrollbar = ScrollArea::ScrollbarType::NORMAL;
|
||||
std::function<void(size_t elementIndex)> elementContent;
|
||||
std::function<void(const ScrollArea::InnerContentParameters&)> innerContentExtraCallback;
|
||||
};
|
||||
|
||||
void layout(const Clay_ElementId& id, const Options& opts);
|
||||
|
||||
ScrollArea* scrollArea = nullptr;
|
||||
private:
|
||||
Options options;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
#include "TreeListing.hpp"
|
||||
#include "Helpers/ConvertVec.hpp"
|
||||
#include "ScrollArea.hpp"
|
||||
#include "ManyElementScrollArea.hpp"
|
||||
#include "../GUIManager.hpp"
|
||||
|
||||
#include "../ElementHelpers/ScrollAreaHelpers.hpp"
|
||||
#include "../ElementHelpers/ButtonHelpers.hpp"
|
||||
#include "LayoutElement.hpp"
|
||||
|
||||
|
|
@ -54,10 +53,9 @@ void TreeListing::layout(const Clay_ElementId& id, const Data& newDisplayData) {
|
|||
CLAY(lIdParent, {
|
||||
.layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}
|
||||
}) {
|
||||
scroll_area_many_entries(gui, "scroll", {
|
||||
gui.element<ManyElementScrollArea>("scroll", ManyElementScrollArea::Options{
|
||||
.entryHeight = ENTRY_HEIGHT,
|
||||
.entryCount = flattenedIndexList.size(),
|
||||
.growing = d.scrollAreaGrowing,
|
||||
.elementContent = [&](size_t i) {
|
||||
const ObjInfo& objInfo = flattenedIndexList[i];
|
||||
gui.element<LayoutElement>("elem", [&](LayoutElement*, const Clay_ElementId& lId) {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ class TreeListing : public Element {
|
|||
};
|
||||
|
||||
struct Data {
|
||||
bool scrollAreaGrowing = true;
|
||||
std::set<TreeListingObjIndexList>* selectedIndices = nullptr;
|
||||
std::function<std::optional<DirectoryInfo>(const TreeListingObjIndexList& objIndex)> dirInfo;
|
||||
std::function<void(const TreeListingObjIndexList& objIndex, bool isOpen)> setDirectoryOpen;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue