add query of range for spinbox
This commit is contained in:
parent
40030f7740
commit
0e94346fc1
@ -95,8 +95,11 @@ namespace nana
|
|||||||
void range(double begin, double last, double step);
|
void range(double begin, double last, double step);
|
||||||
|
|
||||||
/// Sets the string spin values.
|
/// Sets the string spin values.
|
||||||
void range(std::initializer_list<std::string> values_utf8);
|
void range(std::vector<std::string> values_utf8);
|
||||||
void range(std::initializer_list<std::wstring> values);
|
|
||||||
|
std::vector<std::string> range_string() const;
|
||||||
|
std::pair<int, int> range_int() const;
|
||||||
|
std::pair<double, double> range_double() const;
|
||||||
|
|
||||||
/// Gets the spined value
|
/// Gets the spined value
|
||||||
::std::string value() const;
|
::std::string value() const;
|
||||||
|
|||||||
@ -54,6 +54,11 @@ namespace nana
|
|||||||
: begin_{ vbegin }, last_{ vlast }, step_{ step }, value_{ vbegin }
|
: begin_{ vbegin }, last_{ vlast }, step_{ step }, value_{ vbegin }
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
std::pair<T, T> range() const
|
||||||
|
{
|
||||||
|
return std::make_pair(begin_, last_);
|
||||||
|
}
|
||||||
|
|
||||||
std::string value() const override
|
std::string value() const override
|
||||||
{
|
{
|
||||||
return std::to_string(value_);
|
return std::to_string(value_);
|
||||||
@ -139,19 +144,14 @@ namespace nana
|
|||||||
: public range_interface
|
: public range_interface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
range_text(std::initializer_list<std::string> & initlist)
|
range_text(std::vector<std::string>&& texts):
|
||||||
: texts_(initlist)
|
texts_(std::move(texts))
|
||||||
{
|
{
|
||||||
for (auto & s : initlist)
|
|
||||||
{
|
|
||||||
texts_.emplace_back(std::string{ s });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
range_text(std::initializer_list<std::wstring>& initlist)
|
const std::vector<std::string>& range() const
|
||||||
{
|
{
|
||||||
for (auto & s : initlist)
|
return texts_;
|
||||||
texts_.emplace_back(to_utf8(s));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string value() const override
|
std::string value() const override
|
||||||
@ -318,6 +318,11 @@ namespace nana
|
|||||||
reset_text();
|
reset_text();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const range_interface* range() const
|
||||||
|
{
|
||||||
|
return range_.get();
|
||||||
|
}
|
||||||
|
|
||||||
void modifier(std::string&& prefix, std::string&& suffix)
|
void modifier(std::string&& prefix, std::string&& suffix)
|
||||||
{
|
{
|
||||||
modifier_.prefix = std::move(prefix);
|
modifier_.prefix = std::move(prefix);
|
||||||
@ -637,18 +642,38 @@ namespace nana
|
|||||||
API::refresh_window(handle());
|
API::refresh_window(handle());
|
||||||
}
|
}
|
||||||
|
|
||||||
void spinbox::range(std::initializer_list<std::string> steps_utf8)
|
void spinbox::range(std::vector<std::string> values)
|
||||||
{
|
{
|
||||||
using namespace drawerbase::spinbox;
|
using namespace drawerbase::spinbox;
|
||||||
get_drawer_trigger().impl()->set_range(std::unique_ptr<range_interface>(new range_text(steps_utf8)));
|
get_drawer_trigger().impl()->set_range(std::unique_ptr<range_interface>(new range_text(std::move(values))));
|
||||||
API::refresh_window(handle());
|
API::refresh_window(handle());
|
||||||
}
|
}
|
||||||
|
|
||||||
void spinbox::range(std::initializer_list<std::wstring> steps)
|
std::vector<std::string> spinbox::range_string() const
|
||||||
{
|
{
|
||||||
using namespace drawerbase::spinbox;
|
auto range = dynamic_cast<const drawerbase::spinbox::range_text*>(get_drawer_trigger().impl()->range());
|
||||||
get_drawer_trigger().impl()->set_range(std::unique_ptr<range_interface>(new range_text(steps)));
|
if (nullptr == range)
|
||||||
API::refresh_window(handle());
|
throw std::runtime_error("the type of spinbox range is not string");
|
||||||
|
|
||||||
|
return range->range();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<int, int> spinbox::range_int() const
|
||||||
|
{
|
||||||
|
auto range = dynamic_cast<const drawerbase::spinbox::range_numeric<int>*>(get_drawer_trigger().impl()->range());
|
||||||
|
if (nullptr == range)
|
||||||
|
throw std::runtime_error("the type of spinbox range is not integer");
|
||||||
|
|
||||||
|
return range->range();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::pair<double, double> spinbox::range_double() const
|
||||||
|
{
|
||||||
|
auto range = dynamic_cast<const drawerbase::spinbox::range_numeric<double>*>(get_drawer_trigger().impl()->range());
|
||||||
|
if (nullptr == range)
|
||||||
|
throw std::runtime_error("the type of spinbox range is not double");
|
||||||
|
|
||||||
|
return range->range();
|
||||||
}
|
}
|
||||||
|
|
||||||
::std::string spinbox::value() const
|
::std::string spinbox::value() const
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user