add new method for place.splitter renderer
This commit is contained in:
parent
74898dcc01
commit
94bb4103f8
@ -22,6 +22,11 @@
|
||||
|
||||
namespace nana
|
||||
{
|
||||
namespace paint
|
||||
{
|
||||
class graphics;
|
||||
}
|
||||
|
||||
class widget;
|
||||
namespace detail
|
||||
{
|
||||
@ -111,6 +116,8 @@ namespace nana
|
||||
*/
|
||||
void bind(window handle);
|
||||
window window_handle() const;
|
||||
|
||||
void splitter_renderer(std::function<void(window, paint::graphics&, mouse_action)> fn);
|
||||
|
||||
void div(const char* s); ///< Divides the attached widget into fields.
|
||||
const std::string& div() const noexcept; ///< Returns div-text that depends on fields status.
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <cfloat>
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
#include <nana/push_ignore_diagnostic>
|
||||
#include <nana/deploy.hpp>
|
||||
@ -582,6 +583,9 @@ namespace nana
|
||||
std::map<std::string, field_dock*> docks;
|
||||
std::map<std::string, field_dock*> dock_factoris;
|
||||
|
||||
std::function<void(window, paint::graphics&, nana::mouse_action)> split_renderer;
|
||||
std::set<div_splitter*> splitters;
|
||||
|
||||
//A temporary pointer used to refer to a specified div object which
|
||||
//will be deleted in modification process.
|
||||
std::unique_ptr<division> tmp_replaced;
|
||||
@ -1601,9 +1605,24 @@ namespace nana
|
||||
impl_(impl),
|
||||
init_weight_(init_weight)
|
||||
{
|
||||
impl->splitters.insert(this);
|
||||
this->splitter_.set_renderer(impl_->split_renderer);
|
||||
|
||||
this->weight.assign(splitter_px);
|
||||
}
|
||||
|
||||
~div_splitter()
|
||||
{
|
||||
impl_->splitters.erase(this);
|
||||
}
|
||||
|
||||
void set_renderer(const std::function<void(window, paint::graphics&, mouse_action)> & fn, bool update)
|
||||
{
|
||||
this->splitter_.set_renderer(fn);
|
||||
if (update && this->splitter_.handle())
|
||||
API::refresh_window(this->splitter_);
|
||||
}
|
||||
|
||||
void direction(bool horizontal) noexcept
|
||||
{
|
||||
splitter_cursor_ = (horizontal ? cursor::size_we : cursor::size_ns);
|
||||
@ -1943,7 +1962,7 @@ namespace nana
|
||||
private:
|
||||
implement* const impl_;
|
||||
nana::cursor splitter_cursor_{nana::cursor::arrow};
|
||||
place_parts::splitter<true> splitter_;
|
||||
place_parts::splitter splitter_;
|
||||
nana::point begin_point_;
|
||||
int left_pos_, right_pos_;
|
||||
unsigned left_pixels_, right_pixels_;
|
||||
@ -2510,8 +2529,7 @@ namespace nana
|
||||
}
|
||||
}
|
||||
|
||||
for (auto & el : field.second->elements)
|
||||
API::show_window(el.handle, is_show);
|
||||
field.second->visible(is_show);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3009,6 +3027,14 @@ namespace nana
|
||||
return impl_->window_handle;
|
||||
}
|
||||
|
||||
void place::splitter_renderer(std::function<void(window, paint::graphics&, mouse_action)> fn)
|
||||
{
|
||||
impl_->split_renderer.swap(fn);
|
||||
|
||||
for (auto sp : impl_->splitters)
|
||||
sp->set_renderer(impl_->split_renderer, true);
|
||||
}
|
||||
|
||||
void place::div(const char* s)
|
||||
{
|
||||
place_parts::tokenizer tknizer(s);
|
||||
|
@ -29,16 +29,77 @@ namespace nana
|
||||
virtual ~splitter_interface(){}
|
||||
};
|
||||
|
||||
template<bool IsLite>
|
||||
class drawer_splitter
|
||||
: public drawer_trigger
|
||||
{
|
||||
public:
|
||||
void set_renderer(const std::function<void(window, paint::graphics&, mouse_action)>& rd)
|
||||
{
|
||||
renderer_ = rd;
|
||||
}
|
||||
private:
|
||||
void attached(widget_reference wdg, graph_reference) override
|
||||
{
|
||||
window_handle_ = wdg;
|
||||
}
|
||||
|
||||
void refresh(graph_reference graph) override
|
||||
{
|
||||
API::dev::copy_transparent_background(window_handle_, graph);
|
||||
if (renderer_)
|
||||
renderer_(window_handle_, graph, API::mouse_action(window_handle_));
|
||||
}
|
||||
|
||||
void mouse_enter(graph_reference graph, const arg_mouse&) override
|
||||
{
|
||||
refresh(graph);
|
||||
API::dev::lazy_refresh();
|
||||
}
|
||||
|
||||
void mouse_move(graph_reference graph, const arg_mouse&) override
|
||||
{
|
||||
refresh(graph);
|
||||
API::dev::lazy_refresh();
|
||||
}
|
||||
|
||||
void mouse_leave(graph_reference graph, const arg_mouse&) override
|
||||
{
|
||||
refresh(graph);
|
||||
API::dev::lazy_refresh();
|
||||
}
|
||||
|
||||
void mouse_down(graph_reference graph, const arg_mouse&)
|
||||
{
|
||||
refresh(graph);
|
||||
API::dev::lazy_refresh();
|
||||
}
|
||||
|
||||
void mouse_up(graph_reference graph, const arg_mouse&)
|
||||
{
|
||||
refresh(graph);
|
||||
API::dev::lazy_refresh();
|
||||
}
|
||||
private:
|
||||
window window_handle_{nullptr};
|
||||
std::function<void(window, paint::graphics&, mouse_action)> renderer_;
|
||||
};
|
||||
|
||||
class splitter
|
||||
: public widget_object <typename std::conditional<IsLite, category::lite_widget_tag, category::widget_tag>::type, drawer_trigger>,
|
||||
: public widget_object<category::widget_tag, drawer_splitter>,
|
||||
public splitter_interface
|
||||
{
|
||||
public:
|
||||
void set_renderer(const std::function<void(window, paint::graphics&, mouse_action)>& rd)
|
||||
{
|
||||
get_drawer_trigger().set_renderer(rd);
|
||||
}
|
||||
private:
|
||||
void _m_complete_creation() override
|
||||
{
|
||||
this->caption("place-splitter");
|
||||
widget_object <typename std::conditional<IsLite, category::lite_widget_tag, category::widget_tag>::type, drawer_trigger>::_m_complete_creation();
|
||||
widget_object<category::widget_tag, drawer_splitter>::_m_complete_creation();
|
||||
|
||||
API::effects_bground(*this, effects::bground_transparent(0), 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user