Add the new spinbox widget

This commit is contained in:
cnjinhao
2015-01-22 06:19:24 +08:00
parent 0597d895b4
commit 4ff3a6afd5
22 changed files with 861 additions and 177 deletions

View File

@@ -155,7 +155,7 @@ namespace detail
{
bool enabled :1;
bool dbl_click :1;
bool capture :1; //if mouse button is down, it always receive mouse move even the mouse is out of its rectangle
bool captured :1; //if mouse button is down, it always receive mouse move even the mouse is out of its rectangle
bool modal :1;
bool take_active:1; //If take_active is false, other.active_window still keeps the focus.
bool refreshing :1;

View File

@@ -42,7 +42,7 @@ namespace detail
~bedrock();
void pump_event(window, bool is_modal);
void map_thread_root_buffer(core_window_t* );
void map_thread_root_buffer(core_window_t*, bool forced);
static int inc_window(unsigned tid = 0);
thread_context* open_thread_context(unsigned tid = 0);
thread_context* get_thread_context(unsigned tid = 0);

View File

@@ -110,7 +110,7 @@ namespace nana
void key_char(const arg_keyboard&);
void key_release(const arg_keyboard&);
void shortkey(const arg_keyboard&);
void map(window); //Copy the root buffer to screen
void map(window, bool forced); //Copy the root buffer to screen
void refresh();
drawer_trigger* realizer() const;
void attached(widget&, drawer_trigger&);

View File

@@ -28,7 +28,7 @@ namespace nana{
return 2;
}
bool render(core_window_t * wd)
bool render(core_window_t * wd, bool forced)
{
bool rendered = false;
core_window_t * root_wd = wd->root_widget;
@@ -53,7 +53,7 @@ namespace nana{
rendered = true;
//Avoiding duplicated rendering. If the window is declared to lazy refresh, it should be rendered.
if (!action.rendered || (action.window->other.upd_state == core_window_t::update_state::refresh))
if ((forced && (action.window == wd)) || !action.rendered || (action.window->other.upd_state == core_window_t::update_state::refresh))
{
rd_set.emplace_back(r, action.window);
action.rendered = true;

View File

@@ -150,7 +150,7 @@ namespace detail
core_window_t* root(native_window_type) const;
//Copy the root buffer that wnd specified into DeviceContext
void map(core_window_t*);
void map(core_window_t*, bool forced);
bool update(core_window_t*, bool redraw, bool force);
void refresh_tree(core_window_t*);

View File

@@ -106,6 +106,9 @@ namespace nana
void add_arrow(const std::string&, const pat::cloneable<factory_interface<arrow_interface>>&);
arrow_interface* const * keeper_arrow(const std::string&);
void add_button(const std::string&, const pat::cloneable<factory_interface<element_interface>>&);
element_interface* const* keeper_button(const std::string&);
};
class crook;
@@ -131,6 +134,14 @@ namespace nana
using factory_t = provider::factory<ArrowElement, arrow_interface>;
provider().add_arrow(name, pat::cloneable<typename factory_t::interface_type>(factory_t()));
}
class button;
template<typename ButtonElement>
void add_button(const std::string& name)
{
using factory_t = provider::factory<ButtonElement, element_interface>;
provider().add_button(name, pat::cloneable<typename factory_t::interface_type>(factory_t()));
}
}//end namespace element
template<typename Element> class facade;
@@ -200,6 +211,20 @@ namespace nana
::nana::direction dir_{::nana::direction::north};
};//end class facade<element::arrow>
template<>
class facade<element::button>
: public element::element_interface
{
public:
facade(const char* name = nullptr);
void switch_to(const char*);
public:
//Implement element_interface
bool draw(graph_reference, const ::nana::color& bgcolor, const ::nana::color& fgcolor, const ::nana::rectangle&, element_state) override;
private:
element::element_interface* const * keeper_;
};//end class facade<element::button>
namespace element
{

View File

@@ -45,7 +45,7 @@ namespace nana
void week_name(unsigned index, const nana::string&);
void month_name(unsigned index, const nana::string&);
private:
where _m_pos_where(graph_reference, int x, int y);
where _m_pos_where(graph_reference, const ::nana::point& pos);
void _m_draw(graph_reference);
void _m_draw_topbar(graph_reference);
void _m_make_drawing_basis(drawing_basis&, graph_reference, const nana::point& refpos);

View File

@@ -0,0 +1,78 @@
/*
* A Spin box widget
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* @file: nana/gui/widgets/spanbox.hpp
*/
#ifndef NANA_GUI_WIDGET_SPINBOX_HPP
#define NANA_GUI_WIDGET_SPINBOX_HPP
#include "widget.hpp"
#include "skeletons/text_editor_scheme.hpp"
namespace nana
{
namespace drawerbase
{
namespace spinbox
{
/// Declaration of internal spinbox implementation
class implementation;
/// Drawer of spinbox
class drawer
: public ::nana::drawer_trigger
{
drawer(const drawer&) = delete;
drawer(drawer&&) = delete;
drawer& operator=(const drawer&) = delete;
drawer& operator=(drawer&&) = delete;
public:
drawer();
~drawer();
implementation * impl() const;
private:
//Overrides drawer_trigger
void attached(widget_reference, graph_reference) override;
void refresh(graph_reference) override;
void focus(graph_reference, const arg_focus&) override;
void mouse_wheel(graph_reference, const arg_wheel&) override;
void mouse_down(graph_reference, const arg_mouse&) override;
void mouse_move(graph_reference, const arg_mouse&) override;
void mouse_up(graph_reference, const arg_mouse& arg) override;
void mouse_leave(graph_reference, const arg_mouse&) override;
private:
implementation * const impl_;
};
};
}//end namespace drawerbase
/// Spinbox Widget
class spinbox
: public widget_object <category::widget_tag, drawerbase::spinbox::drawer, ::nana::general_events, ::nana::widgets::skeletons::text_editor_scheme>
{
public:
spinbox();
spinbox(window, bool visible);
spinbox(window, const nana::rectangle& = {}, bool visible = true);
void range(int begin, int last, int step);
void range(double begin, double last, double step);
void range(std::initializer_list<std::string> steps_utf8);
void range(std::initializer_list<std::wstring> steps);
void qualify(std::wstring prefix, std::wstring suffix);
void qualify(const std::string & prefix_utf8, const std::string& suffix_utf8);
private:
::nana::string _m_caption() const;
void _m_caption(::nana::string&&);
};
}//end namespace nana
#endif //NANA_GUI_WIDGET_SPINBOX_HPP