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
|
|
@ -4,8 +4,8 @@
|
|||
#include "../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
|
||||
#include "Helpers/ConvertVec.hpp"
|
||||
#include "../GUIStuff/Elements/GridScrollArea.hpp"
|
||||
#include "../GUIStuff/ElementHelpers/ButtonHelpers.hpp"
|
||||
#include "../GUIStuff/ElementHelpers/ScrollAreaHelpers.hpp"
|
||||
#include "../GUIStuff/Elements/ImageDisplay.hpp"
|
||||
#include "../World.hpp"
|
||||
|
||||
FileSelectScreen::FileSelectScreen(MainProgram& m): Screen(m) {}
|
||||
|
||||
|
|
@ -17,32 +17,61 @@ void FileSelectScreen::gui_layout_run() {
|
|||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_FIXED(gui.io.windowSize.x()), .height = CLAY_SIZING_FIXED(gui.io.windowSize.y())},
|
||||
.padding = CLAY_PADDING_ALL(15),
|
||||
.childGap = 15,
|
||||
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP },
|
||||
.layoutDirection = CLAY_TOP_TO_BOTTOM,
|
||||
},
|
||||
}) {
|
||||
text_label(gui, "Test grid");
|
||||
gui.element<GridScrollArea>("Test grid", GridScrollArea::Options{
|
||||
.entryMaximumWidth = 100.0f,
|
||||
text_label(gui, "File selector");
|
||||
auto& fileList = get_file_list();
|
||||
gui.element<GridScrollArea>("File selector grid", GridScrollArea::Options{
|
||||
.entryMaximumWidth = 200.0f,
|
||||
.childAlignmentX = CLAY_ALIGN_X_LEFT,
|
||||
.entryHeight = 100.0f,
|
||||
.entryCount = 20000,
|
||||
.entryHeight = 250.0f,
|
||||
.entryCount = fileList.size(),
|
||||
.elementContent = [&](size_t i) {
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
.sizing = { .width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)},
|
||||
.padding = CLAY_PADDING_ALL(2),
|
||||
.sizing = { .width = CLAY_SIZING_FIXED(150), .height = CLAY_SIZING_GROW(0)},
|
||||
.padding = CLAY_PADDING_ALL(gui.io.theme->padding1),
|
||||
.childGap = 2,
|
||||
.childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER },
|
||||
.layoutDirection = CLAY_TOP_TO_BOTTOM
|
||||
}
|
||||
}) {
|
||||
text_button_sized(gui, "button", "Square " + std::to_string(i), CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0));
|
||||
CLAY_AUTO_ID({
|
||||
.layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0) }},
|
||||
.aspectRatio = { .aspectRatio = 1.0f }
|
||||
}) {
|
||||
gui.element<ImageDisplay>("ico", main.conf.configPath / "saveThumbnails" / (fileList[i] + ".jpg"));
|
||||
}
|
||||
text_label(gui, fileList[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void FileSelectScreen::draw(SkCanvas* canvas) {
|
||||
canvas->clear(SkColor4f{0.0f, 0.0f, 0.0f, 0.0f});
|
||||
const std::vector<std::string>& FileSelectScreen::get_file_list() {
|
||||
if(!fileListOptional.has_value()) {
|
||||
std::filesystem::path savePath = main.conf.configPath / "saves";
|
||||
fileListOptional = std::vector<std::string>();
|
||||
auto& fL = fileListOptional.value();
|
||||
int globCount;
|
||||
char** filesInPath = SDL_GlobDirectory(savePath.string().c_str(), "*", 0, &globCount);
|
||||
if(filesInPath) {
|
||||
for(int i = 0; i < globCount; i++) {
|
||||
std::filesystem::path p = filesInPath[i];
|
||||
std::string fExt = p.extension().string();
|
||||
if(fExt == "." + World::FILE_EXTENSION)
|
||||
fL.emplace_back(p.stem().string());
|
||||
}
|
||||
}
|
||||
}
|
||||
return fileListOptional.value();
|
||||
}
|
||||
|
||||
void FileSelectScreen::draw(SkCanvas* canvas) {
|
||||
canvas->clear(main.g.gui.io.theme->backColor1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue