Readded bookmark menu

This commit is contained in:
Yousef Khadadeh 2026-04-06 20:16:25 +03:00
parent b7bd2efc71
commit 915fbe598b
10 changed files with 711 additions and 813 deletions

View file

@ -1,6 +1,13 @@
#pragma once
#include "Element.hpp"
#include <Helpers/NetworkingObjects/NetObjID.hpp>
#include <set>
namespace GUIStuff {
typedef std::vector<size_t> TreeListingObjIndexList;
}
bool operator<(const GUIStuff::TreeListingObjIndexList& a, const GUIStuff::TreeListingObjIndexList& b);
namespace GUIStuff {
@ -9,54 +16,37 @@ class GUIManager;
class TreeListing : public Element {
public:
static constexpr float ENTRY_HEIGHT = 25.0f;
static constexpr float ICON_SIZE = 25.0f;
struct ParentObjectIDPair {
NetworkingObjects::NetObjID parent;
NetworkingObjects::NetObjID object;
bool operator==(const ParentObjectIDPair&) const = default;
struct ObjInfo {
TreeListingObjIndexList objIndex;
bool isDirectory = false;
bool isOpen = false;
};
struct ParentObjectIDStack {
std::vector<NetworkingObjects::NetObjID> parents;
NetworkingObjects::NetObjID object;
struct DirectoryInfo {
size_t dirSize;
bool isOpen;
};
struct DisplayData {
struct ObjInList {
NetworkingObjects::NetObjID id;
bool isDirectory = false;
bool isDirectoryOpen = false;
};
std::function<std::optional<ObjInList>(NetworkingObjects::NetObjID, size_t)> getObjInListAtIndex;
std::function<size_t(const ParentObjectIDPair&)> getIndexOfObjInList;
std::function<void(NetworkingObjects::NetObjID, bool)> setDirectoryOpen;
std::function<bool(NetworkingObjects::NetObjID)> drawNonDirectoryObjIconGUI;
std::function<bool(const ParentObjectIDPair&)> drawObjGUI;
std::function<void(NetworkingObjects::NetObjID, size_t, const std::vector<ParentObjectIDPair>&)> moveObjectsToListAtIndex;
};
struct SelectionData {
std::vector<ParentObjectIDPair> orderedObjsSelected;
std::unordered_set<NetworkingObjects::NetObjID> objsSelected;
struct Data {
std::set<TreeListingObjIndexList>* selectedIndices = nullptr;
std::function<std::optional<DirectoryInfo>(const TreeListingObjIndexList& objIndex)> dirInfo;
std::function<void(const TreeListingObjIndexList& objIndex, bool isOpen)> setDirectoryOpen;
std::function<void(const TreeListingObjIndexList& objIndex)> drawNonDirectoryObjIconGUI;
std::function<void(const TreeListingObjIndexList& objIndex)> drawObjGUI;
std::function<void(const TreeListingObjIndexList& objIndex)> onDoubleClick;
std::function<void()> onSelectChange;
std::function<void(const std::vector<TreeListingObjIndexList>& objIndices, const TreeListingObjIndexList& newObjIndex)> moveObj;
};
TreeListing(GUIManager& gui);
void layout(const Clay_ElementId& id, NetworkingObjects::NetObjID rootObjID, const DisplayData& displayData, SelectionData& selectionData);
void layout(const Clay_ElementId& id, const Data& newDisplayData);
private:
bool dragHoldSelected = false;
void recursive_visible_flattened_obj_list(std::vector<ObjInfo>& objs, const TreeListingObjIndexList& objIndex);
void set_single_selected_object(SelectionData& selectionData);
void recursive_gui(UpdateInputData& io, GUIManager& gui, const DisplayData& displayData, SelectionData& selectionData, NetworkingObjects::NetObjID objID, size_t& itemCount, size_t itemCountToStartAt, size_t itemCountToEndAt, size_t listDepth, std::optional<ParentObjectIDStack>& hoveredObject, std::vector<NetworkingObjects::NetObjID>& parentIDStack, bool parentJustSelected);
void select_and_unselect_parents(const std::vector<NetworkingObjects::NetObjID>& parentIDStack, NetworkingObjects::NetObjID newSelectedObj, SelectionData& selectionData);
void unselect_object(NetworkingObjects::NetObjID id, SelectionData& selectionData);
bool topHalfOfHovered = false;
std::optional<ParentObjectIDPair> objDragged;
std::optional<ParentObjectIDStack> oldHoveredObject;
std::chrono::steady_clock::time_point timeStartedHoveringOverObject;
std::vector<ObjInfo> flattenedIndexList;
Data d;
};
}