From cfd1d5e0e18f80d5058762b43e5423d1d4842e5f Mon Sep 17 00:00:00 2001 From: Tristan Walter <twalter@orn.mpg.de> Date: Mon, 9 Nov 2020 13:44:46 +0100 Subject: [PATCH] * hovered state for items in filechooser * operator->() is const now for derived_ptrs * not finding the fonts does no longer crash the application --- Application/src/commons/common/gui/IMGUIBase.cpp | 9 ++++++--- Application/src/commons/common/gui/types/Layout.h | 2 +- .../src/commons/common/gui/types/ScrollableList.h | 9 +++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Application/src/commons/common/gui/IMGUIBase.cpp b/Application/src/commons/common/gui/IMGUIBase.cpp index c2221fa..d0eb29d 100644 --- a/Application/src/commons/common/gui/IMGUIBase.cpp +++ b/Application/src/commons/common/gui/IMGUIBase.cpp @@ -422,7 +422,7 @@ void clear_cache() { file::Path path("fonts/Quicksand-"); if (!path.add_extension("ttf").exists()) - U_EXCEPTION("Cannot find file '%S'", &path.str()); + Except("Cannot find file '%S'", &path.str()); auto io = ImGui::GetIO(); //io.FontAllowUserScaling = true; @@ -449,8 +449,11 @@ void clear_cache() { auto full = path.str() + suffix + ".ttf"; auto ptr = io.Fonts->AddFontFromFileTTF(full.c_str(), base_scale * im_font_scale, &config); - if(!ptr) - U_EXCEPTION("Cannot load font '%S' with index %d.", &path.str(), config.FontNo); + if (!ptr) { + Warning("Cannot load font '%S' with index %d.", &path.str(), config.FontNo); + ptr = io.Fonts->AddFontDefault(); + im_font_scale = max(1, dpi_scale) * 0.5; + } ptr->FontSize = base_scale * im_font_scale; return ptr; diff --git a/Application/src/commons/common/gui/types/Layout.h b/Application/src/commons/common/gui/types/Layout.h index 32062cf..b8a265b 100644 --- a/Application/src/commons/common/gui/types/Layout.h +++ b/Application/src/commons/common/gui/types/Layout.h @@ -22,7 +22,7 @@ namespace gui { bool operator<(derived_ptr<Base> other) const { return get() < other.get(); } operator bool() const { return get() != nullptr; } - Base* operator ->() { return get(); } + Base* operator ->() const { return get(); } template<typename T> operator derived_ptr<T> () { diff --git a/Application/src/commons/common/gui/types/ScrollableList.h b/Application/src/commons/common/gui/types/ScrollableList.h index 9e569e5..b13d081 100644 --- a/Application/src/commons/common/gui/types/ScrollableList.h +++ b/Application/src/commons/common/gui/types/ScrollableList.h @@ -23,9 +23,10 @@ namespace gui { template <typename Q = T> class Item { GETTER(Q, value) + GETTER_SETTER(bool, hovered) public: - Item(T v) : _value(v) {} + Item(T v) : _value(v), _hovered(false) {} }; GETTER(std::vector<Item<T>>, items) @@ -342,7 +343,8 @@ namespace gui { for(auto rect : _rects) { auto idx = rect_to_idx[rect]; auto item = static_cast<const CustomItem*>(&_items[idx].value()); - + _items[idx].set_hovered(rect->hovered()); + if(rect->pressed() || (_stays_toggled && (long)rect_to_idx[rect] == _last_selected_item)) rect->set_fillclr(item->base_color().brightenHSL(0.15f)); else if(rect->hovered()) @@ -353,6 +355,9 @@ namespace gui { } else { for(auto rect : _rects) { + auto idx = rect_to_idx[rect]; + _items[idx].set_hovered(rect->hovered()); + if(rect->pressed() || (_stays_toggled && (long)rect_to_idx[rect] == _last_selected_item)) rect->set_fillclr(_item_color.brighten(0.15f)); else if(rect->hovered()) -- GitLab