Compare commits
2 Commits
Prerelease
...
master
Author | SHA1 | Date | |
---|---|---|---|
c8946673c3 | |||
d0a246bffe |
@@ -61,27 +61,31 @@ namespace JUI {
|
||||
auto origin_point = origin->Point();
|
||||
|
||||
using namespace J3ML;
|
||||
Color4 line_color = Colors::Blues::DarkBlue;
|
||||
float line_size = 1;
|
||||
|
||||
J2D::DrawLine(line_color, origin->Point(), goal->Point(), line_size);
|
||||
|
||||
float tri_size = 10;
|
||||
J2D::DrawLine(color, origin->Point(), goal->Point(), line_width);
|
||||
|
||||
Vector2 triangle_base_pt = goal->Point() + (origin->Point().Normalized());
|
||||
|
||||
J2D::DrawPoint(Colors::Yellow, triangle_base_pt, 4);
|
||||
Vector2 direction = ( origin->Point() - goal->Point()).Normalized();
|
||||
|
||||
Vector2 tri_left = triangle_base_pt.Normalized().Rotated90CW()*tri_size;
|
||||
Vector2 tri_right = triangle_base_pt.Normalized().Rotated90CW()*tri_size;
|
||||
Vector2 triangle_base_pt = goal->Point() + (direction*arrowhead_size);
|
||||
|
||||
//J2D::DrawPoint(Colors::Yellow, triangle_base_pt, 4);
|
||||
|
||||
Vector2 tri_left = triangle_base_pt + (direction.Rotated90CW() *arrowhead_size);
|
||||
Vector2 tri_right = triangle_base_pt + (direction.Rotated90CCW()*arrowhead_size);
|
||||
Vector2 tri_top = goal->Point();
|
||||
|
||||
J2D::DrawLine(line_color, tri_top, tri_left, line_size);
|
||||
J2D::DrawLine(line_color, tri_top, tri_right, line_size);
|
||||
J2D::DrawLine(color, tri_top, tri_left, arrowhead_size);
|
||||
J2D::DrawLine(color, tri_top, tri_right, arrowhead_size);
|
||||
|
||||
J2D::FillTriangle(line_color, {tri_left, tri_right, tri_top});
|
||||
}
|
||||
protected:
|
||||
|
||||
float arrowhead_size;
|
||||
float line_width;
|
||||
Color4 color;
|
||||
|
||||
Anchor* origin;
|
||||
Anchor* goal;
|
||||
private:
|
||||
|
@@ -20,16 +20,21 @@ namespace JUI
|
||||
{
|
||||
class FileListing : public JUI::Widget { };
|
||||
|
||||
// TODO: Implement SortBy enumeration - Date, Size, Name, Type
|
||||
class FileDialogWindow : public JUI::Window
|
||||
{
|
||||
public:
|
||||
Event<> UserCompleted;
|
||||
Event<> UserConfirmed;
|
||||
Event<> UserCancelled;
|
||||
Event<std::string> FileSelected;
|
||||
FileDialogWindow() : Window() {
|
||||
auto* toolbar = new JUI::UtilityBar(this->Content());
|
||||
|
||||
auto* file_listing = new JUI::Rect(this->Content());
|
||||
Title("File Dialog");
|
||||
|
||||
//auto* toolbar = new JUI::UtilityBar(this->Content());
|
||||
|
||||
auto* file_listing = new JUI::ScrollingRect(this->Content());
|
||||
file_listing->Size({100_percent, 100_percent-20_px});
|
||||
|
||||
file_layout = new JUI::VerticalListLayout(file_listing);
|
||||
@@ -37,32 +42,82 @@ namespace JUI
|
||||
|
||||
/// Tree system
|
||||
|
||||
std::string format_perms(const std::filesystem::perms& p) const {
|
||||
using std::filesystem::perms;
|
||||
auto parse = [=](char op, perms perm) {
|
||||
return (perms::none == (perm & p) ? '-' : op);
|
||||
};
|
||||
|
||||
std::string perm_string = "";
|
||||
|
||||
perm_string += parse('r', perms::owner_read);
|
||||
perm_string += parse('w', perms::owner_write);
|
||||
perm_string += parse('x', perms::owner_exec);
|
||||
|
||||
perm_string += parse('r', perms::group_read);
|
||||
perm_string += parse('w', perms::group_write);
|
||||
perm_string += parse('x', perms::group_exec);
|
||||
|
||||
perm_string += parse('r', perms::others_read);
|
||||
perm_string += parse('w', perms::others_write);
|
||||
perm_string += parse('x', perms::others_exec);
|
||||
|
||||
return perm_string;
|
||||
}
|
||||
|
||||
std::string format_size(uintmax_t size) const {
|
||||
bool addSpace = false;
|
||||
int precision = 2;
|
||||
std::vector<std::string> units = {"B", "KB", "GB", "TB", "PB", "EB", "ZB", "YB"};
|
||||
|
||||
if (Math::Abs(size) < 1) return std::to_string(size) + (addSpace ? " " : "") + units[0];
|
||||
|
||||
auto exponent = Math::Min<uintmax_t>(Math::Floor(Math::Log10(size < 0 ? -size : size) / 3), units.size()-1);
|
||||
|
||||
auto n = (size < 0 ? -size : size) / std::pow(1000, exponent);
|
||||
|
||||
|
||||
return (size < 0 ? "-" : "") + std::format("{}", n) + (addSpace ? " ": "") + units[exponent];
|
||||
}
|
||||
|
||||
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});
|
||||
|
||||
std::string entry_type = entry.is_directory() ? "directory" : "file";
|
||||
std::string perms = stringify(entry.status().permissions());
|
||||
std::string type = stringify(entry.status().type());
|
||||
std::string perms = format_perms(entry.status().permissions());
|
||||
|
||||
auto file_size = (entry.is_directory() ? entry.file_size() : 0 );
|
||||
auto file_size = (entry.is_directory() ? 0 : entry.file_size());
|
||||
auto file_size_str = format_size(file_size);
|
||||
std::filesystem::file_time_type timestamp = (entry.is_directory() ? std::filesystem::file_time_type{} : entry.last_write_time());
|
||||
|
||||
std::string label = std::format("{} {} {} {} {}", entry.path().filename().string(), entry.file_size(), perms, entry.last_write_time(), type);
|
||||
std::string label = std::format("{} {} {} {} {}", entry.path().filename().string(), file_size_str, entry_type, perms, timestamp);
|
||||
|
||||
rect->Content(entry.path().filename());
|
||||
rect->Content(label);
|
||||
rect->BaseBGColor(Colors::Gray);
|
||||
|
||||
index++;
|
||||
|
||||
if (entry.is_directory()) {
|
||||
|
||||
}
|
||||
rect->Clicked += [this, entry] (auto ev) mutable {
|
||||
FileSelected(entry.path().string());
|
||||
};
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
|
||||
FileDialogWindow(const std::filesystem::path& root) : FileDialogWindow() {
|
||||
std::cout << root.relative_path() << std::endl;
|
||||
std::cout << root.root_directory() << std::endl;
|
||||
std::cout << root.filename() << std::endl;
|
||||
std::cout << root.parent_path() << std::endl;
|
||||
std::cout << root.string() << std::endl;
|
||||
std::cout << std::filesystem::current_path() << std::endl;
|
||||
|
||||
Title(std::format("'{}' in '{}' - File Dialog", root.relative_path().string(), std::filesystem::current_path().string()));
|
||||
|
||||
for (const auto& entry: std::filesystem::directory_iterator(root)) {
|
||||
|
||||
CreateFileEntry(entry);
|
||||
@@ -73,10 +128,15 @@ namespace JUI
|
||||
Parent(parent);
|
||||
}
|
||||
|
||||
|
||||
void SetSelectedFile(const std::string& filename);
|
||||
void SetConfirmOverwrite(bool confirm);
|
||||
void SetBlockingWhileOpen(bool blocking);
|
||||
bool GetBlockingWhileOpen() const;
|
||||
|
||||
|
||||
protected:
|
||||
int directories_indexed = 0;
|
||||
int index = 0;
|
||||
VerticalListLayout* file_layout;
|
||||
std::vector<Rect*> file_entry_widgets;
|
||||
private:
|
||||
|
4
main.cpp
4
main.cpp
@@ -66,7 +66,7 @@ int count_descendants(JUI::Widget* w) {
|
||||
}
|
||||
|
||||
void CreateFileDialog() {
|
||||
auto* dialog = new JUI::FileDialogWindow(scene, "assets");
|
||||
auto* dialog = new JUI::FileDialogWindow(scene, ".");
|
||||
}
|
||||
|
||||
/// Creates the window that provides a "Welcome" dialog to the user.
|
||||
@@ -180,7 +180,7 @@ JUI::UtilityBar* CreateUtilityBar(JUI::Widget* root) {
|
||||
}
|
||||
}
|
||||
|
||||
auto* ptA = new JUI::Anchor(topbar, {30_px, 20_px});
|
||||
auto* ptA = new JUI::Anchor(topbar, {30_px, 40_px});
|
||||
|
||||
auto* ptB = new JUI::Anchor(demos, UDim2::BottomRight);
|
||||
|
||||
|
Reference in New Issue
Block a user