Skip to content

Commit

Permalink
Merge pull request #16 from lilggamegenius/fixed-includes
Browse files Browse the repository at this point in the history
Set include dirs to be SYSTEM to prevent user-enabled warnings in header
  • Loading branch information
kfsone authored Apr 23, 2024
2 parents f59b092 + 8655cab commit 265f13b
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 17 deletions.
10 changes: 9 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ add_library(
target_include_directories(
imguiwrap

PUBLIC
SYSTEM PUBLIC

${CMAKE_CURRENT_SOURCE_DIR}
)

target_include_directories(
imguiwrap

PRIVATE

${CMAKE_CURRENT_SOURCE_DIR}
)
Expand Down
14 changes: 9 additions & 5 deletions src/imguiwrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ glfw_error_callback(int error, const char* description) noexcept
// the passed ImGuiWrapperFn repeatedly until the std::optional it
// returns has a value, which is then returned as the exit code.
int
imgui_main(const ImGuiWrapConfig& config, const ImGuiWrapperFn& mainFn) noexcept
imgui_main(const ImGuiWrapConfig& config, const ImGuiWrapperFn& mainFn, const ImGuiWrapperInitFn &initFn) noexcept
{
// Setup window
glfwSetErrorCallback(glfw_error_callback);
Expand Down Expand Up @@ -106,6 +106,10 @@ imgui_main(const ImGuiWrapConfig& config, const ImGuiWrapperFn& mainFn) noexcept
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init(glsl_version);

// User Init Function
/// TODO: Double check if there's a better place to call this
initFn();

// Main loop
const auto& clearColor = config.clearColor_;
std::optional<int> exitCode{};
Expand Down Expand Up @@ -182,8 +186,8 @@ flagsWindow(const char* title, bool* showing, const std::function<void(void)>& i
}

constexpr ImGuiWindowFlags editWindowFlags = ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoFocusOnAppearing |
ImGuiWindowFlags_AlwaysUseWindowPadding;
ImGuiWindowFlags_NoFocusOnAppearing;
//ImGuiWindowFlags_AlwaysUseWindowPadding;

dear::Begin(title, showing, editWindowFlags) && impl;
}
Expand Down Expand Up @@ -288,8 +292,8 @@ namespace dear
ImGuiWindowFlags_AlwaysVerticalScrollbar);
ImGui::CheckboxFlags("AlwaysHorizontalScrollbar", flags,
ImGuiWindowFlags_AlwaysHorizontalScrollbar);
ImGui::CheckboxFlags("AlwaysUseWindowPadding", flags,
ImGuiWindowFlags_AlwaysUseWindowPadding);
//ImGui::CheckboxFlags("AlwaysUseWindowPadding", flags,
// ImGuiWindowFlags_AlwaysUseWindowPadding);
ImGui::CheckboxFlags("NoNavInputs", flags, ImGuiWindowFlags_NoNavInputs);
ImGui::CheckboxFlags("NoNavFocus", flags, ImGuiWindowFlags_NoNavFocus);
ImGui::CheckboxFlags("UnsavedDocument", flags, ImGuiWindowFlags_UnsavedDocument);
Expand Down
67 changes: 61 additions & 6 deletions src/imguiwrap.dear.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,18 @@ namespace dear
// Wrapper for ImGui::BeginChild ... EndChild, which will always call EndChild.
struct Child : public ScopeWrapper<Child, true>
{
Child(const char* title, const ImVec2& size = Zero, bool border = false,
Child(const char* title, const ImVec2& size = Zero, ImGuiChildFlags child_flags = 0,
ImGuiWindowFlags flags = 0) noexcept
: ScopeWrapper(ImGui::BeginChild(title, size, border, flags))
: ScopeWrapper(ImGui::BeginChild(title, size, child_flags, flags))
{}
Child(ImGuiID id, const ImVec2& size = Zero, bool border = false,
Child(ImGuiID id, const ImVec2& size = Zero, ImGuiChildFlags child_flags = 0,
ImGuiWindowFlags flags = 0) noexcept
: ScopeWrapper(ImGui::BeginChild(id, size, border, flags))
: ScopeWrapper(ImGui::BeginChild(id, size, child_flags, flags))
{}
static void dtor() noexcept { ImGui::EndChild(); }
};

#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
// Wrapper for ImGui::BeginChildFrame ... EndChildFrame, which will always call EndChildFrame.
struct ChildFrame : public ScopeWrapper<ChildFrame, true>
{
Expand All @@ -116,6 +117,7 @@ namespace dear
{}
static void dtor() noexcept { ImGui::EndChildFrame(); }
};
#endif

// Wrapper for ImGui::BeginGroup ... EndGroup which will always call EndGroup.
struct Group : public ScopeWrapper<Group, true>
Expand Down Expand Up @@ -179,7 +181,7 @@ namespace dear
// Wrapper for ImGui::Begin...EndToolTip.
struct Tooltip : public ScopeWrapper<Tooltip>
{
Tooltip() noexcept : ScopeWrapper(true) { ImGui::BeginTooltip(); }
Tooltip(bool enabled = true) noexcept : ScopeWrapper(enabled && ImGui::BeginTooltip()) { }
static void dtor() noexcept { ImGui::EndTooltip(); }
};

Expand Down Expand Up @@ -217,6 +219,31 @@ namespace dear
}
};

