From a71e02b5f2025a9df3851964a5414ae658bcd277 Mon Sep 17 00:00:00 2001 From: besh81 Date: Sat, 19 Jan 2019 15:04:19 +0100 Subject: [PATCH 1/2] adding treebox scheme --- include/nana/gui/widgets/treebox.hpp | 19 ++++++++- source/gui/widgets/treebox.cpp | 60 +++++++++++++++------------- 2 files changed, 50 insertions(+), 29 deletions(-) diff --git a/include/nana/gui/widgets/treebox.hpp b/include/nana/gui/widgets/treebox.hpp index ef804ff9..bf8c2746 100644 --- a/include/nana/gui/widgets/treebox.hpp +++ b/include/nana/gui/widgets/treebox.hpp @@ -347,13 +347,30 @@ 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 /// \brief Displays a hierarchical list of items, such as the files and directories on a disk. /// See also in [documentation](http://nanapro.org/en-us/documentation/widgets/treebox.htm) class treebox - :public widget_object < category::widget_tag, drawerbase::treebox::trigger, drawerbase::treebox::treebox_events> + :public widget_object { public: /// A type refers to the item and is also used to iterate through the nodes. diff --git a/source/gui/widgets/treebox.cpp b/source/gui/widgets/treebox.cpp index cf5c4ea8..8152f42d 100644 --- a/source/gui/widgets/treebox.cpp +++ b/source/gui/widgets/treebox.cpp @@ -238,11 +238,11 @@ namespace nana switch (affect) { case 1: - pos_.x += impl_->shape.indent_pixels; + pos_.x += impl_->data.scheme_ptr->indent_displacement; break; default: if (affect >= 2) - pos_.x -= impl_->shape.indent_pixels * (affect - 1); + pos_.x -= impl_->data.scheme_ptr->indent_displacement * (affect - 1); } auto & comp_placer = impl_->data.comp_placer; @@ -301,6 +301,7 @@ namespace nana { nana::paint::graphics * graph; ::nana::treebox * widget_ptr; + ::nana::treebox::scheme_type* scheme_ptr; trigger * trigger_ptr; pat::cloneable comp_placer; @@ -310,13 +311,11 @@ namespace nana struct shape_tag { - nana::upoint border; std::shared_ptr> scroll; mutable std::map image_table; tree_cont_type::node_type * first; //The node at the top of screen - int indent_pixels; int offset_x; }shape; @@ -356,7 +355,6 @@ namespace nana data.stop_drawing = false; shape.first = nullptr; - shape.indent_pixels = 10; shape.offset_x = 0; shape.scroll = std::make_shared>(); @@ -451,7 +449,7 @@ namespace nana data.graph->rectangle(true, data.widget_ptr->bgcolor()); //Draw tree - attr.tree_cont.for_each(shape.first, item_rendering_director(this, nana::point(static_cast(attr.tree_cont.indent_size(shape.first) * shape.indent_pixels) - shape.offset_x, margin_top_bottom()))); + attr.tree_cont.for_each(shape.first, item_rendering_director(this, nana::point(static_cast(attr.tree_cont.indent_size(shape.first) * data.scheme_ptr->indent_displacement) - shape.offset_x, margin_top_bottom()))); if (!ignore_update) API::update_window(data.widget_ptr->handle()); @@ -711,7 +709,7 @@ namespace nana case 3: //param is the begin pos of an item in absolute. { - int beg = static_cast(tree.indent_size(node) * shape.indent_pixels) - shape.offset_x; + int beg = static_cast(tree.indent_size(node) * data.scheme_ptr->indent_displacement) - shape.offset_x; int end = beg + static_cast(node_w_pixels(node)); bool take_adjust = false; @@ -910,7 +908,7 @@ namespace nana bool track_mouse(int x, int y) { - int xpos = attr.tree_cont.indent_size(shape.first) * shape.indent_pixels - shape.offset_x; + int xpos = attr.tree_cont.indent_size(shape.first) * data.scheme_ptr->indent_displacement - shape.offset_x; item_locator nl(this, xpos, x, y); attr.tree_cont.template for_each(shape.first, nl); @@ -1449,37 +1447,42 @@ namespace nana if(compset->comp_attribute(component::bground, attr)) { - const ::nana::color color_table[][2] = { { { 0xE8, 0xF5, 0xFD }, { 0xD8, 0xF0, 0xFA } }, //highlighted - { { 0xC4, 0xE8, 0xFA }, { 0xB6, 0xE6, 0xFB } }, //Selected and highlighted - { { 0xD5, 0xEF, 0xFC }, {0x99, 0xDE, 0xFD } } //Selected but not highlighted - }; + auto scheme_ptr = static_cast<::nana::treebox::scheme_type*>(API::dev::get_scheme(window_handle_)); - const ::nana::color *clrptr = nullptr; + const ::nana::color_proxy *bg_ptr = nullptr, *fg_ptr = nullptr; if(compset->item_attribute().mouse_pointed) { if(compset->item_attribute().selected) - clrptr = color_table[1]; + { + bg_ptr = &scheme_ptr->item_bg_selected_and_highlighted; + fg_ptr = &scheme_ptr->item_fg_selected_and_highlighted; + } else - clrptr = color_table[0]; + { + bg_ptr = &scheme_ptr->item_bg_highlighted; + fg_ptr = &scheme_ptr->item_fg_highlighted; + } } else if(compset->item_attribute().selected) - clrptr = color_table[2]; + { + bg_ptr = &scheme_ptr->item_bg_selected; + fg_ptr = &scheme_ptr->item_fg_selected; + } - if (clrptr) + if(bg_ptr) { if (API::is_transparent_background(window_handle_)) { paint::graphics item_graph{ attr.area.dimension() }; - item_graph.rectangle(false, clrptr[1]); - item_graph.rectangle(rectangle{attr.area.dimension()}.pare_off(1), true, *clrptr); - + item_graph.rectangle(false, *fg_ptr); + item_graph.rectangle(rectangle{ attr.area.dimension() }.pare_off(1), true, *bg_ptr); graph.blend(attr.area, item_graph, attr.area.position(), 0.5); } else { - graph.rectangle(attr.area, false, clrptr[1]); - graph.rectangle(attr.area.pare_off(1), true, *clrptr); + graph.rectangle(attr.area, false, *fg_ptr); + graph.rectangle(attr.area.pare_off(1), true, *bg_ptr); } } } @@ -1577,10 +1580,10 @@ namespace nana switch(affect) { case 0: break; - case 1: item_pos_.x += static_cast(node_desc.indent_pixels); break; + case 1: item_pos_.x += static_cast(impl_->data.scheme_ptr->indent_displacement); break; default: if(affect >= 2) - item_pos_.x -= static_cast(node_desc.indent_pixels) * (affect - 1); + item_pos_.x -= static_cast(impl_->data.scheme_ptr->indent_displacement) * (affect - 1); } impl_->assign_node_attr(node_attr_, &node); @@ -1942,7 +1945,8 @@ namespace nana impl_->data.graph = &graph; widget.bgcolor(colors::white); - impl_->data.widget_ptr = static_cast< ::nana::treebox*>(&widget); + impl_->data.widget_ptr = static_cast<::nana::treebox*>(&widget); + impl_->data.scheme_ptr = static_cast<::nana::treebox::scheme_type*>(API::dev::get_scheme(widget)); widget.caption("nana treebox"); } @@ -1961,7 +1965,7 @@ namespace nana { auto & shape = impl_->shape; - int xpos = impl_->attr.tree_cont.indent_size(shape.first) * shape.indent_pixels - shape.offset_x; + int xpos = impl_->attr.tree_cont.indent_size(shape.first) * impl_->data.scheme_ptr->indent_displacement - shape.offset_x; item_locator nl(impl_, xpos, arg.pos.x, arg.pos.y); impl_->attr.tree_cont.for_each(shape.first, nl); @@ -1986,7 +1990,7 @@ namespace nana { auto & shape = impl_->shape; - int xpos = impl_->attr.tree_cont.indent_size(shape.first) * shape.indent_pixels - shape.offset_x; + int xpos = impl_->attr.tree_cont.indent_size(shape.first) * impl_->data.scheme_ptr->indent_displacement - shape.offset_x; item_locator nl(impl_, xpos, arg.pos.x, arg.pos.y); impl_->attr.tree_cont.for_each(shape.first, nl); @@ -2013,7 +2017,7 @@ namespace nana { auto & shape = impl_->shape; - int xpos = impl_->attr.tree_cont.indent_size(shape.first) * shape.indent_pixels - shape.offset_x; + int xpos = impl_->attr.tree_cont.indent_size(shape.first) * impl_->data.scheme_ptr->indent_displacement - shape.offset_x; item_locator nl(impl_, xpos, arg.pos.x, arg.pos.y); impl_->attr.tree_cont.for_each(shape.first, nl); From 91dfaa5d7ecb0e63f052349f438343038cc1706d Mon Sep 17 00:00:00 2001 From: besh81 Date: Mon, 21 Jan 2019 11:37:35 +0100 Subject: [PATCH 2/2] 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"); }