From 91dfaa5d7ecb0e63f052349f438343038cc1706d Mon Sep 17 00:00:00 2001 From: besh81 Date: Mon, 21 Jan 2019 11:37:35 +0100 Subject: [PATCH] added treebox scheme --- include/nana/gui/widgets/detail/compset.hpp | 16 +++++++- include/nana/gui/widgets/treebox.hpp | 37 +++++++++--------- source/gui/widgets/treebox.cpp | 43 +++++++++++---------- 3 files changed, 55 insertions(+), 41 deletions(-) diff --git a/include/nana/gui/widgets/detail/compset.hpp b/include/nana/gui/widgets/detail/compset.hpp index 7e77629d..3991fe4e 100644 --- a/include/nana/gui/widgets/detail/compset.hpp +++ b/include/nana/gui/widgets/detail/compset.hpp @@ -46,7 +46,7 @@ namespace nana{ namespace widgets{ namespace detail }; /// A component set placer used for specifying component position and size. - template + template class compset_placer { public: @@ -56,10 +56,22 @@ namespace nana{ namespace widgets{ namespace detail /// A type of widget-defined item attribute. typedef ItemAttribute item_attribute_t; + + /// Widget scheme. + typedef WidgetScheme widget_scheme_t; + + widget_scheme_t * wdg_scheme_ptr_{ nullptr }; + public: - /// The destrcutor. + /// The destructor. virtual ~compset_placer(){} + /// Init the scheme pointer + void init_scheme(widget_scheme_t* wdg_scheme_ptr) + { + wdg_scheme_ptr_ = wdg_scheme_ptr; + } + /// Enable/Disable the specified component. virtual void enable(component_t, bool) = 0; virtual bool enabled(component_t) const = 0; diff --git a/include/nana/gui/widgets/treebox.hpp b/include/nana/gui/widgets/treebox.hpp index bf8c2746..4ff78e99 100644 --- a/include/nana/gui/widgets/treebox.hpp +++ b/include/nana/gui/widgets/treebox.hpp @@ -60,8 +60,26 @@ namespace nana ::std::string text; }; + struct scheme + : public widget_geometrics + { + color_proxy item_bg_selected{ static_cast(0xD5EFFC) }; ///< item selected: background color + color_proxy item_fg_selected{ static_cast(0x99DEFD) }; ///< item selected: foreground color + color_proxy item_bg_highlighted{ static_cast(0xE8F5FD) }; ///< item highlighted: background color + color_proxy item_fg_highlighted{ static_cast(0xD8F0FA) }; ///< item highlighted: foreground color + color_proxy item_bg_selected_and_highlighted{ static_cast(0xC4E8FA) }; ///< item selected and highlighted: background color + color_proxy item_fg_selected_and_highlighted{ static_cast(0xB6E6FB) }; ///< item selected and highlighted: foreground color + + unsigned item_offset{ 16 }; ///< item position displacement in pixels + unsigned text_offset{ 4 }; ///< text position displacement in pixels + unsigned icon_size{ 16 }; ///< icon size in pixels + unsigned crook_size{ 16 }; ///< crook size in pixels (TODO: the function that draw the crook doesn't scale the shape) + + unsigned indent_displacement{ 18 }; ///< children position displacement in pixels (def=18 (before was 10)) + }; + typedef widgets::detail::compset compset_interface; - typedef widgets::detail::compset_placer compset_placer_interface; + typedef widgets::detail::compset_placer compset_placer_interface; class renderer_interface { @@ -347,23 +365,6 @@ namespace nana basic_event selected; ///< a user selects or unselects a node basic_event hovered; ///< a user moves the cursor over a node }; - - - struct scheme - : public widget_geometrics - { - color_proxy item_bg_selected{ static_cast(0xD5EFFC) }; ///< item selected: background color - color_proxy item_fg_selected{ static_cast(0x99DEFD) }; ///< item selected: foreground color - color_proxy item_bg_highlighted{ static_cast(0xE8F5FD) }; ///< item highlighted: background color - color_proxy item_fg_highlighted{ static_cast(0xD8F0FA) }; ///< item highlighted: foreground color - color_proxy item_bg_selected_and_highlighted{ static_cast(0xC4E8FA) }; ///< item selected and highlighted: background color - color_proxy item_fg_selected_and_highlighted{ static_cast(0xB6E6FB) }; ///< item selected and highlighted: foreground color - - - unsigned item_offset{ 16 }; - unsigned text_offset{ 4 }; - unsigned indent_displacement{ 18 }; ///< children position displacement in pixels (def=18 (before was 10)) - }; }//end namespace treebox }//end namespace drawerbase diff --git a/source/gui/widgets/treebox.cpp b/source/gui/widgets/treebox.cpp index 8152f42d..9deb3bd2 100644 --- a/source/gui/widgets/treebox.cpp +++ b/source/gui/widgets/treebox.cpp @@ -1330,8 +1330,6 @@ namespace nana class internal_placer : public compset_placer_interface { - static const unsigned item_offset = 16; - static const unsigned text_offset = 4; private: //Implement the compset_locator_interface @@ -1340,10 +1338,10 @@ namespace nana switch(comp) { case component_t::crook: - pixels_crook_ = (enabled ? 16 : 0); + enable_crook_ = enabled; break; case component_t::icon: - pixels_icon_ = (enabled ? 16 : 0); + enable_icon_ = enabled; break; default: break; @@ -1355,9 +1353,9 @@ namespace nana switch(comp) { case component_t::crook: - return (0 != pixels_crook_); + return enable_crook_; case component_t::icon: - return (0 != pixels_icon_); + return enable_icon_; default: break; } @@ -1366,16 +1364,17 @@ namespace nana virtual unsigned item_height(graph_reference graph) const override { + auto m = std::max((enable_crook_ ? wdg_scheme_ptr_->crook_size : 0), (enable_icon_ ? wdg_scheme_ptr_->icon_size : 0)); #ifdef _nana_std_has_string_view - return graph.text_extent_size(std::wstring_view{ L"jH{", 3 }).height + 8; + return std::max(m, graph.text_extent_size(std::wstring_view{ L"jH{", 3 }).height + 8); #else - return graph.text_extent_size(L"jH{", 3).height + 8; + return std::max(m, graph.text_extent_size(L"jH{", 3).height + 8); #endif } virtual unsigned item_width(graph_reference graph, const item_attribute_t& attr) const override { - return graph.text_extent_size(attr.text).width + pixels_crook_ + pixels_icon_ + (text_offset << 1) + item_offset; + return graph.text_extent_size(attr.text).width + (enable_crook_ ? wdg_scheme_ptr_->crook_size : 0) + (enable_icon_ ? wdg_scheme_ptr_ ->icon_size: 0) + (wdg_scheme_ptr_->text_offset << 1) + wdg_scheme_ptr_->item_offset; } // Locate a component through the specified coordinate. @@ -1390,35 +1389,35 @@ namespace nana case component_t::expander: if(attr.has_children) { - r->width = item_offset; + r->width = wdg_scheme_ptr_->item_offset; return true; } return false; case component_t::bground: return true; case component_t::crook: - if(pixels_crook_) + if(enable_crook_) { - r->x += item_offset; - r->width = pixels_crook_; + r->x += wdg_scheme_ptr_->item_offset; + r->width = wdg_scheme_ptr_->crook_size; return true; } return false; case component_t::icon: - if(pixels_icon_) + if(enable_icon_) { - r->x += item_offset + pixels_crook_; + r->x += wdg_scheme_ptr_->item_offset + (enable_crook_ ? wdg_scheme_ptr_->crook_size : 0); r->y = 2; - r->width = pixels_icon_; + r->width = wdg_scheme_ptr_->icon_size; r->height -= 2; return true; } return false; case component_t::text: { - auto text_pos = item_offset + pixels_crook_ + pixels_icon_ + text_offset; + auto text_pos = wdg_scheme_ptr_->item_offset + (enable_crook_ ? wdg_scheme_ptr_->crook_size : 0) + (enable_icon_ ? wdg_scheme_ptr_->icon_size : 0) + wdg_scheme_ptr_->text_offset; r->x += text_pos; - r->width -= (text_pos + text_offset); + r->width -= (text_pos + wdg_scheme_ptr_->text_offset); }; return true; default: @@ -1427,8 +1426,8 @@ namespace nana return false; } private: - unsigned pixels_crook_{0}; - unsigned pixels_icon_{0}; + bool enable_crook_{ false }; + bool enable_icon_{ false }; }; class internal_renderer @@ -1534,7 +1533,7 @@ namespace nana if((nullptr == img) || img->empty()) img = &(item_attr.icon_normal); - if(! img->empty()) + if(!img->empty()) { auto size = img->size(); if(size.width > attr.area.width || size.height > attr.area.height) @@ -1947,6 +1946,8 @@ namespace nana widget.bgcolor(colors::white); impl_->data.widget_ptr = static_cast<::nana::treebox*>(&widget); impl_->data.scheme_ptr = static_cast<::nana::treebox::scheme_type*>(API::dev::get_scheme(widget)); + impl_->data.comp_placer->init_scheme(impl_->data.scheme_ptr); + widget.caption("nana treebox"); }