add new method for place.splitter renderer
This commit is contained in:
parent
74898dcc01
commit
94bb4103f8
@ -22,6 +22,11 @@
|
|||||||
|
|
||||||
namespace nana
|
namespace nana
|
||||||
{
|
{
|
||||||
|
namespace paint
|
||||||
|
{
|
||||||
|
class graphics;
|
||||||
|
}
|
||||||
|
|
||||||
class widget;
|
class widget;
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
@ -112,6 +117,8 @@ namespace nana
|
|||||||
void bind(window handle);
|
void bind(window handle);
|
||||||
window window_handle() const;
|
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.
|
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.
|
const std::string& div() const noexcept; ///< Returns div-text that depends on fields status.
|
||||||
void modify(const char* field_name, const char* div_text); ///< Modifies a specified field.
|
void modify(const char* field_name, const char* div_text); ///< Modifies a specified field.
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <nana/push_ignore_diagnostic>
|
#include <nana/push_ignore_diagnostic>
|
||||||
#include <nana/deploy.hpp>
|
#include <nana/deploy.hpp>
|
||||||
@ -582,6 +583,9 @@ namespace nana
|
|||||||
std::map<std::string, field_dock*> docks;
|
std::map<std::string, field_dock*> docks;
|
||||||
std::map<std::string, field_dock*> dock_factoris;
|
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
|
//A temporary pointer used to refer to a specified div object which
|
||||||
//will be deleted in modification process.
|
//will be deleted in modification process.
|
||||||
std::unique_ptr<division> tmp_replaced;
|
std::unique_ptr<division> tmp_replaced;
|
||||||
@ -1601,9 +1605,24 @@ namespace nana
|
|||||||
impl_(impl),
|
impl_(impl),
|
||||||
init_weight_(init_weight)
|
init_weight_(init_weight)
|
||||||
{
|
{
|
||||||
|
impl->splitters.insert(this);
|
||||||
|
this->splitter_.set_renderer(impl_->split_renderer);
|
||||||
|
|
||||||
this->weight.assign(splitter_px);
|
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
|
void direction(bool horizontal) noexcept
|
||||||
{
|
{
|
||||||
splitter_cursor_ = (horizontal ? cursor::size_we : cursor::size_ns);
|
splitter_cursor_ = (horizontal ? cursor::size_we : cursor::size_ns);
|
||||||
@ -1943,7 +1962,7 @@ namespace nana
|
|||||||
private:
|
private:
|
||||||
implement* const impl_;
|
implement* const impl_;
|
||||||
nana::cursor splitter_cursor_{nana::cursor::arrow};
|
nana::cursor splitter_cursor_{nana::cursor::arrow};
|
||||||
place_parts::splitter<true> splitter_;
|
place_parts::splitter splitter_;
|
||||||
nana::point begin_point_;
|
nana::point begin_point_;
|
||||||
int left_pos_, right_pos_;
|
int left_pos_, right_pos_;
|
||||||
unsigned left_pixels_, right_pixels_;
|
unsigned left_pixels_, right_pixels_;
|
||||||
@ -2510,8 +2529,7 @@ namespace nana
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto & el : field.second->elements)
|
field.second->visible(is_show);
|
||||||
API::show_window(el.handle, is_show);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3009,6 +3027,14 @@ namespace nana
|
|||||||
return impl_->window_handle;
|
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)
|
void place::div(const char* s)
|
||||||
{
|
{
|
||||||
place_parts::tokenizer tknizer(s);
|
place_parts::tokenizer tknizer(s);
|
||||||
|
@ -29,16 +29,77 @@ namespace nana
|
|||||||
virtual ~splitter_interface(){}
|
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
|
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 splitter_interface
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
void set_renderer(const std::function<void(window, paint::graphics&, mouse_action)>& rd)
|
||||||
|
{
|
||||||
|
get_drawer_trigger().set_renderer(rd);
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
void _m_complete_creation() override
|
void _m_complete_creation() override
|
||||||
{
|
{
|
||||||
this->caption("place-splitter");
|
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