diff --git a/include/nana/gui/widgets/toolbar.hpp b/include/nana/gui/widgets/toolbar.hpp index d23efcc6..9b1ce5e3 100644 --- a/include/nana/gui/widgets/toolbar.hpp +++ b/include/nana/gui/widgets/toolbar.hpp @@ -92,6 +92,13 @@ namespace nana bool enable(size_type index) const; void enable(size_type index, bool enable_state); void scale(unsigned s); ///< Sets the scale of control button. + + void go_right(); + + bool detached() { return detached_; }; + + private: + bool detached_; }; }//end namespace nana #endif diff --git a/source/gui/widgets/toolbar.cpp b/source/gui/widgets/toolbar.cpp index c70f34ea..18a3323e 100644 --- a/source/gui/widgets/toolbar.cpp +++ b/source/gui/widgets/toolbar.cpp @@ -34,6 +34,7 @@ namespace nana std::string text; nana::paint::image image; unsigned pixels{0}; + unsigned position{ 0 }; // last item position. nana::size textsize; bool enable{true}; @@ -78,6 +79,16 @@ namespace nana insert(cont_.size(), text, nana::paint::image(), item_type::kind::button); } + void go_right() + { + right_ = cont_.size(); + } + + size_t right() + { + return right_; + } + void insert(size_type pos) { if(pos < cont_.size()) @@ -107,6 +118,7 @@ namespace nana } private: container_type cont_; + size_t right_{ npos }; }; class item_renderer @@ -224,6 +236,7 @@ namespace nana if (item) { _m_calc_pixels(item, false); + item->position = x; ir(x, y, item->pixels, impl_->scale + ir.extra_size, *item, (index == impl_->which ? impl_->state : item_renderer::state_t::normal)); x += item->pixels; } @@ -234,6 +247,20 @@ namespace nana x += 4; } ++index; + if (index == impl_->items.right() && index < impl_->items.size()) + { + int total_x = 0; + for (size_t i = index; i < impl_->items.size(); i++) { + if (impl_->items.at(i) == nullptr) { + total_x += 8; // we assume that separator has width = 8. + } + else { + _m_calc_pixels(impl_->items.at(i), false); + total_x += impl_->items.at(i)->pixels; + } + } + x = graph.size().width - total_x - 4; + } } } @@ -244,6 +271,8 @@ namespace nana widget_ = static_cast< ::nana::toolbar*>(&widget); widget.caption("nana toolbar"); + if (widget_->detached()) return; + impl_->event_size = API::events(widget.parent()).resized.connect_unignorable([this](const arg_resized& arg) { auto wd = widget_->handle(); @@ -399,6 +428,11 @@ namespace nana create(wd, r, visible); } + void toolbar::go_right() + { + get_drawer_trigger().items().go_right(); + } + void toolbar::separate() { get_drawer_trigger().items().separate();