More scroll area fixes, added image display, and continuing work on file selector
This commit is contained in:
parent
4e1ab6fc50
commit
87f5f74c86
12 changed files with 131 additions and 25 deletions
|
|
@ -1,6 +1,5 @@
|
|||
#include "ScrollAreaHelpers.hpp"
|
||||
#include "../GUIManager.hpp"
|
||||
#include "../Elements/LayoutElement.hpp"
|
||||
|
||||
namespace GUIStuff { namespace ElementHelpers {
|
||||
|
||||
|
|
@ -13,8 +12,23 @@ ScrollArea* scroll_area_many_entries(GUIManager& gui, const char* id, const Scro
|
|||
.innerContent = [&](const ScrollArea::InnerContentParameters& params) {
|
||||
if(options.innerContentExtraCallback) options.innerContentExtraCallback(params);
|
||||
|
||||
if(params.containerDimensions.y() == 0.0f)
|
||||
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;
|
||||
|
|
@ -32,13 +46,11 @@ ScrollArea* scroll_area_many_entries(GUIManager& gui, const char* id, const Scro
|
|||
gui.new_id("many element list", [&] {
|
||||
for(size_t i = startPoint; i < endPoint; i++) {
|
||||
gui.new_id(i - startPoint, [&] {
|
||||
gui.element<LayoutElement>("elem", [&] (LayoutElement*, const Clay_ElementId& lId) {
|
||||
CLAY(lId, {
|
||||
.layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(options.entryHeight)}}
|
||||
}) {
|
||||
options.elementContent(i);
|
||||
}
|
||||
});
|
||||
CLAY_AUTO_ID({
|
||||
.layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(options.entryHeight)}}
|
||||
}) {
|
||||
options.elementContent(i);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ 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.
|
||||
std::function<void(size_t elementIndex)> elementContent;
|
||||
std::function<void(const ScrollArea::InnerContentParameters&)> innerContentExtraCallback;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ template <typename T> class DropDown : public Element {
|
|||
.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) {
|
||||
|
|
|
|||
42
src/GUIStuff/Elements/ImageDisplay.cpp
Normal file
42
src/GUIStuff/Elements/ImageDisplay.cpp
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#include "ImageDisplay.hpp"
|
||||
#include "../GUIManager.hpp"
|
||||
#include <include/codec/SkJpegDecoder.h>
|
||||
|
||||
namespace GUIStuff {
|
||||
|
||||
ImageDisplay::ImageDisplay(GUIManager& gui): Element(gui) {}
|
||||
|
||||
void ImageDisplay::layout(const Clay_ElementId& id, const std::filesystem::path& imgPath) {
|
||||
if(imgPath != oldImgPath) {
|
||||
std::string imgData;
|
||||
try {
|
||||
imgData = read_file_to_string(imgPath);
|
||||
auto codec = SkCodec::MakeFromData(SkData::MakeWithoutCopy(imgData.c_str(), imgData.size()), {
|
||||
SkJpegDecoder::Decoder()
|
||||
});
|
||||
img = std::get<0>(codec->getImage());
|
||||
} catch(...) {
|
||||
img = nullptr;
|
||||
}
|
||||
gui.invalidate_draw_element(this);
|
||||
}
|
||||
|
||||
CLAY(id, {
|
||||
.layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}},
|
||||
.custom = {.customData = this}
|
||||
}) {
|
||||
}
|
||||
}
|
||||
|
||||
void ImageDisplay::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) {
|
||||
if(img) {
|
||||
canvas->drawImageRect(img, boundingBox.value().get_sk_rect(), {SkFilterMode::kLinear, SkMipmapMode::kNone});
|
||||
}
|
||||
else {
|
||||
SkPaint p{io.theme->frontColor1};
|
||||
p.setAntiAlias(skiaAA);
|
||||
canvas->drawRect(boundingBox.value().get_sk_rect(), p);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
18
src/GUIStuff/Elements/ImageDisplay.hpp
Normal file
18
src/GUIStuff/Elements/ImageDisplay.hpp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include "Element.hpp"
|
||||
|
||||
namespace GUIStuff {
|
||||
|
||||
class ImageDisplay : public Element {
|
||||
public:
|
||||
ImageDisplay(GUIManager& gui);
|
||||
void layout(const Clay_ElementId& id, const std::filesystem::path& imgPath);
|
||||
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override;
|
||||
|
||||
private:
|
||||
std::filesystem::path oldImgPath;
|
||||
sk_sp<SkImage> img;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -57,6 +57,7 @@ void TreeListing::layout(const Clay_ElementId& id, const Data& newDisplayData) {
|
|||
scroll_area_many_entries(gui, "scroll", {
|
||||
.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,6 +31,7 @@ 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