From 9468e9ced711330acfa1c73f03dd3473b04d220d Mon Sep 17 00:00:00 2001 From: cklosters Date: Thu, 17 Aug 2023 11:59:34 +0200 Subject: [PATCH 01/10] add timeiscolour as target --- solution_info.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/solution_info.json b/solution_info.json index bd282c3a02..52fd167fea 100644 --- a/solution_info.json +++ b/solution_info.json @@ -1,5 +1,7 @@ { "Type": "nap::SolutionInfo", "mID": "SolutionInfo", - "AdditionalTargets": [] + "AdditionalTargets": [ + "apps/timeiscolour" + ] } \ No newline at end of file From 27f1ea44d306e8c64abe0882f63194998192336f Mon Sep 17 00:00:00 2001 From: cklosters Date: Tue, 22 Aug 2023 14:43:19 +0200 Subject: [PATCH 02/10] adjust spacing --- system_modules/napimgui/src/imguiservice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system_modules/napimgui/src/imguiservice.cpp b/system_modules/napimgui/src/imguiservice.cpp index 9c44c203d5..8d441222f4 100644 --- a/system_modules/napimgui/src/imguiservice.cpp +++ b/system_modules/napimgui/src/imguiservice.cpp @@ -300,7 +300,7 @@ namespace nap style->WindowRounding = 0.0f; style->FramePadding = ImVec2(5, 5); style->FrameRounding = 0.0f; - style->ItemSpacing = ImVec2(12, 6); + style->ItemSpacing = ImVec2(12, 9); style->ItemInnerSpacing = ImVec2(8, 6); style->IndentSpacing = 25.0f; style->ScrollbarSize = 13.0f; From 74d70a93f0cb58385599acbfb032a5f8da9b58e7 Mon Sep 17 00:00:00 2001 From: cklosters Date: Tue, 22 Aug 2023 18:29:28 +0200 Subject: [PATCH 03/10] add style configuration --- system_modules/napimgui/src/imguiservice.cpp | 174 +++++++++++-------- system_modules/napimgui/src/imguiservice.h | 33 +++- 2 files changed, 127 insertions(+), 80 deletions(-) diff --git a/system_modules/napimgui/src/imguiservice.cpp b/system_modules/napimgui/src/imguiservice.cpp index 8d441222f4..3221f37fef 100644 --- a/system_modules/napimgui/src/imguiservice.cpp +++ b/system_modules/napimgui/src/imguiservice.cpp @@ -45,6 +45,26 @@ RTTI_BEGIN_STRUCT(nap::gui::ColorPalette) RTTI_PROPERTY("InvertIcons", &nap::gui::ColorPalette::mInvertIcon, nap::rtti::EPropertyMetaData::Default) RTTI_END_STRUCT +RTTI_BEGIN_STRUCT(nap::gui::Style) + RTTI_PROPERTY("WindowPadding", &nap::gui::Style::mWindowPadding, nap::rtti::EPropertyMetaData::Default) + RTTI_PROPERTY("WindowRounding", &nap::gui::Style::mWindowRounding, nap::rtti::EPropertyMetaData::Default) + RTTI_PROPERTY("FramePadding", &nap::gui::Style::mFramePadding, nap::rtti::EPropertyMetaData::Default) + RTTI_PROPERTY("FrameRounding", &nap::gui::Style::mFrameRounding, nap::rtti::EPropertyMetaData::Default) + RTTI_PROPERTY("ItemSpacing", &nap::gui::Style::mItemSpacing, nap::rtti::EPropertyMetaData::Default) + RTTI_PROPERTY("ItemInnerSpacing", &nap::gui::Style::mItemInnerSpacing, nap::rtti::EPropertyMetaData::Default) + RTTI_PROPERTY("IndentSpacing", &nap::gui::Style::mIndentSpacing, nap::rtti::EPropertyMetaData::Default) + RTTI_PROPERTY("ScrollbarSize", &nap::gui::Style::mScrollbarSize, nap::rtti::EPropertyMetaData::Default) + RTTI_PROPERTY("ScrollbarRounding", &nap::gui::Style::mScrollbarRounding, nap::rtti::EPropertyMetaData::Default) + RTTI_PROPERTY("GrabMinSize", &nap::gui::Style::mGrabMinSize, nap::rtti::EPropertyMetaData::Default) + RTTI_PROPERTY("GrabRounding", &nap::gui::Style::mGrabRounding, nap::rtti::EPropertyMetaData::Default) + RTTI_PROPERTY("WindowBorderSize", &nap::gui::Style::mWindowBorderSize, nap::rtti::EPropertyMetaData::Default) + RTTI_PROPERTY("PopupRounding", &nap::gui::Style::mPopupRounding, nap::rtti::EPropertyMetaData::Default) + RTTI_PROPERTY("ChildRounding", &nap::gui::Style::mChildRounding, nap::rtti::EPropertyMetaData::Default) + RTTI_PROPERTY("WindowTitleAlign", &nap::gui::Style::mWindowTitleAlign, nap::rtti::EPropertyMetaData::Default) + RTTI_PROPERTY("PopupBorderSize", &nap::gui::Style::mPopupBorderSize, nap::rtti::EPropertyMetaData::Default) + RTTI_PROPERTY("TabRounding", &nap::gui::Style::mTabRounding, nap::rtti::EPropertyMetaData::Default) +RTTI_END_STRUCT + RTTI_BEGIN_CLASS(nap::IMGuiServiceConfiguration) RTTI_PROPERTY("ColorScheme", &nap::IMGuiServiceConfiguration::mColorScheme, nap::rtti::EPropertyMetaData::Default) RTTI_PROPERTY("FontSize", &nap::IMGuiServiceConfiguration::mFontSize, nap::rtti::EPropertyMetaData::Default) @@ -53,6 +73,7 @@ RTTI_BEGIN_CLASS(nap::IMGuiServiceConfiguration) RTTI_PROPERTY("FontSampling", &nap::IMGuiServiceConfiguration::mFontOversampling, nap::rtti::EPropertyMetaData::Default) RTTI_PROPERTY("FontSpacing", &nap::IMGuiServiceConfiguration::mFontSpacing, nap::rtti::EPropertyMetaData::Default) RTTI_PROPERTY("Colors", &nap::IMGuiServiceConfiguration::mCustomColors, nap::rtti::EPropertyMetaData::Default) + RTTI_PROPERTY("Style", &nap::IMGuiServiceConfiguration::mStyle, nap::rtti::EPropertyMetaData::Default) RTTI_END_CLASS RTTI_BEGIN_CLASS_NO_DEFAULT_CONSTRUCTOR(nap::IMGuiService) @@ -96,7 +117,7 @@ namespace nap icon::remove, icon::add, icon::change, - icon::subtract + icon::subtract }; return map; } @@ -136,7 +157,7 @@ namespace nap // Add custom scheme if not present scheme_map.emplace(std::make_pair(EColorScheme::Custom, customPalette)); - + // Return color palette assert(scheme_map.find(colorScheme) != scheme_map.end()); return scheme_map[colorScheme]; @@ -237,8 +258,8 @@ namespace nap static void destroyDeviceObjects(RenderService& renderService) { - if (gDescriptorSetLayout) { vkDestroyDescriptorSetLayout(renderService.getDevice(), gDescriptorSetLayout, nullptr); } - if (gSampler) { vkDestroySampler(renderService.getDevice(), gSampler, nullptr); } + if (gDescriptorSetLayout) { vkDestroyDescriptorSetLayout(renderService.getDevice(), gDescriptorSetLayout, nullptr); } + if (gSampler) { vkDestroySampler(renderService.getDevice(), gSampler, nullptr); } } @@ -277,7 +298,7 @@ namespace nap } - static std::unique_ptr createStyle(const gui::ColorPalette& palette) + static std::unique_ptr createStyle(const gui::ColorPalette& palette, const gui::Style& style) { // Get ImGUI colors ImVec4 IMGUI_NAPBACK(palette.mBackgroundColor, 0.94f); @@ -293,77 +314,77 @@ namespace nap ImVec4 IMGUI_NAPHIG3(palette.mHighlightColor3, 1.0f); // Create style - std::unique_ptr style = std::make_unique(); + std::unique_ptr gui_style = std::make_unique(); // Apply settings from config - style->WindowPadding = ImVec2(10, 10); - style->WindowRounding = 0.0f; - style->FramePadding = ImVec2(5, 5); - style->FrameRounding = 0.0f; - style->ItemSpacing = ImVec2(12, 9); - style->ItemInnerSpacing = ImVec2(8, 6); - style->IndentSpacing = 25.0f; - style->ScrollbarSize = 13.0f; - style->ScrollbarRounding = 0.0f; - style->GrabMinSize = 5.0f; - style->GrabRounding = 0.0f; - style->WindowBorderSize = 0.0f; - style->PopupRounding = 0.0f; - style->ChildRounding = 0.0f; - style->WindowTitleAlign = { 0.5f, 0.5f }; - style->PopupBorderSize = 0.0f; - style->TabRounding = 0.0f; - - style->Colors[ImGuiCol_Text] = IMGUI_NAPFRO4; - style->Colors[ImGuiCol_TextDisabled] = IMGUI_NAPFRO2; - style->Colors[ImGuiCol_WindowBg] = IMGUI_NAPBACK; - style->Colors[ImGuiCol_ChildBg] = IMGUI_NAPBACK; - style->Colors[ImGuiCol_PopupBg] = IMGUI_NAPBACK; - style->Colors[ImGuiCol_Border] = IMGUI_NAPDARK; - style->Colors[ImGuiCol_BorderShadow] = IMGUI_NAPFRO1; - style->Colors[ImGuiCol_FrameBg] = IMGUI_NAPDARK; - style->Colors[ImGuiCol_FrameBgHovered] = IMGUI_NAPDARK; - style->Colors[ImGuiCol_FrameBgActive] = IMGUI_NAPDARK; - style->Colors[ImGuiCol_TitleBg] = IMGUI_NAPMENU; - style->Colors[ImGuiCol_TitleBgCollapsed] = IMGUI_NAPMENU; - style->Colors[ImGuiCol_TitleBgActive] = IMGUI_NAPFRO2; - style->Colors[ImGuiCol_MenuBarBg] = IMGUI_NAPMENU; - style->Colors[ImGuiCol_ScrollbarBg] = IMGUI_NAPDARK; - style->Colors[ImGuiCol_ScrollbarGrab] = IMGUI_NAPMENU; - style->Colors[ImGuiCol_ScrollbarGrabHovered] = IMGUI_NAPFRO3; - style->Colors[ImGuiCol_ScrollbarGrabActive] = IMGUI_NAPFRO3; - style->Colors[ImGuiCol_CheckMark] = IMGUI_NAPFRO4; - style->Colors[ImGuiCol_SliderGrab] = IMGUI_NAPFRO3; - style->Colors[ImGuiCol_SliderGrabActive] = IMGUI_NAPFRO4; - style->Colors[ImGuiCol_Button] = IMGUI_NAPFRO1; - style->Colors[ImGuiCol_ButtonHovered] = IMGUI_NAPHIG1; - style->Colors[ImGuiCol_ButtonActive] = IMGUI_NAPFRO3; - style->Colors[ImGuiCol_Header] = IMGUI_NAPFRO1; - style->Colors[ImGuiCol_HeaderHovered] = IMGUI_NAPHIG1; - style->Colors[ImGuiCol_HeaderActive] = IMGUI_NAPHIG1; - style->Colors[ImGuiCol_ResizeGrip] = IMGUI_NAPFRO1; - style->Colors[ImGuiCol_ResizeGripHovered] = IMGUI_NAPFRO3; - style->Colors[ImGuiCol_ResizeGripActive] = IMGUI_NAPFRO4; - style->Colors[ImGuiCol_Tab] = IMGUI_NAPFRO1; - style->Colors[ImGuiCol_TabHovered] = IMGUI_NAPHIG1; - style->Colors[ImGuiCol_TabActive] = IMGUI_NAPHIG1; - style->Colors[ImGuiCol_TabUnfocused] = IMGUI_NAPFRO1; - style->Colors[ImGuiCol_TabUnfocusedActive] = IMGUI_NAPHIG1; - style->Colors[ImGuiCol_PlotLines] = IMGUI_NAPFRO3; - style->Colors[ImGuiCol_PlotLinesHovered] = IMGUI_NAPHIG1; - style->Colors[ImGuiCol_PlotHistogram] = IMGUI_NAPFRO3; - style->Colors[ImGuiCol_PlotHistogramHovered] = IMGUI_NAPHIG1; - style->Colors[ImGuiCol_TextSelectedBg] = IMGUI_NAPFRO1; - style->Colors[ImGuiCol_ModalWindowDimBg] = IMGUI_NAPMODA; - style->Colors[ImGuiCol_Separator] = IMGUI_NAPDARK; - style->Colors[ImGuiCol_SeparatorHovered] = IMGUI_NAPFRO4; - style->Colors[ImGuiCol_SeparatorActive] = IMGUI_NAPFRO4; - style->Colors[ImGuiCol_NavHighlight] = IMGUI_NAPFRO4; - style->Colors[ImGuiCol_NavWindowingHighlight] = IMGUI_NAPFRO4; - style->Colors[ImGuiCol_NavWindowingDimBg] = IMGUI_NAPMODA; - style->Colors[ImGuiCol_DragDropTarget] = IMGUI_NAPHIG1; - - return style; + gui_style->WindowPadding = { style.mWindowPadding.x, style.mWindowPadding.y }; + gui_style->WindowRounding = style.mWindowRounding; + gui_style->FramePadding = { style.mFramePadding.x, style.mFramePadding.y }; + gui_style->FrameRounding = style.mFrameRounding; + gui_style->ItemSpacing = { style.mItemSpacing.x, style.mItemSpacing.y }; + gui_style->ItemInnerSpacing = { style.mItemInnerSpacing.x, style.mItemInnerSpacing.y }; + gui_style->IndentSpacing = style.mIndentSpacing; + gui_style->ScrollbarSize = style.mScrollbarSize; + gui_style->ScrollbarRounding = style.mScrollbarRounding; + gui_style->GrabMinSize = style.mGrabMinSize; + gui_style->GrabRounding = style.mGrabRounding; + gui_style->WindowBorderSize = style.mWindowBorderSize; + gui_style->PopupRounding = style.mPopupRounding; + gui_style->ChildRounding = style.mChildRounding; + gui_style->WindowTitleAlign = { style.mWindowTitleAlign.x, style.mItemInnerSpacing.y }; + gui_style->PopupBorderSize = style.mPopupBorderSize; + gui_style->TabRounding = style.mTabRounding; + + gui_style->Colors[ImGuiCol_Text] = IMGUI_NAPFRO4; + gui_style->Colors[ImGuiCol_TextDisabled] = IMGUI_NAPFRO2; + gui_style->Colors[ImGuiCol_WindowBg] = IMGUI_NAPBACK; + gui_style->Colors[ImGuiCol_ChildBg] = IMGUI_NAPBACK; + gui_style->Colors[ImGuiCol_PopupBg] = IMGUI_NAPBACK; + gui_style->Colors[ImGuiCol_Border] = IMGUI_NAPDARK; + gui_style->Colors[ImGuiCol_BorderShadow] = IMGUI_NAPFRO1; + gui_style->Colors[ImGuiCol_FrameBg] = IMGUI_NAPDARK; + gui_style->Colors[ImGuiCol_FrameBgHovered] = IMGUI_NAPDARK; + gui_style->Colors[ImGuiCol_FrameBgActive] = IMGUI_NAPDARK; + gui_style->Colors[ImGuiCol_TitleBg] = IMGUI_NAPMENU; + gui_style->Colors[ImGuiCol_TitleBgCollapsed] = IMGUI_NAPMENU; + gui_style->Colors[ImGuiCol_TitleBgActive] = IMGUI_NAPFRO2; + gui_style->Colors[ImGuiCol_MenuBarBg] = IMGUI_NAPMENU; + gui_style->Colors[ImGuiCol_ScrollbarBg] = IMGUI_NAPDARK; + gui_style->Colors[ImGuiCol_ScrollbarGrab] = IMGUI_NAPMENU; + gui_style->Colors[ImGuiCol_ScrollbarGrabHovered] = IMGUI_NAPFRO3; + gui_style->Colors[ImGuiCol_ScrollbarGrabActive] = IMGUI_NAPFRO3; + gui_style->Colors[ImGuiCol_CheckMark] = IMGUI_NAPFRO4; + gui_style->Colors[ImGuiCol_SliderGrab] = IMGUI_NAPFRO3; + gui_style->Colors[ImGuiCol_SliderGrabActive] = IMGUI_NAPFRO4; + gui_style->Colors[ImGuiCol_Button] = IMGUI_NAPFRO1; + gui_style->Colors[ImGuiCol_ButtonHovered] = IMGUI_NAPHIG1; + gui_style->Colors[ImGuiCol_ButtonActive] = IMGUI_NAPFRO3; + gui_style->Colors[ImGuiCol_Header] = IMGUI_NAPFRO1; + gui_style->Colors[ImGuiCol_HeaderHovered] = IMGUI_NAPHIG1; + gui_style->Colors[ImGuiCol_HeaderActive] = IMGUI_NAPHIG1; + gui_style->Colors[ImGuiCol_ResizeGrip] = IMGUI_NAPFRO1; + gui_style->Colors[ImGuiCol_ResizeGripHovered] = IMGUI_NAPFRO3; + gui_style->Colors[ImGuiCol_ResizeGripActive] = IMGUI_NAPFRO4; + gui_style->Colors[ImGuiCol_Tab] = IMGUI_NAPFRO1; + gui_style->Colors[ImGuiCol_TabHovered] = IMGUI_NAPHIG1; + gui_style->Colors[ImGuiCol_TabActive] = IMGUI_NAPHIG1; + gui_style->Colors[ImGuiCol_TabUnfocused] = IMGUI_NAPFRO1; + gui_style->Colors[ImGuiCol_TabUnfocusedActive] = IMGUI_NAPHIG1; + gui_style->Colors[ImGuiCol_PlotLines] = IMGUI_NAPFRO3; + gui_style->Colors[ImGuiCol_PlotLinesHovered] = IMGUI_NAPHIG1; + gui_style->Colors[ImGuiCol_PlotHistogram] = IMGUI_NAPFRO3; + gui_style->Colors[ImGuiCol_PlotHistogramHovered] = IMGUI_NAPHIG1; + gui_style->Colors[ImGuiCol_TextSelectedBg] = IMGUI_NAPFRO1; + gui_style->Colors[ImGuiCol_ModalWindowDimBg] = IMGUI_NAPMODA; + gui_style->Colors[ImGuiCol_Separator] = IMGUI_NAPDARK; + gui_style->Colors[ImGuiCol_SeparatorHovered] = IMGUI_NAPFRO4; + gui_style->Colors[ImGuiCol_SeparatorActive] = IMGUI_NAPFRO4; + gui_style->Colors[ImGuiCol_NavHighlight] = IMGUI_NAPFRO4; + gui_style->Colors[ImGuiCol_NavWindowingHighlight] = IMGUI_NAPFRO4; + gui_style->Colors[ImGuiCol_NavWindowingDimBg] = IMGUI_NAPMODA; + gui_style->Colors[ImGuiCol_DragDropTarget] = IMGUI_NAPHIG1; + + return gui_style; } @@ -827,7 +848,6 @@ namespace nap for (const auto& display : mRenderService->getDisplays()) { float dpi_scale = math::max(display.getHorizontalDPI(), gui::dpi) / gui::dpi; - //nap::Logger::info("Display: %d, DPI Scale: %.2f", display.getIndex(), dpi_scale); mDPIScale = dpi_scale > mDPIScale ? dpi_scale : mDPIScale; } } @@ -838,7 +858,8 @@ namespace nap mFontAtlas = createFontAtlas(font_size, mConfiguration->mFontOversampling, mConfiguration->mFontSpacing, font_file); // Create style - mStyle = createStyle(getPalette()); + assert(mConfiguration != nullptr); + mStyle = createStyle(getPalette(), mConfiguration->mStyle); // Create context using font & style new_context = createContext(*getConfiguration(), *mFontAtlas, *mStyle, getIniFilePath(window.mID)); @@ -1048,7 +1069,6 @@ namespace nap // Overall font scaling factor is always <= 1.0, because the font is created based on the display with the highest DPI value float gscale = mGuiScale * (math::max(display.getHorizontalDPI(), gui::dpi) / gui::dpi); float fscale = math::max(display.getHorizontalDPI(), gui::dpi) / (mDPIScale * gui::dpi); - //nap::Logger::info("font scale: %.2f", fscale); // Push scaling for window and font based on new display // We must push the original style first before we can scale diff --git a/system_modules/napimgui/src/imguiservice.h b/system_modules/napimgui/src/imguiservice.h index 88a581eb3e..b77dd83df5 100644 --- a/system_modules/napimgui/src/imguiservice.h +++ b/system_modules/napimgui/src/imguiservice.h @@ -103,6 +103,31 @@ namespace nap RGBColor8 mHighlightColor4 = { 0xFF, 0x50, 0x50 }; ///< Property: 'HighlightColor4' Special highlight color 4 (errors) bool mInvertIcon = false; ///< Property: 'InvertIcon' If icons should be inverted }; + + /** + * Configurable GUI style options + */ + struct NAPAPI Style + { + Style() = default; + glm::vec2 mWindowPadding = { 10.0, 10.0f }; ///< Property: 'WindowPadding' + float mWindowRounding = 0.0f; ///< Property: 'WindowRounding' + glm::vec2 mFramePadding = { 5.0f, 5.0f }; ///< Property: 'FramePadding' + float mFrameRounding = 0.0f; ///< Property: 'FrameRounding' + glm::vec2 mItemSpacing = { 12.0f, 6.0f }; ///< Property: 'ItemSpacing' + glm::vec2 mItemInnerSpacing = { 8.0f, 6.0f }; ///< Property: 'ItemInnerSpacing' + float mIndentSpacing = 25.0f; ///< Property: 'IndentSpacing' + float mScrollbarSize = 13.0f; ///< Property: 'ScrollbarSize' + float mScrollbarRounding = 0.0f; ///< Property: 'ScrollbarRounding' + float mGrabMinSize = 5.0f; ///< Property: 'GrabMinSize' + float mGrabRounding = 0.0f; ///< Property: 'GrabRounding' + float mWindowBorderSize = 0.0f; ///< Property: 'WindowBorderSize' + float mPopupRounding = 0.0f; ///< Property: 'PopupRounding' + float mChildRounding = 0.0f; ///< Property: 'ChildRounding' + glm::vec2 mWindowTitleAlign = { 0.5f, 0.5f }; ///< Property: 'WindowTitleAlign' + float mPopupBorderSize = 0.0f; ///< Property: 'PopupBorderSize' + float mTabRounding = 0.0f; ///< Property: 'TabRounding' + }; } @@ -119,7 +144,8 @@ namespace nap std::string mFontFile = ""; ///< Property: 'FontFile' Path to a '.ttf' font file. If left empty the default NAP font will be used glm::ivec2 mFontOversampling = { 5, 3 }; ///< Property: 'FontSampling' Horizontal and vertical font oversampling, higher values result in sharper text in exchange for more memory. float mFontSpacing = 0.25f; ///< Property: 'FontSpacing' Extra horizontal spacing (in pixels) between glyphs. - gui::ColorPalette mCustomColors; ///< Property: 'Colors' Gui color overrides if scheme is set to custom + gui::ColorPalette mCustomColors; ///< Property: 'Colors' Color overrides if scheme is set to custom + gui::Style mStyle; ///< Property: 'Style' Configurable style elements virtual rtti::TypeInfo getServiceType() const override { return RTTI_OF(IMGuiService); } }; @@ -422,17 +448,18 @@ namespace nap */ void handleTouchEvent(const TouchEvent& touchEvent, GUIContext& context); + // Everything related to ImGUI RenderService* mRenderService = nullptr; mutable std::unordered_map mDescriptors; std::unique_ptr mAllocator; std::unordered_map> mContexts; std::unique_ptr mFontAtlas = nullptr; std::unique_ptr mStyle = nullptr; - IMGuiServiceConfiguration* mConfiguration = nullptr; float mGuiScale = 1.0f; ///< Overall GUI scaling factor float mDPIScale = 1.0f; ///< Max font scaling factor, based on the highest display dpi or 1.0 (default) when high dpi if off - // Color palette + // Selected colour palette and style + IMGuiServiceConfiguration* mConfiguration = nullptr; const gui::ColorPalette* mColorPalette = nullptr; // Icons From f89dd86746107061b2bb59a23580d326910eb3c6 Mon Sep 17 00:00:00 2001 From: cklosters Date: Wed, 23 Aug 2023 13:11:45 +0200 Subject: [PATCH 04/10] add move constructor to rect --- system_modules/napmath/src/rect.cpp | 12 ------------ system_modules/napmath/src/rect.h | 26 +++++++++++++++++--------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/system_modules/napmath/src/rect.cpp b/system_modules/napmath/src/rect.cpp index f68c842a58..9ca6b2b3c9 100644 --- a/system_modules/napmath/src/rect.cpp +++ b/system_modules/napmath/src/rect.cpp @@ -71,17 +71,5 @@ namespace nap { return getHeight() > math::epsilon(); } - - - const glm::vec2& Rect::getMin() const - { - return mMinPosition; - } - - - const glm::vec2& Rect::getMax() const - { - return mMaxPosition; - } } } diff --git a/system_modules/napmath/src/rect.h b/system_modules/napmath/src/rect.h index 40a77862a3..491f6dd94f 100644 --- a/system_modules/napmath/src/rect.h +++ b/system_modules/napmath/src/rect.h @@ -4,6 +4,7 @@ #pragma once +// External Includes #include #include #include @@ -14,7 +15,6 @@ namespace nap { /** * Simple 2D rectangle. - * This is a relatively light weight object that can be both copy and move constructed or assigned. */ class NAPAPI Rect final { @@ -36,13 +36,21 @@ namespace nap mMinPosition({ x, y }), mMaxPosition(mMinPosition + glm::vec2(width, height)) {}; /** - * Utility constructor + * Utility min max constructor * @param min: the min x, y position of the rectangle * @param max: the max x, y position of the rectangle */ constexpr Rect(const glm::vec2& min, const glm::vec2& max) : mMinPosition(min), mMaxPosition(max) {} + /** + * Utility min max move constructor + * @param min: the min x, y position of the rectangle + * @param max: the max x, y position of the rectangle + */ + constexpr Rect(glm::vec2&& min, glm::vec2&& max) : + mMinPosition(std::move(min)), mMaxPosition(std::move(max)) {} + // Equal-to operator overload bool operator==(const Rect& other) const; @@ -77,22 +85,22 @@ namespace nap /** * @return the min rectangle coordinates */ - const glm::vec2& getMin() const; + const glm::vec2& getMin() const { return mMinPosition; } /** * @return the max rectangle coordinates */ - const glm::vec2& getMax() const; + const glm::vec2& getMax() const { return mMaxPosition; } glm::vec2 mMinPosition = { 0.0f, 0.0f }; // min x,y position glm::vec2 mMaxPosition = { 0.0f, 0.0f }; // max x,y position }; // Static rectangles - static constexpr Rect topRightRect { { 0.0f, 0.0f}, { 1.0f, 1.0f} }; - static constexpr Rect topLeftRect { { -1.0f, 0.0f }, { 0.0f, 1.0f} }; - static constexpr Rect bottomLeftRect { { -1.0f, -1.0f }, { 0.0f, 0.0f} }; - static constexpr Rect bottomRightRect { { 0.0f, -1.0f }, { 1.0f, 0.0f} }; - static constexpr Rect centeredRect { { -0.5f, -0.5f }, { 0.5f, 0.5f} }; + static constexpr Rect topRightRect { { 0.0f, 0.0f }, { 1.0f, 1.0f} }; + static constexpr Rect topLeftRect { { -1.0f, 0.0f }, { 0.0f, 1.0f} }; + static constexpr Rect bottomLeftRect { { -1.0f, -1.0f }, { 0.0f, 0.0f} }; + static constexpr Rect bottomRightRect { { 0.0f, -1.0f }, { 1.0f, 0.0f} }; + static constexpr Rect centeredRect { { -0.5f, -0.5f }, { 0.5f, 0.5f} }; } } From a596089d5411a7dad60111c5068b76d2f916ff17 Mon Sep 17 00:00:00 2001 From: cklosters Date: Wed, 23 Aug 2023 14:04:38 +0200 Subject: [PATCH 05/10] Document gui properties --- system_modules/napimgui/src/imguiservice.cpp | 45 +++++++++++--------- system_modules/napimgui/src/imguiservice.h | 37 ++++++++-------- 2 files changed, 46 insertions(+), 36 deletions(-) diff --git a/system_modules/napimgui/src/imguiservice.cpp b/system_modules/napimgui/src/imguiservice.cpp index 3221f37fef..706082e43c 100644 --- a/system_modules/napimgui/src/imguiservice.cpp +++ b/system_modules/napimgui/src/imguiservice.cpp @@ -46,6 +46,8 @@ RTTI_BEGIN_STRUCT(nap::gui::ColorPalette) RTTI_END_STRUCT RTTI_BEGIN_STRUCT(nap::gui::Style) + RTTI_PROPERTY("AntiAliasedLines", &nap::gui::Style::mAntiAliasedLines, nap::rtti::EPropertyMetaData::Default) + RTTI_PROPERTY("AntiAliasedFill", &nap::gui::Style::mAntiAliasedFill, nap::rtti::EPropertyMetaData::Default) RTTI_PROPERTY("WindowPadding", &nap::gui::Style::mWindowPadding, nap::rtti::EPropertyMetaData::Default) RTTI_PROPERTY("WindowRounding", &nap::gui::Style::mWindowRounding, nap::rtti::EPropertyMetaData::Default) RTTI_PROPERTY("FramePadding", &nap::gui::Style::mFramePadding, nap::rtti::EPropertyMetaData::Default) @@ -63,6 +65,7 @@ RTTI_BEGIN_STRUCT(nap::gui::Style) RTTI_PROPERTY("WindowTitleAlign", &nap::gui::Style::mWindowTitleAlign, nap::rtti::EPropertyMetaData::Default) RTTI_PROPERTY("PopupBorderSize", &nap::gui::Style::mPopupBorderSize, nap::rtti::EPropertyMetaData::Default) RTTI_PROPERTY("TabRounding", &nap::gui::Style::mTabRounding, nap::rtti::EPropertyMetaData::Default) + RTTI_PROPERTY("TouchExtraPadding", &nap::gui::Style::mTouchExtraPadding, nap::rtti::EPropertyMetaData::Default) RTTI_END_STRUCT RTTI_BEGIN_CLASS(nap::IMGuiServiceConfiguration) @@ -316,25 +319,7 @@ namespace nap // Create style std::unique_ptr gui_style = std::make_unique(); - // Apply settings from config - gui_style->WindowPadding = { style.mWindowPadding.x, style.mWindowPadding.y }; - gui_style->WindowRounding = style.mWindowRounding; - gui_style->FramePadding = { style.mFramePadding.x, style.mFramePadding.y }; - gui_style->FrameRounding = style.mFrameRounding; - gui_style->ItemSpacing = { style.mItemSpacing.x, style.mItemSpacing.y }; - gui_style->ItemInnerSpacing = { style.mItemInnerSpacing.x, style.mItemInnerSpacing.y }; - gui_style->IndentSpacing = style.mIndentSpacing; - gui_style->ScrollbarSize = style.mScrollbarSize; - gui_style->ScrollbarRounding = style.mScrollbarRounding; - gui_style->GrabMinSize = style.mGrabMinSize; - gui_style->GrabRounding = style.mGrabRounding; - gui_style->WindowBorderSize = style.mWindowBorderSize; - gui_style->PopupRounding = style.mPopupRounding; - gui_style->ChildRounding = style.mChildRounding; - gui_style->WindowTitleAlign = { style.mWindowTitleAlign.x, style.mItemInnerSpacing.y }; - gui_style->PopupBorderSize = style.mPopupBorderSize; - gui_style->TabRounding = style.mTabRounding; - + // Apply colors gui_style->Colors[ImGuiCol_Text] = IMGUI_NAPFRO4; gui_style->Colors[ImGuiCol_TextDisabled] = IMGUI_NAPFRO2; gui_style->Colors[ImGuiCol_WindowBg] = IMGUI_NAPBACK; @@ -384,6 +369,28 @@ namespace nap gui_style->Colors[ImGuiCol_NavWindowingDimBg] = IMGUI_NAPMODA; gui_style->Colors[ImGuiCol_DragDropTarget] = IMGUI_NAPHIG1; + // Apply style settings + gui_style->WindowPadding = { style.mWindowPadding.x, style.mWindowPadding.y }; + gui_style->WindowRounding = style.mWindowRounding; + gui_style->FramePadding = { style.mFramePadding.x, style.mFramePadding.y }; + gui_style->FrameRounding = style.mFrameRounding; + gui_style->ItemSpacing = { style.mItemSpacing.x, style.mItemSpacing.y }; + gui_style->ItemInnerSpacing = { style.mItemInnerSpacing.x, style.mItemInnerSpacing.y }; + gui_style->IndentSpacing = style.mIndentSpacing; + gui_style->ScrollbarSize = style.mScrollbarSize; + gui_style->ScrollbarRounding = style.mScrollbarRounding; + gui_style->GrabMinSize = style.mGrabMinSize; + gui_style->GrabRounding = style.mGrabRounding; + gui_style->WindowBorderSize = style.mWindowBorderSize; + gui_style->PopupRounding = style.mPopupRounding; + gui_style->ChildRounding = style.mChildRounding; + gui_style->WindowTitleAlign = { style.mWindowTitleAlign.x, style.mItemInnerSpacing.y }; + gui_style->PopupBorderSize = style.mPopupBorderSize; + gui_style->TabRounding = style.mTabRounding; + gui_style->TouchExtraPadding = { style.mTouchExtraPadding.x, style.mTouchExtraPadding.y }; + gui_style->AntiAliasedFill = style.mAntiAliasedFill; + gui_style->AntiAliasedLines = style.mAntiAliasedLines; + return gui_style; } diff --git a/system_modules/napimgui/src/imguiservice.h b/system_modules/napimgui/src/imguiservice.h index b77dd83df5..c54e4d2d7f 100644 --- a/system_modules/napimgui/src/imguiservice.h +++ b/system_modules/napimgui/src/imguiservice.h @@ -110,23 +110,26 @@ namespace nap struct NAPAPI Style { Style() = default; - glm::vec2 mWindowPadding = { 10.0, 10.0f }; ///< Property: 'WindowPadding' - float mWindowRounding = 0.0f; ///< Property: 'WindowRounding' - glm::vec2 mFramePadding = { 5.0f, 5.0f }; ///< Property: 'FramePadding' - float mFrameRounding = 0.0f; ///< Property: 'FrameRounding' - glm::vec2 mItemSpacing = { 12.0f, 6.0f }; ///< Property: 'ItemSpacing' - glm::vec2 mItemInnerSpacing = { 8.0f, 6.0f }; ///< Property: 'ItemInnerSpacing' - float mIndentSpacing = 25.0f; ///< Property: 'IndentSpacing' - float mScrollbarSize = 13.0f; ///< Property: 'ScrollbarSize' - float mScrollbarRounding = 0.0f; ///< Property: 'ScrollbarRounding' - float mGrabMinSize = 5.0f; ///< Property: 'GrabMinSize' - float mGrabRounding = 0.0f; ///< Property: 'GrabRounding' - float mWindowBorderSize = 0.0f; ///< Property: 'WindowBorderSize' - float mPopupRounding = 0.0f; ///< Property: 'PopupRounding' - float mChildRounding = 0.0f; ///< Property: 'ChildRounding' - glm::vec2 mWindowTitleAlign = { 0.5f, 0.5f }; ///< Property: 'WindowTitleAlign' - float mPopupBorderSize = 0.0f; ///< Property: 'PopupBorderSize' - float mTabRounding = 0.0f; ///< Property: 'TabRounding' + bool mAntiAliasedLines = true; ///< Property: 'AntiAliasedLines' Enable anti-aliasing on lines/borders. Disable if you are really tight on CPU/GPU. + bool mAntiAliasedFill = true; ///< Property: 'AntiAliasedFill' Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.) + glm::vec2 mWindowPadding = { 10.0, 10.0f }; ///< Property: 'WindowPadding' Padding within a window. + float mWindowRounding = 0.0f; ///< Property: 'WindowRounding' Radius of window corners rounding. Set to 0.0f to have rectangular windows. + glm::vec2 mFramePadding = { 5.0f, 5.0f }; ///< Property: 'FramePadding' Padding within a framed rectangle (used by most widgets). + float mFrameRounding = 0.0f; ///< Property: 'FrameRounding' Radius of frame corners rounding. Set to 0.0f to have rectangular frame (used by most widgets). + glm::vec2 mItemSpacing = { 12.0f, 6.0f }; ///< Property: 'ItemSpacing' Horizontal and vertical spacing between widgets/lines. + glm::vec2 mItemInnerSpacing = { 8.0f, 6.0f }; ///< Property: 'ItemInnerSpacing' Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label). + float mIndentSpacing = 25.0f; ///< Property: 'IndentSpacing' Horizontal indentation when e.g. entering a tree node. Generally == (FontSize + FramePadding.x*2). + float mScrollbarSize = 13.0f; ///< Property: 'ScrollbarSize' Width of the vertical scrollbar, Height of the horizontal scrollbar. + float mScrollbarRounding = 0.0f; ///< Property: 'ScrollbarRounding' Radius of grab corners for scrollbar. + float mGrabMinSize = 5.0f; ///< Property: 'GrabMinSize' Minimum width/height of a grab box for slider/scrollbar. + float mGrabRounding = 0.0f; ///< Property: 'GrabRounding' Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs. + float mWindowBorderSize = 0.0f; ///< Property: 'WindowBorderSize' Thickness of border around windows. Generally set to 0.0f or 1.0f. (Other values are not well tested and more CPU/GPU costly). + float mPopupRounding = 0.0f; ///< Property: 'PopupRounding' Radius of popup window corners rounding. (Note that tooltip windows use WindowRounding) + float mChildRounding = 0.0f; ///< Property: 'ChildRounding' Radius of child window corners rounding. Set to 0.0f to have rectangular windows. + glm::vec2 mWindowTitleAlign = { 0.5f, 0.5f }; ///< Property: 'WindowTitleAlign' Alignment for title bar text. Defaults to (0.0f,0.5f) for left-aligned,vertically centered. + float mPopupBorderSize = 0.0f; ///< Property: 'PopupBorderSize' Thickness of border around popup/tooltip windows. Generally set to 0.0f or 1.0f. (Other values are not well tested and more CPU/GPU costly). + float mTabRounding = 0.0f; ///< Property: 'TabRounding' Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs. + glm::vec2 mTouchExtraPadding = { 0.0f, 0.0f }; ///< Property: 'TouchExtraPadding' Expand reactive bounding box for touch-based system where touch position is not accurate enough. We don't sort widgets so priority on overlap will always be given to the first widget. So don't grow this too much! }; } From f020ebfef8a757f5b8d35882f2ed790acf548b1e Mon Sep 17 00:00:00 2001 From: cklosters Date: Wed, 23 Aug 2023 14:06:31 +0200 Subject: [PATCH 06/10] just because I have OCD --- system_modules/napimgui/src/imguiservice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system_modules/napimgui/src/imguiservice.cpp b/system_modules/napimgui/src/imguiservice.cpp index 706082e43c..d38cfd9c23 100644 --- a/system_modules/napimgui/src/imguiservice.cpp +++ b/system_modules/napimgui/src/imguiservice.cpp @@ -370,6 +370,8 @@ namespace nap gui_style->Colors[ImGuiCol_DragDropTarget] = IMGUI_NAPHIG1; // Apply style settings + gui_style->AntiAliasedFill = style.mAntiAliasedFill; + gui_style->AntiAliasedLines = style.mAntiAliasedLines; gui_style->WindowPadding = { style.mWindowPadding.x, style.mWindowPadding.y }; gui_style->WindowRounding = style.mWindowRounding; gui_style->FramePadding = { style.mFramePadding.x, style.mFramePadding.y }; @@ -388,8 +390,6 @@ namespace nap gui_style->PopupBorderSize = style.mPopupBorderSize; gui_style->TabRounding = style.mTabRounding; gui_style->TouchExtraPadding = { style.mTouchExtraPadding.x, style.mTouchExtraPadding.y }; - gui_style->AntiAliasedFill = style.mAntiAliasedFill; - gui_style->AntiAliasedLines = style.mAntiAliasedLines; return gui_style; } From f8558fe22a9afb524cc0c8dd71b7cda166d4b6a6 Mon Sep 17 00:00:00 2001 From: cklosters Date: Wed, 23 Aug 2023 14:12:41 +0200 Subject: [PATCH 07/10] don't include project as additional target --- solution_info.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/solution_info.json b/solution_info.json index 52fd167fea..bd282c3a02 100644 --- a/solution_info.json +++ b/solution_info.json @@ -1,7 +1,5 @@ { "Type": "nap::SolutionInfo", "mID": "SolutionInfo", - "AdditionalTargets": [ - "apps/timeiscolour" - ] + "AdditionalTargets": [] } \ No newline at end of file From 1084ff97cbd1baa626fe98da2c45f33318100abf Mon Sep 17 00:00:00 2001 From: cklosters Date: Wed, 23 Aug 2023 15:13:54 +0200 Subject: [PATCH 08/10] fix title alignment --- system_modules/napimgui/src/imguiservice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system_modules/napimgui/src/imguiservice.cpp b/system_modules/napimgui/src/imguiservice.cpp index d38cfd9c23..f597cf6a2c 100644 --- a/system_modules/napimgui/src/imguiservice.cpp +++ b/system_modules/napimgui/src/imguiservice.cpp @@ -386,7 +386,7 @@ namespace nap gui_style->WindowBorderSize = style.mWindowBorderSize; gui_style->PopupRounding = style.mPopupRounding; gui_style->ChildRounding = style.mChildRounding; - gui_style->WindowTitleAlign = { style.mWindowTitleAlign.x, style.mItemInnerSpacing.y }; + gui_style->WindowTitleAlign = { style.mWindowTitleAlign.x, style.mWindowTitleAlign.y }; gui_style->PopupBorderSize = style.mPopupBorderSize; gui_style->TabRounding = style.mTabRounding; gui_style->TouchExtraPadding = { style.mTouchExtraPadding.x, style.mTouchExtraPadding.y }; From c985ad9b24daef84a9519d22f2664e9f4f451ba6 Mon Sep 17 00:00:00 2001 From: cklosters Date: Wed, 23 Aug 2023 15:15:07 +0200 Subject: [PATCH 09/10] update comment --- system_modules/napimgui/src/imguiservice.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system_modules/napimgui/src/imguiservice.h b/system_modules/napimgui/src/imguiservice.h index c54e4d2d7f..a33befe2fe 100644 --- a/system_modules/napimgui/src/imguiservice.h +++ b/system_modules/napimgui/src/imguiservice.h @@ -126,7 +126,7 @@ namespace nap float mWindowBorderSize = 0.0f; ///< Property: 'WindowBorderSize' Thickness of border around windows. Generally set to 0.0f or 1.0f. (Other values are not well tested and more CPU/GPU costly). float mPopupRounding = 0.0f; ///< Property: 'PopupRounding' Radius of popup window corners rounding. (Note that tooltip windows use WindowRounding) float mChildRounding = 0.0f; ///< Property: 'ChildRounding' Radius of child window corners rounding. Set to 0.0f to have rectangular windows. - glm::vec2 mWindowTitleAlign = { 0.5f, 0.5f }; ///< Property: 'WindowTitleAlign' Alignment for title bar text. Defaults to (0.0f,0.5f) for left-aligned,vertically centered. + glm::vec2 mWindowTitleAlign = { 0.5f, 0.5f }; ///< Property: 'WindowTitleAlign' Alignment for title bar text. Defaults to (0.5f,0.5f) for vertically & horizontally centered. float mPopupBorderSize = 0.0f; ///< Property: 'PopupBorderSize' Thickness of border around popup/tooltip windows. Generally set to 0.0f or 1.0f. (Other values are not well tested and more CPU/GPU costly). float mTabRounding = 0.0f; ///< Property: 'TabRounding' Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs. glm::vec2 mTouchExtraPadding = { 0.0f, 0.0f }; ///< Property: 'TouchExtraPadding' Expand reactive bounding box for touch-based system where touch position is not accurate enough. We don't sort widgets so priority on overlap will always be given to the first widget. So don't grow this too much! From eb2ffb4a9d0ffc71ab473d5dd4f7e508da98bc7c Mon Sep 17 00:00:00 2001 From: cklosters Date: Wed, 23 Aug 2023 21:31:19 +0200 Subject: [PATCH 10/10] open popup only once --- demos/copystamp/src/copystampapp.cpp | 7 +++++-- demos/copystamp/src/copystampapp.h | 1 - demos/paintobject/src/paintobjectapp.cpp | 7 +++++-- demos/paintobject/src/paintobjectapp.h | 1 - 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/demos/copystamp/src/copystampapp.cpp b/demos/copystamp/src/copystampapp.cpp index d8a019cf7b..c39be0b802 100644 --- a/demos/copystamp/src/copystampapp.cpp +++ b/demos/copystamp/src/copystampapp.cpp @@ -177,8 +177,12 @@ namespace nap // Notify user that painting in debug mode is slow #ifndef NDEBUG - if (!mPopupOpened) + static bool popup_opened = false; + if (!popup_opened) + { ImGui::OpenPopup(popupID); + popup_opened = true; + } handlePopup(); #endif // DEBUG @@ -206,7 +210,6 @@ namespace nap ImGui::SameLine(); if (ImGui::ImageButton(mGuiService->getIcon(icon::ok), "Gotcha")) { - mPopupOpened = true; ImGui::CloseCurrentPopup(); } ImGui::EndPopup(); diff --git a/demos/copystamp/src/copystampapp.h b/demos/copystamp/src/copystampapp.h index 65659fa762..9d64273f83 100644 --- a/demos/copystamp/src/copystampapp.h +++ b/demos/copystamp/src/copystampapp.h @@ -87,6 +87,5 @@ namespace nap // Handle debug popup void handlePopup(); - bool mPopupOpened = false; }; } diff --git a/demos/paintobject/src/paintobjectapp.cpp b/demos/paintobject/src/paintobjectapp.cpp index d417253f55..16ab7bcc65 100644 --- a/demos/paintobject/src/paintobjectapp.cpp +++ b/demos/paintobject/src/paintobjectapp.cpp @@ -114,8 +114,12 @@ namespace nap // Notify user that painting in debug mode is slow #ifndef NDEBUG - if (!mPopupOpened) + static bool popup_opened = false; + if (!popup_opened) + { ImGui::OpenPopup(popupID); + popup_opened = true; + } handlePopup(); #endif // DEBUG @@ -506,7 +510,6 @@ namespace nap ImGui::SameLine(); if (ImGui::ImageButton(mGuiService->getIcon(icon::ok), "Gotcha")) { - mPopupOpened = true; ImGui::CloseCurrentPopup(); } ImGui::EndPopup(); diff --git a/demos/paintobject/src/paintobjectapp.h b/demos/paintobject/src/paintobjectapp.h index 8cce2c4508..e35702dade 100644 --- a/demos/paintobject/src/paintobjectapp.h +++ b/demos/paintobject/src/paintobjectapp.h @@ -148,6 +148,5 @@ namespace nap // Handle debug popup void handlePopup(); - bool mPopupOpened = false; }; }