// Wrapper for ImGui::TreeNode...ImGui::TreePop.
// See also SeparatedTreeNode.
struct TreeNodeEx : public ScopeWrapper<TreeNodeEx>
{
template<typename... Args>
TreeNodeEx(Args&&... args) noexcept
: ScopeWrapper(ImGui::TreeNodeEx(std::forward<Args>(args)...))
{}
static void dtor() noexcept { ImGui::TreePop(); }
};

// Wrapper around a TreeNode followed by a Separator (it's a fairly common sequence).
struct SeparatedTreeNodeEx : public ScopeWrapper<SeparatedTreeNodeEx>
{
template<typename... Args>
SeparatedTreeNodeEx(Args&&... args) noexcept
: ScopeWrapper(ImGui::TreeNodeEx(std::forward<Args>(args)...))
{}
static void dtor() noexcept
{
ImGui::TreePop();
ImGui::Separator();
}
};

// Popup provides the stock wrapper around ImGui::BeginPopup...ImGui::EndPopup as well as two
// methods of instantiating a modal, for those who want modality to be a property fo Popup
// rather than a discrete type.
Expand Down Expand Up @@ -297,7 +324,7 @@ namespace dear
// Wrapper for BeginTooltip predicated on the previous item being hovered.
struct ItemTooltip : public ScopeWrapper<ItemTooltip>
{
ItemTooltip(ImGuiHoveredFlags flags = 0) noexcept
ItemTooltip(ImGuiHoveredFlags flags = ImGuiHoveredFlags_ForTooltip) noexcept
: ScopeWrapper(ImGui::IsItemHovered(flags))
{
if (ok_)
Expand All @@ -306,6 +333,34 @@ namespace dear
static void dtor() noexcept { ImGui::EndTooltip(); }
};

struct WithID : public ScopeWrapper<WithID>
{
template<typename... Args>
WithID(Args&&... args) noexcept : ScopeWrapper(true)
{
ImGui::PushID(std::forward<Args>(args)...);
}
static void dtor() noexcept
{
ImGui::PopID();
}
};

struct Disabled : public ScopeWrapper<Disabled>
{

Disabled(bool disabled) noexcept : ScopeWrapper(true)
{
ImGui::BeginDisabled(disabled); // Ideally we would only call this if disabled is true, but because dtor is static, we can't keep track of state
}
static void dtor() noexcept
{
ImGui::EndDisabled();
}
};



//// Text helpers

// std::string helpers.
Expand Down
3 changes: 2 additions & 1 deletion src/imguiwrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

using ImGuiWrapperReturnType = std::optional<int>;
using ImGuiWrapperFn = std::function<ImGuiWrapperReturnType()>;
using ImGuiWrapperInitFn = std::function<void()>;

// ImGuiWrapConfig describes the parameters of the main window created by imgui_main.
struct ImGuiWrapConfig
Expand Down Expand Up @@ -63,4 +64,4 @@ struct ImGuiWrapConfig
// imgui_main implements a main-loop that constructs a GL window and calls the supplied
// mainFn every frame until the app is closed.
// See dear::SetHostWindowSize if your callback needs to change the GL window size.
extern int imgui_main(const ImGuiWrapConfig& config, const ImGuiWrapperFn& mainFn) noexcept;
extern int imgui_main(const ImGuiWrapConfig& config, const ImGuiWrapperFn& mainFn, const ImGuiWrapperInitFn &initFn = []{}) noexcept;
2 changes: 1 addition & 1 deletion vendor/glfw
Submodule glfw updated 100 files
4 changes: 2 additions & 2 deletions vendor/imgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ add_library (
target_include_directories (
imgui

PUBLIC
SYSTEM PUBLIC

${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src/backends
${IMGUI_GLFW_PATH}/include
$<$<BOOL:${IMGUI_GLFW_PATH}>:${IMGUI_GLFW_PATH}/include>
)

target_link_libraries (
Expand Down
2 changes: 1 addition & 1 deletion vendor/imgui/src
Submodule src updated 178 files

0 comments on commit 265f13b

Please sign in to comment.