Fix layoutorder on file entries spazzing out in non-testbed apps.

This commit is contained in:
2025-07-08 14:33:35 -05:00
parent d0a246bffe
commit c8946673c3

View File

@@ -27,13 +27,14 @@ namespace JUI
Event<> UserCompleted; Event<> UserCompleted;
Event<> UserConfirmed; Event<> UserConfirmed;
Event<> UserCancelled; Event<> UserCancelled;
Event<std::string> FileSelected;
FileDialogWindow() : Window() { FileDialogWindow() : Window() {
Title("File Dialog"); Title("File Dialog");
auto* toolbar = new JUI::UtilityBar(this->Content()); //auto* toolbar = new JUI::UtilityBar(this->Content());
auto* file_listing = new JUI::Rect(this->Content()); auto* file_listing = new JUI::ScrollingRect(this->Content());
file_listing->Size({100_percent, 100_percent-20_px}); file_listing->Size({100_percent, 100_percent-20_px});
file_layout = new JUI::VerticalListLayout(file_listing); file_layout = new JUI::VerticalListLayout(file_listing);
@@ -82,7 +83,8 @@ namespace JUI
JUI::Rect* CreateFileEntry(const std::filesystem::directory_entry& entry) { JUI::Rect* CreateFileEntry(const std::filesystem::directory_entry& entry) {
auto* rect = new JUI::TextRect(file_layout); auto* rect = new JUI::TextButton(file_layout);
rect->LayoutOrder(index);
rect->Size({100_percent, 20_px}); rect->Size({100_percent, 20_px});
std::string entry_type = entry.is_directory() ? "directory" : "file"; std::string entry_type = entry.is_directory() ? "directory" : "file";
@@ -95,11 +97,17 @@ namespace JUI
std::string label = std::format("{} {} {} {} {}", entry.path().filename().string(), file_size_str, entry_type, perms, timestamp); std::string label = std::format("{} {} {} {} {}", entry.path().filename().string(), file_size_str, entry_type, perms, timestamp);
rect->Content(label); rect->Content(label);
rect->BaseBGColor(Colors::Gray);
index++;
rect->Clicked += [this, entry] (auto ev) mutable {
FileSelected(entry.path().string());
};
return rect; return rect;
} }
FileDialogWindow(const std::filesystem::path& root) : FileDialogWindow() { FileDialogWindow(const std::filesystem::path& root) : FileDialogWindow() {
std::cout << root.relative_path() << std::endl; std::cout << root.relative_path() << std::endl;
std::cout << root.root_directory() << std::endl; std::cout << root.root_directory() << std::endl;
@@ -120,11 +128,15 @@ namespace JUI
Parent(parent); Parent(parent);
} }
void SetSelectedFile(const std::string& filename);
void SetConfirmOverwrite(bool confirm);
void SetBlockingWhileOpen(bool blocking);
bool GetBlockingWhileOpen() const;
protected: protected:
int directories_indexed = 0; int directories_indexed = 0;
int index = 0;
VerticalListLayout* file_layout; VerticalListLayout* file_layout;
std::vector<Rect*> file_entry_widgets; std::vector<Rect*> file_entry_widgets;
private: private: