Skip to content

Commit

Permalink
Merge pull request #246 from PetrFlajsingr/245-reorder-classes-to-pro…
Browse files Browse the repository at this point in the history
…perties-events-functions-format

245 reorder classes to properties events functions format
  • Loading branch information
PetrFlajsingr authored Sep 19, 2022
2 parents 5785084 + 42c64eb commit 6415ecb
Show file tree
Hide file tree
Showing 111 changed files with 259 additions and 277 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ set(SOURCES
src/pf_imgui/interface/Element.cpp
src/pf_imgui/elements/ConsolePanel.cpp
src/pf_imgui/common/Label.cpp
)
src/pf_imgui/elements/plots/types/plot_types_impls.cpp)

set(BLUEPRINT_SOURCES
src/pf_imgui/node_editor/blueprint/pins/CheckboxPin.cpp
Expand Down Expand Up @@ -395,7 +395,7 @@ set(INCLUDES
src/pf_imgui/concepts/ConfigConstruction.h
src/pf_imgui/common/Tags.h
src/pf_imgui/reactive/PropertyOwner.h
src/pf_imgui/reactive/EventOwner.h)
src/pf_imgui/reactive/EventOwner.h src/pf_imgui/elements/plots/types/Plottable.h)

set(BLUEPRINT_INCLUDES
src/pf_imgui/node_editor/blueprint/common.h
Expand Down
1 change: 1 addition & 0 deletions src/pf_imgui/DockBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "DockBuilder.h"
#include <pf_imgui/dialogs/Window.h>
#include <pf_imgui/elements/DockSpace.h>

namespace pf::ui::ig {

Expand Down
2 changes: 1 addition & 1 deletion src/pf_imgui/DockBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <memory>
#include <pf_common/Visitor.h>
#include <pf_imgui/common/Size.h>
#include <pf_imgui/elements/DockSpace.h>
#include <pf_imgui/enums.h>
#include <pf_imgui/fwd.h>
#include <string>
#include <variant>
#include <vector>
Expand Down
8 changes: 8 additions & 0 deletions src/pf_imgui/ImGuiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
#include <range/v3/view/addressof.hpp>
#include <range/v3/view/filter.hpp>
#include <utility>
#include <pf_imgui/dialogs/BackgroundDockingArea.h>
#include <pf_imgui/dialogs/CommandPaletteWindow.h>
#include <pf_imgui/dialogs/Window.h>
#include <pf_imgui/elements/MenuBars.h>
#include <pf_imgui/elements/OverlayGizmo.h>
#include <pf_imgui/elements/RadioGroup.h>
#include <pf_imgui/elements/StatusBar.h>
#include <pf_imgui/interface/DragNDrop.h>

namespace pf::ui::ig {

Expand Down
29 changes: 8 additions & 21 deletions src/pf_imgui/ImGuiInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,13 @@
#ifndef PF_IMGUI_IMGUIINTERFACE_H
#define PF_IMGUI_IMGUIINTERFACE_H

// TODO: get rid of many of these include and use forward declarations
#include <imgui.h>
#include <memory>
#include <pf_imgui/DockBuilder.h>
#include <pf_imgui/_export.h>
#include <pf_imgui/dialogs/BackgroundDockingArea.h>
#include <pf_imgui/dialogs/CommandPaletteWindow.h>
#include <pf_imgui/dialogs/FileDialog.h>
#include <pf_imgui/dialogs/InputDialog.h>
#include <pf_imgui/dialogs/MessageDialog.h>
#include <pf_imgui/dialogs/ModalDialog.h>
#include <pf_imgui/dialogs/Window.h>
#include <pf_imgui/elements/MenuBars.h>
#include <pf_imgui/elements/OverlayGizmo.h>
#include <pf_imgui/elements/RadioGroup.h>
#include <pf_imgui/elements/StatusBar.h>
#include <pf_imgui/fwd.h>
#include <pf_imgui/icons.h>
#include <pf_imgui/interface/DragNDrop.h>
#include <pf_imgui/interface/ElementContainer.h>
#include <pf_imgui/managers/DialogManager.h>
#include <pf_imgui/managers/FontManager.h>
#include <pf_imgui/managers/NotificationManager.h>
Expand Down Expand Up @@ -272,7 +259,7 @@ class PF_IMGUI_EXPORT ImGuiInterface : public Renderable {
Font font = Font::Default();

protected:
std::unique_ptr<AppMenuBar> menuBar = nullptr;
std::unique_ptr<AppMenuBar> menuBar;

virtual void newFrame_impl() = 0;

Expand Down Expand Up @@ -302,19 +289,19 @@ class PF_IMGUI_EXPORT ImGuiInterface : public Renderable {
std::size_t idCounter{};

std::vector<std::unique_ptr<Window>> windows{};
std::unique_ptr<AppStatusBar> statusBar = nullptr;
std::unique_ptr<AppStatusBar> statusBar;

toml::table config;

std::vector<std::unique_ptr<DragNDropGroup>> dragNDropGroups{};
std::vector<std::unique_ptr<RadioGroup>> radioGroups{};
std::vector<std::unique_ptr<DragNDropGroup>> dragNDropGroups;
std::vector<std::unique_ptr<RadioGroup>> radioGroups;

std::vector<std::unique_ptr<CommandPaletteWindow>> commandPalettes{};
std::vector<std::unique_ptr<CommandPaletteWindow>> commandPalettes;

std::vector<std::unique_ptr<DockBuilder>> dockBuilders{};
std::unique_ptr<BackgroundDockingArea> backgroundDockingArea = nullptr;
std::vector<std::unique_ptr<DockBuilder>> dockBuilders;
std::unique_ptr<BackgroundDockingArea> backgroundDockingArea;

std::unique_ptr<ViewportOverlayGizmo> viewportGizmo{};
std::unique_ptr<ViewportOverlayGizmo> viewportGizmo;
};

} // namespace pf::ui::ig
Expand Down
1 change: 0 additions & 1 deletion src/pf_imgui/common/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#define PF_IMGUI_COLOR_H

#include <concepts>
#include <cstdint>
#include <imgui.h>
#include <pf_common/concepts/Integral.h>
#include <pf_imgui/_export.h>
Expand Down
1 change: 0 additions & 1 deletion src/pf_imgui/common/Size.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include <compare>
#include <concepts>
#include <cstdint>
#include <imgui.h>
#include <pf_imgui/_export.h>

Expand Down
5 changes: 2 additions & 3 deletions src/pf_imgui/dialogs/BackgroundDockingArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "BackgroundDockingArea.h"
#include <imgui_internal.h>
#include <imcmd_command_palette.h>

namespace pf::ui::ig {

Expand All @@ -12,15 +13,13 @@ BackgroundDockingArea::BackgroundDockingArea(std::string_view elementName)

DockSpace &BackgroundDockingArea::getDockSpace() { return dockSpace; }

Size BackgroundDockingArea::getSize() const { return size; }

void BackgroundDockingArea::renderImpl() {
RAII end{ImGui::End};
ImGui::SetNextWindowSize(ImGui::GetMainViewport()->Size - leftTopMargin - bottomRightMargin);
ImGui::SetNextWindowPos(ImGui::GetMainViewport()->Pos + leftTopMargin);
if (ImGui::Begin("##background_dock_window", nullptr, flags)) {
const auto viewportSize = ImGui::GetMainViewport()->Size;
size = Size{Width{viewportSize.x}, Height{viewportSize.y}};
*Prop_modify(size) = Size{Width{viewportSize.x}, Height{viewportSize.y}};
dockSpace.render();
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/pf_imgui/dialogs/BackgroundDockingArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef PF_IMGUI_DIALOGS_BACKGROUNDDOCKINGAREA_H
#define PF_IMGUI_DIALOGS_BACKGROUNDDOCKINGAREA_H

#include <pf_imgui/_export.h>
#include <pf_imgui/elements/DockSpace.h>
#include <pf_imgui/interface/Renderable.h>

Expand All @@ -16,7 +17,7 @@ namespace pf::ui::ig {
/**
* @brief A special type of window, which acts as docking area for the whole main viewport. It is always in the background.
*/
class BackgroundDockingArea : public Renderable {
class PF_IMGUI_EXPORT BackgroundDockingArea : public Renderable {
friend class ImGuiInterface;

public:
Expand All @@ -32,15 +33,15 @@ class BackgroundDockingArea : public Renderable {
*/
[[nodiscard]] DockSpace &getDockSpace();

[[nodiscard]] Size getSize() const;
/** Size automatically computed to fit the viewport */
ReadOnlyProperty<Size> size;

protected:
void renderImpl() override;

private:
ImVec2 leftTopMargin = ImVec2{0, 0};
ImVec2 bottomRightMargin = ImVec2{0, 0};
Size size;
DockSpace dockSpace;
constexpr static auto flags = ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoResize
| ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar;
Expand Down
9 changes: 9 additions & 0 deletions src/pf_imgui/dialogs/CommandPaletteWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//

#include "CommandPaletteWindow.h"
#include <imcmd_command_palette.h>

namespace pf::ui::ig {

Expand Down Expand Up @@ -33,4 +34,12 @@ void CommandPaletteWindow::renderImpl() {
if (!open) { *visibility.modify() = Visibility::Invisible; }
}

void CommandPaletteWindow::addCommandImpl(std::string commandName, std::function<void()> callback) {
ImCmd::SetCurrentContext(context);
auto command = ImCmd::Command{};
command.Name = std::move(commandName);
command.InitialCallback = std::forward<decltype(callback)>(callback);
ImCmd::AddCommand(std::move(command));
}

} // namespace pf::ui::ig
20 changes: 11 additions & 9 deletions src/pf_imgui/dialogs/CommandPaletteWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
* @date 8.2.22
*/

#ifndef PF_IMGUI_COMMANDPALETTEWINDOW_H
#define PF_IMGUI_COMMANDPALETTEWINDOW_H
#ifndef PF_IMGUI_DIALOGS_COMMANDPALETTEWINDOW_H
#define PF_IMGUI_DIALOGS_COMMANDPALETTEWINDOW_H

#include <imcmd_command_palette.h>
#include <pf_imgui/interface/Renderable.h>
#include <string>
#include <utility>

// fwd for command palette implementation
namespace ImCmd {
struct Context;
}

namespace pf::ui::ig {

/**
Expand All @@ -33,11 +37,7 @@ class CommandPaletteWindow : public Renderable {
* @param callback callback of the command
*/
void addCommand(std::string commandName, std::invocable auto &&callback) {
ImCmd::SetCurrentContext(context);
auto command = ImCmd::Command{};
command.Name = std::move(commandName);
command.InitialCallback = std::forward<decltype(callback)>(callback);
ImCmd::AddCommand(std::move(command));
addCommandImpl(std::move(commandName), std::forward<decltype(callback)>(callback));
}
/**
* Remove given command from the palette
Expand All @@ -59,8 +59,10 @@ class CommandPaletteWindow : public Renderable {
void renderImpl() override;

private:
void addCommandImpl(std::string commandName, std::function<void()> callback);

ImCmd::Context *context = nullptr;
};

} // namespace pf::ui::ig
#endif // PF_IMGUI_COMMANDPALETTEWINDOW_H
#endif // PF_IMGUI_DIALOGS_COMMANDPALETTEWINDOW_H
45 changes: 30 additions & 15 deletions src/pf_imgui/dialogs/FileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,35 @@
//

#include "FileDialog.h"
#include <ImGuiFileDialog.h>
#include <fmt/format.h>
#include <pf_imgui/managers/DialogManager.h>
#include <utility>

namespace pf::ui::ig {
// TODO: fix multi dir selection - when using GetSelection() it returns invalid path

FileDialog::FileDialog(FileType dialogFileType, std::string_view elementName, std::string_view labelText,
const std::vector<FileExtensionSettings> &extSettings,
std::function<void(std::vector<std::filesystem::path>)> onSelect, std::function<void()> onCancel,
Size initialSize, std::filesystem::path startPath, std::string startName, Modal modality,
uint32_t maxSelected)
: Renderable(elementName), label(std::string{labelText}), size(initialSize), openPath(std::move(startPath)),
defaultName(std::move(startName)), modal(modality), fileType(dialogFileType), maxSelectCount(maxSelected),
onFilesSelected(std::move(onSelect)), onSelectCanceled(std::move(onCancel)),
fileDialogInstance(new IGFD::FileDialog{}) {
if (fileType == FileType::File) { prepareExtInfos(extSettings); }
}

FileDialog::~FileDialog() = default;

bool FileDialog::isDone() const { return done; }

#ifdef USE_BOOKMARK
std::string FileDialog::serializeBookmark() { return fileDialogInstance.SerializeBookmarks(); }
std::string FileDialog::serializeBookmark() { return fileDialogInstance->SerializeBookmarks(); }

void FileDialog::deserializeBookmark(const std::string &bookmarkStr) {
fileDialogInstance.DeserializeBookmarks(bookmarkStr);
fileDialogInstance->DeserializeBookmarks(bookmarkStr);
}
#endif

void FileDialog::prepareExtInfos(const std::vector<FileExtensionSettings> &extSettings) {
for (const auto &[extNames, desc, extColor] : extSettings) {
Expand Down Expand Up @@ -47,25 +63,25 @@ void FileDialog::renderImpl() {
[[maybe_unused]] auto fontScoped = font.applyScopedIfNotDefault();
switch (modal) {
case Modal::Yes:
fileDialogInstance.OpenModal(getName(), label->get(), fileType == FileType::File ? filters.c_str() : nullptr,
openPath.string(), defaultName, static_cast<int>(maxSelectCount));
fileDialogInstance->OpenModal(getName(), label->get(), fileType == FileType::File ? filters.c_str() : nullptr,
openPath.string(), defaultName, static_cast<int>(maxSelectCount));
break;
case Modal::No:
fileDialogInstance.OpenDialog(getName(), label->get(), fileType == FileType::File ? filters.c_str() : nullptr,
openPath.string(), defaultName, static_cast<int>(maxSelectCount));
fileDialogInstance->OpenDialog(getName(), label->get(), fileType == FileType::File ? filters.c_str() : nullptr,
openPath.string(), defaultName, static_cast<int>(maxSelectCount));
break;
}

std::ranges::for_each(extColors, [this](const auto &extColor) {
const auto &[ext, col] = extColor;
fileDialogInstance.SetFileStyle(IGFD_FileStyleByExtention, ext.c_str(), static_cast<ImVec4>(col));
fileDialogInstance->SetFileStyle(IGFD_FileStyleByExtention, ext.c_str(), static_cast<ImVec4>(col));
});

if (fileDialogInstance.Display(getName(), ImGuiWindowFlags_NoCollapse, static_cast<ImVec2>(*size))) {
RAII end{[&] { fileDialogInstance.Close(); }};
if (fileDialogInstance.IsOk()) {
const auto filePathName = fileDialogInstance.GetFilePathName();
const auto selection = fileDialogInstance.GetSelection();
if (fileDialogInstance->Display(getName(), ImGuiWindowFlags_NoCollapse, static_cast<ImVec2>(*size))) {
RAII end{[&] { fileDialogInstance->Close(); }};
if (fileDialogInstance->IsOk()) {
const auto filePathName = fileDialogInstance->GetFilePathName();
const auto selection = fileDialogInstance->GetSelection();

if (!selection.empty() && fileType != FileType::Directory) {
auto selectionVec = std::vector<std::filesystem::path>();
Expand All @@ -81,5 +97,4 @@ void FileDialog::renderImpl() {
done = true;
}
}

} // namespace pf::ui::ig
Loading

0 comments on commit 6415ecb

Please sign in to comment.