impove slider

This commit is contained in:
Jinhao 2016-05-22 04:31:33 +08:00
parent 6217232a31
commit 5e33bc643f
3 changed files with 481 additions and 366 deletions

View File

@ -44,65 +44,65 @@ namespace nana
bilateral, forward, backward bilateral, forward, backward
}; };
class provider
class renderer_interface
{ {
public: public:
virtual ~provider() = default; using graph_reference = ::nana::paint::graphics&;
virtual std::string adorn_trace(unsigned vmax, unsigned vadorn) const = 0;
struct data_bar
{
bool vert; ///< Indicates whether the slider is vertical.
::nana::rectangle area; ///< Position and size of bar.
unsigned border_weight; ///< The border weight in pixels.
}; };
class renderer struct data_slider
{ {
public: bool vert; ///< Indicates whether the slider is vertical.
typedef ::nana::paint::graphics & graph_reference; double pos;
unsigned border_weight;
struct bar_t unsigned weight;
{
bool horizontal;
nana::rectangle r; //the rectangle of bar.
unsigned border_size; //border_size of bar.
}; };
struct slider_t struct data_adorn
{ {
bool horizontal; bool vert; ///< Indicates whether the slider is vertical.
int pos; ::nana::point bound;
unsigned border;
unsigned scale;
};
struct adorn_t
{
bool horizontal;
nana::point bound;
int fixedpos; int fixedpos;
unsigned block; unsigned block;
unsigned vcur_scale; //pixels of vcur scale. unsigned vcur_scale;
}; };
virtual ~renderer() = default; struct data_vernier
{
bool vert; ///< Indicates whether the slider is vertical.
int position;
int end_position;
unsigned knob_weight;
std::string text;
};
virtual ~renderer_interface() = default;
virtual void background(window, graph_reference, bool isglass) = 0; virtual void background(window, graph_reference, bool isglass) = 0;
virtual void adorn(window, graph_reference, const adorn_t&) = 0; virtual void adorn(window, graph_reference, const data_adorn&) = 0;
virtual void adorn_textbox(window, graph_reference, const ::std::string&, const nana::rectangle&) = 0; virtual void vernier(window, graph_reference, const data_vernier&) = 0;
virtual void bar(window, graph_reference, const bar_t&) = 0; virtual void bar(window, graph_reference, const data_bar&) = 0;
virtual void slider(window, graph_reference, const slider_t&) = 0; virtual void slider(window, graph_reference, mouse_action, const data_slider&) = 0;
}; };
class controller;
class trigger class trigger
: public drawer_trigger : public drawer_trigger
{ {
class model;
public: public:
typedef controller controller_t;
trigger(); trigger();
~trigger(); ~trigger();
controller_t* ctrl() const; model* get_model() const;
private: private:
void attached(widget_reference, graph_reference) override; void attached(widget_reference, graph_reference) override;
void detached() override;
void refresh(graph_reference) override; void refresh(graph_reference) override;
void mouse_down(graph_reference, const arg_mouse&) override; void mouse_down(graph_reference, const arg_mouse&) override;
void mouse_up(graph_reference, const arg_mouse&) override; void mouse_up(graph_reference, const arg_mouse&) override;
@ -110,18 +110,19 @@ namespace nana
void mouse_leave(graph_reference, const arg_mouse&) override; void mouse_leave(graph_reference, const arg_mouse&) override;
void resized(graph_reference, const arg_resized&) override; void resized(graph_reference, const arg_resized&) override;
private: private:
controller_t * impl_; model * model_ptr_;
}; };
}//end namespace slider }//end namespace slider
}//end namespace drawerbase }//end namespace drawerbase
/// A slider widget wich the user can drag for tracking \todo add scheme ? /// A slider widget wich the user can drag for tracking \todo add scheme ?
class slider class slider
: public widget_object<category::widget_tag, drawerbase::slider::trigger, drawerbase::slider::slider_events> : public widget_object<category::widget_tag, drawerbase::slider::trigger, drawerbase::slider::slider_events>
{ {
public: public:
typedef drawerbase::slider::renderer renderer; ///< The interface for user-defined renderer. using renderer_interface = drawerbase::slider::renderer_interface; ///< The interface for customized renderer.
typedef drawerbase::slider::provider provider; ///< The interface for user-defined provider. using seekdir = drawerbase::slider::seekdir; ///< Defines the slider seek direction.
typedef drawerbase::slider::seekdir seekdir; ///< Defines the slider seek direction.
slider(); slider();
slider(window, bool visible); slider(window, bool visible);
@ -130,16 +131,17 @@ namespace nana
void seek(seekdir); ///< Define the direction that user can seek by using mouse. void seek(seekdir); ///< Define the direction that user can seek by using mouse.
void vertical(bool); void vertical(bool);
bool vertical() const; bool vertical() const;
void vmax(unsigned); void maximum(unsigned);
unsigned vmax() const; unsigned maximum() const;
void value(unsigned); void value(unsigned);
unsigned value() const; unsigned value() const;
unsigned move_step(bool forward); ///< Increase or decrease the value of slider. unsigned move_step(bool forward); ///< Increase or decrease the value of slider.
unsigned adorn() const; unsigned adorn() const;
pat::cloneable<renderer>& ext_renderer(); ///< Refers to the current renderer that slider is using. const pat::cloneable<renderer_interface>& renderer(); ///< Refers to the current renderer that slider is using.
void ext_renderer(const pat::cloneable<renderer>&); ///< Set the current renderer. void renderer(const pat::cloneable<renderer_interface>&); ///< Set the current renderer.
void ext_provider(const pat::cloneable<provider>&);
void vernier(std::function<std::string(unsigned maximum, unsigned cursor_value)> provider);
void transparent(bool); void transparent(bool);
bool transparent() const; bool transparent() const;
}; };

View File

@ -72,9 +72,7 @@ namespace nana
typedef compset_interface::item_attribute_t item_attribute_t; typedef compset_interface::item_attribute_t item_attribute_t;
typedef compset_interface::comp_attribute_t comp_attribute_t; typedef compset_interface::comp_attribute_t comp_attribute_t;
virtual ~renderer_interface() virtual ~renderer_interface() = default;
{}
virtual void set_color(const nana::color& bgcolor, const nana::color& fgcolor) = 0; virtual void set_color(const nana::color& bgcolor, const nana::color& fgcolor) = 0;
virtual void bground(graph_reference, const compset_interface *) const = 0; virtual void bground(graph_reference, const compset_interface *) const = 0;

File diff suppressed because it is too large Load Diff