Skip to content

Commit c908c28

Browse files
committed
[ADD] : add a place separator
[FIX] : fix places ui styles
1 parent 23212e1 commit c908c28

2 files changed

Lines changed: 59 additions & 19 deletions

File tree

ImGuiFileDialog.cpp

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,12 @@ inline bool inRadioButton(const char* vLabel, bool vToggled) {
348348
#ifndef removePlaceButtonString
349349
#define removePlaceButtonString "-"
350350
#endif // removePlaceButtonString
351+
#ifndef validatePlaceButtonString
352+
#define validatePlaceButtonString "ok"
353+
#endif // validatePlaceButtonString
354+
#ifndef editPlaceButtonString
355+
#define editPlaceButtonString "E"
356+
#endif // editPlaceButtonString
351357
#ifndef IMGUI_TOGGLE_BUTTON
352358
inline bool inToggleButton(const char* vLabel, bool* vToggled) {
353359
bool pressed = false;
@@ -3012,6 +3018,7 @@ bool IGFD::PlacesFeature::m_DrawPlacesPane(FileDialogInternal& vFileDialogIntern
30123018
auto group_ptr = group.second.lock();
30133019
if (group_ptr != nullptr) {
30143020
if (ImGui::CollapsingHeader(group_ptr->name.c_str())) {
3021+
ImGui::BeginChild(group_ptr->name.c_str(), ImVec2(0, 0), ImGuiChildFlags_AutoResizeY);
30153022
if (group_ptr->canBeEdited) {
30163023
ImGui::PushID(group_ptr.get());
30173024
if (IMGUI_BUTTON(addPlaceButtonString "##ImGuiFileDialogAddPlace")) {
@@ -3021,13 +3028,18 @@ bool IGFD::PlacesFeature::m_DrawPlacesPane(FileDialogInternal& vFileDialogIntern
30213028
}
30223029
if (group_ptr->selectedPlaceForEdition >= 0 && group_ptr->selectedPlaceForEdition < (int)group_ptr->places.size()) {
30233030
ImGui::SameLine();
3024-
if (IMGUI_BUTTON(removePlaceButtonString "##ImGuiFileDialogAddPlace")) {
3031+
if (IMGUI_BUTTON(removePlaceButtonString "##ImGuiFileDialogRemovePlace")) {
30253032
group_ptr->places.erase(group_ptr->places.begin() + group_ptr->selectedPlaceForEdition);
30263033
if (group_ptr->selectedPlaceForEdition == (int)group_ptr->places.size()) {
30273034
--group_ptr->selectedPlaceForEdition;
30283035
}
30293036
}
30303037
if (group_ptr->selectedPlaceForEdition >= 0 && group_ptr->selectedPlaceForEdition < (int)group_ptr->places.size()) {
3038+
ImGui::SameLine();
3039+
if (IMGUI_BUTTON(validatePlaceButtonString "##ImGuiFileDialogOkPlace")) {
3040+
group_ptr->places[(size_t)group_ptr->selectedPlaceForEdition].name = std::string(group_ptr->editBuffer);
3041+
group_ptr->selectedPlaceForEdition = -1;
3042+
}
30313043
ImGui::SameLine();
30323044
ImGui::PushItemWidth(vSize.x - ImGui::GetCursorPosX());
30333045
if (ImGui::InputText("##ImGuiFileDialogPlaceEdit", group_ptr->editBuffer, MAX_FILE_DIALOG_NAME_BUFFER)) {
@@ -3040,33 +3052,53 @@ bool IGFD::PlacesFeature::m_DrawPlacesPane(FileDialogInternal& vFileDialogIntern
30403052
ImGui::Separator();
30413053
}
30423054
if (!group_ptr->places.empty()) {
3055+
const auto& current_path = vFileDialogInternal.fileManager.GetCurrentPath();
30433056
group_ptr->clipper.Begin((int)group_ptr->places.size(), ImGui::GetTextLineHeightWithSpacing());
30443057
while (group_ptr->clipper.Step()) {
30453058
for (int i = group_ptr->clipper.DisplayStart; i < group_ptr->clipper.DisplayEnd; i++) {
3046-
if (i < 0) continue;
3047-
const PlaceStruct& place = group_ptr->places[(size_t)i];
3048-
ImGui::PushID(i);
3049-
std::string place_name = place.name;
3050-
if (!place.style.icon.empty()) {
3051-
place_name = place.style.icon + " " + place_name;
3059+
if (i < 0) {
3060+
continue;
30523061
}
3053-
if (ImGui::Selectable(place_name.c_str(), group_ptr->selectedPlaceForEdition == i, ImGuiSelectableFlags_AllowDoubleClick) ||
3054-
(group_ptr->selectedPlaceForEdition == -1 && place.path == vFileDialogInternal.fileManager.GetCurrentPath())) { // select if path is current
3055-
group_ptr->selectedPlaceForEdition = i;
3056-
IGFD::Utils::ResetBuffer(group_ptr->editBuffer);
3057-
IGFD::Utils::AppendToBuffer(group_ptr->editBuffer, MAX_FILE_DIALOG_NAME_BUFFER, place.name);
3058-
if (ImGui::IsMouseDoubleClicked(0)) { // apply path
3059-
vFileDialogInternal.fileManager.SetCurrentPath(place.path);
3060-
vFileDialogInternal.fileManager.OpenCurrentPath(vFileDialogInternal);
3061-
res = true;
3062+
const PlaceStruct& place = group_ptr->places[(size_t)i];
3063+
if (place.thickness > 0.0f) {
3064+
ImGui::SeparatorEx(ImGuiSeparatorFlags_Horizontal, place.thickness);
3065+
} else {
3066+
ImGui::PushID(i);
3067+
std::string place_name = place.name;
3068+
if (!place.style.icon.empty()) {
3069+
place_name = place.style.icon + " " + place_name;
30623070
}
3063-
}
3064-
ImGui::PopID();
3065-
if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", place.path.c_str()); //-V111
3071+
if (group_ptr->canBeEdited) {
3072+
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
3073+
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
3074+
if (ImGui::SmallButton(editPlaceButtonString "##ImGuiFileDialogPlaceEditButton")) {
3075+
group_ptr->selectedPlaceForEdition = i;
3076+
IGFD::Utils::ResetBuffer(group_ptr->editBuffer);
3077+
IGFD::Utils::AppendToBuffer(group_ptr->editBuffer, MAX_FILE_DIALOG_NAME_BUFFER, place.name);
3078+
}
3079+
ImGui::PopStyleVar();
3080+
ImGui::PopStyleColor();
3081+
ImGui::SameLine();
3082+
}
3083+
if (ImGui::Selectable(place_name.c_str(), current_path == place.path || group_ptr->selectedPlaceForEdition == i, ImGuiSelectableFlags_AllowDoubleClick)) { // select if path is current
3084+
if (ImGui::IsMouseDoubleClicked(0)) {
3085+
group_ptr->selectedPlaceForEdition = -1; // stop edition
3086+
// apply path
3087+
vFileDialogInternal.fileManager.SetCurrentPath(place.path);
3088+
vFileDialogInternal.fileManager.OpenCurrentPath(vFileDialogInternal);
3089+
res = true;
3090+
}
3091+
}
3092+
ImGui::PopID();
3093+
if (ImGui::IsItemHovered()) {
3094+
ImGui::SetTooltip("%s", place.path.c_str());
3095+
}
3096+
}
30663097
}
30673098
}
30683099
group_ptr->clipper.End();
30693100
}
3101+
ImGui::EndChild();
30703102
}
30713103
}
30723104
}
@@ -3155,6 +3187,12 @@ bool IGFD::PlacesFeature::GroupStruct::AddPlace(const std::string& vPlaceName, c
31553187
return true;
31563188
}
31573189

3190+
void IGFD::PlacesFeature::GroupStruct::AddPlaceSeparator(const float& vThickness) {
3191+
PlaceStruct place;
3192+
place.thickness = vThickness;
3193+
places.push_back(place);
3194+
}
3195+
31583196
bool IGFD::PlacesFeature::GroupStruct::RemovePlace(const std::string& vPlaceName) {
31593197
if (vPlaceName.empty()) {
31603198
return false;

ImGuiFileDialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,6 +2048,7 @@ class IGFD_API PlacesFeature {
20482048
std::string path; // absolute path of the place
20492049
bool canBeSaved = true; // defined by code, can be used for prevent serialization / deserialization
20502050
FileStyle style;
2051+
float thickness = 0.0f; // when more than 0.0f, is a separator
20512052
};
20522053

20532054
struct GroupStruct {
@@ -2064,6 +2065,7 @@ class IGFD_API PlacesFeature {
20642065
const std::string& vPlacePath, // place path
20652066
const bool& vCanBeSaved, // prevent serialization
20662067
const FileStyle& vStyle = {}); // style
2068+
void AddPlaceSeparator(const float& vThickness = 1.0f);
20672069
bool RemovePlace( // remove a place by code, return true if succeed
20682070
const std::string& vPlaceName); // place name to remove
20692071
};

0 commit comments

Comments
 (0)