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
|
|
@ -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