improve inputbox
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* A Message Box Class
|
||||
* Nana C++ Library(http://www.nanapro.org)
|
||||
* Copyright(C) 2003-2013 Jinhao(cnjinhao@hotmail.com)
|
||||
* 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
|
||||
@@ -94,22 +94,133 @@ namespace nana
|
||||
|
||||
class inputbox
|
||||
{
|
||||
public:
|
||||
inputbox(window, ::nana::string description, ::nana::string title = ::nana::string(), ::nana::string label = ::nana::string());
|
||||
struct abstract_content
|
||||
{
|
||||
virtual ~abstract_content() = default;
|
||||
|
||||
void set_modal();
|
||||
bool valid() const;
|
||||
int get_int(int value, int begin, int last, int step);
|
||||
double get_double(double value, double begin, double last, double step);
|
||||
::nana::string get_string();
|
||||
virtual const ::nana::string& label() const = 0;
|
||||
virtual window create(window, unsigned label_px) = 0;
|
||||
virtual unsigned fixed_pixels() const = 0;
|
||||
};
|
||||
public:
|
||||
class integer
|
||||
: public abstract_content
|
||||
{
|
||||
struct implement;
|
||||
public:
|
||||
integer(::nana::string label, int init_value, int begin, int last, int step);
|
||||
~integer();
|
||||
|
||||
int value() const;
|
||||
private:
|
||||
//Implementation of abstract_content
|
||||
const ::nana::string& label() const override;
|
||||
window create(window, unsigned label_px) override;
|
||||
unsigned fixed_pixels() const override;
|
||||
private:
|
||||
std::unique_ptr<implement> impl_;
|
||||
};
|
||||
|
||||
class real
|
||||
: public abstract_content
|
||||
{
|
||||
struct implement;
|
||||
public:
|
||||
real(::nana::string label, double init_value, double begin, double last, double step);
|
||||
~real();
|
||||
|
||||
double value() const;
|
||||
private:
|
||||
//Implementation of abstract_content
|
||||
const ::nana::string& label() const override;
|
||||
window create(window, unsigned label_px) override;
|
||||
unsigned fixed_pixels() const override;
|
||||
private:
|
||||
std::unique_ptr<implement> impl_;
|
||||
};
|
||||
|
||||
class text
|
||||
: public abstract_content
|
||||
{
|
||||
struct implement;
|
||||
public:
|
||||
text(::nana::string label);
|
||||
text(::nana::string label, std::vector<::nana::string>);
|
||||
|
||||
~text();
|
||||
|
||||
::nana::string value() const;
|
||||
private:
|
||||
//Implementation of abstract_content
|
||||
const ::nana::string& label() const override;
|
||||
window create(window, unsigned label_px) override;
|
||||
unsigned fixed_pixels() const override;
|
||||
private:
|
||||
std::unique_ptr<implement> impl_;
|
||||
};
|
||||
|
||||
class date
|
||||
: public abstract_content
|
||||
{
|
||||
struct implement;
|
||||
public:
|
||||
date(::nana::string label);
|
||||
|
||||
~date();
|
||||
|
||||
::nana::string value() const;
|
||||
int year() const;
|
||||
int month() const; //[1, 12]
|
||||
int day() const; //[1, 31]
|
||||
unsigned fixed_pixels() const override;
|
||||
private:
|
||||
//Implementation of abstract_content
|
||||
const ::nana::string& label() const override;
|
||||
window create(window, unsigned label_px) override;
|
||||
private:
|
||||
std::unique_ptr<implement> impl_;
|
||||
};
|
||||
|
||||
inputbox(window, ::nana::string description, ::nana::string title = ::nana::string());
|
||||
|
||||
template<typename ...Args>
|
||||
bool show(Args&& ... args)
|
||||
{
|
||||
std::vector<abstract_content*> contents;
|
||||
_m_fetch_args(contents, std::forward<Args>(args)...);
|
||||
|
||||
if (contents.empty())
|
||||
return false;
|
||||
|
||||
return _m_open(contents, false);
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
bool show_modal(Args&& ... args)
|
||||
{
|
||||
std::vector<abstract_content*> contents;
|
||||
_m_fetch_args(contents, std::forward<Args>(args)...);
|
||||
|
||||
if (contents.empty())
|
||||
return false;
|
||||
|
||||
return _m_open(contents, true);
|
||||
}
|
||||
private:
|
||||
void _m_fetch_args(std::vector<abstract_content*>&);
|
||||
|
||||
template<typename ...Args>
|
||||
void _m_fetch_args(std::vector<abstract_content*>& contents, abstract_content& content, Args&&... args)
|
||||
{
|
||||
contents.push_back(&content);
|
||||
_m_fetch_args(contents, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
bool _m_open(std::vector<abstract_content*>&, bool modal);
|
||||
private:
|
||||
window owner_;
|
||||
bool valid_input_;
|
||||
bool modal_mode_;
|
||||
|
||||
::nana::string description_;
|
||||
::nana::string title_;
|
||||
::nana::string label_;
|
||||
};
|
||||
}//end namespace nana
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* A date chooser Implementation
|
||||
* Nana C++ Library(http://www.nanapro.org)
|
||||
* Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com)
|
||||
* 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
|
||||
@@ -43,7 +43,6 @@ namespace nana
|
||||
bool chose() const;
|
||||
nana::date read() const;
|
||||
void week_name(unsigned index, const nana::string&);
|
||||
void month_name(unsigned index, const nana::string&);
|
||||
private:
|
||||
where _m_pos_where(graph_reference, const ::nana::point& pos);
|
||||
void _m_draw(graph_reference);
|
||||
@@ -64,7 +63,6 @@ namespace nana
|
||||
void mouse_up(graph_reference, const arg_mouse&) override;
|
||||
private:
|
||||
nana::string weekstr_[7];
|
||||
nana::string monthstr_[12];
|
||||
|
||||
widget * widget_;
|
||||
|
||||
@@ -115,7 +113,6 @@ namespace nana
|
||||
bool chose() const;
|
||||
nana::date read() const;
|
||||
void weekstr(unsigned index, const nana::string&);///<Set the week strings which will be displayed for day, index is in range of [0, 6]
|
||||
void monthstr(unsigned index, const nana::string&);///<Set the month strings which will be displayed for month. index is in range of [0, 11]
|
||||
};
|
||||
}//end namespace nana
|
||||
|
||||
|
||||
Reference in New Issue
Block a user