add checkbox function for group
This commit is contained in:
parent
9940e2883e
commit
51f9e87979
@ -36,11 +36,11 @@ namespace nana{
|
|||||||
|
|
||||||
/// The construction that creates the widget and set the titel or caption
|
/// The construction that creates the widget and set the titel or caption
|
||||||
|
|
||||||
group(window parent, ///<
|
group(window parent, ///< a handle to the parent
|
||||||
::nana::string titel, ///<
|
::nana::string titel, ///< caption of the group
|
||||||
bool format = false, ///< Use a formated label?
|
bool formatted = false, ///< Enable/disable the formatted text for the title
|
||||||
unsigned gap = 2, ///< betwen the content and the external limit
|
unsigned gap = 2, ///< betwen the content and the external limit
|
||||||
rectangle r = {} , ///<
|
const rectangle& r = {} ,
|
||||||
bool visible = true
|
bool visible = true
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -48,6 +48,18 @@ namespace nana{
|
|||||||
/// The destruction
|
/// The destruction
|
||||||
~group();
|
~group();
|
||||||
|
|
||||||
|
/// Adds an option for user selection
|
||||||
|
void add_option(::nana::string);
|
||||||
|
|
||||||
|
/// Enables/disables the radio mode which is single selection
|
||||||
|
void radio_mode(bool);
|
||||||
|
|
||||||
|
/// Returns the index of option in radio_mode, it throws a logic_error if radio_mode is false.
|
||||||
|
std::size_t option() const;
|
||||||
|
|
||||||
|
/// Determines a specified option is checked, it throws an out_of_range if !(pos < number of options)
|
||||||
|
bool option_checked(std::size_t pos) const;
|
||||||
|
|
||||||
group& enable_format_caption(bool format);
|
group& enable_format_caption(bool format);
|
||||||
|
|
||||||
|
|
||||||
@ -57,7 +69,6 @@ namespace nana{
|
|||||||
void div(const char* div_str);
|
void div(const char* div_str);
|
||||||
field_reference operator[](const char* field);
|
field_reference operator[](const char* field);
|
||||||
|
|
||||||
|
|
||||||
template<typename Widget, typename ...Args>
|
template<typename Widget, typename ...Args>
|
||||||
Widget* create_child(const char* field, Args && ... args)
|
Widget* create_child(const char* field, Args && ... args)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -185,6 +185,7 @@ namespace checkbox
|
|||||||
void checkbox::radio(bool is_radio)
|
void checkbox::radio(bool is_radio)
|
||||||
{
|
{
|
||||||
get_drawer_trigger().impl()->crook.radio(is_radio);
|
get_drawer_trigger().impl()->crook.radio(is_radio);
|
||||||
|
API::refresh_window(handle());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkbox::transparent(bool enabled)
|
void checkbox::transparent(bool enabled)
|
||||||
@ -193,6 +194,7 @@ namespace checkbox
|
|||||||
API::effects_bground(*this, effects::bground_transparent(0), 0.0);
|
API::effects_bground(*this, effects::bground_transparent(0), 0.0);
|
||||||
else
|
else
|
||||||
API::effects_bground_remove(*this);
|
API::effects_bground_remove(*this);
|
||||||
|
API::refresh_window(handle());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool checkbox::transparent() const
|
bool checkbox::transparent() const
|
||||||
@ -204,10 +206,12 @@ namespace checkbox
|
|||||||
//class radio_group
|
//class radio_group
|
||||||
radio_group::~radio_group()
|
radio_group::~radio_group()
|
||||||
{
|
{
|
||||||
for(auto & i : ui_container_)
|
for(auto & e : ui_container_)
|
||||||
{
|
{
|
||||||
API::umake_event(i.eh_checked);
|
e.uiobj->radio(false);
|
||||||
API::umake_event(i.eh_destroy);
|
e.uiobj->react(true);
|
||||||
|
API::umake_event(e.eh_checked);
|
||||||
|
API::umake_event(e.eh_destroy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,18 +18,29 @@
|
|||||||
#include <nana/gui/widgets/group.hpp>
|
#include <nana/gui/widgets/group.hpp>
|
||||||
#include <nana/gui/widgets/label.hpp>
|
#include <nana/gui/widgets/label.hpp>
|
||||||
#include <nana/gui/drawing.hpp>
|
#include <nana/gui/drawing.hpp>
|
||||||
|
#include <nana/gui/widgets/checkbox.hpp>
|
||||||
|
|
||||||
|
#define _THROW_IF_EMPTY()\
|
||||||
|
if(empty()) \
|
||||||
|
throw std::logic_error("the group is invalid");
|
||||||
|
|
||||||
namespace nana{
|
namespace nana{
|
||||||
|
|
||||||
|
static const char* field_title = "__nana_group_title__";
|
||||||
|
static const char* field_options = "__nana_group_options__";
|
||||||
|
|
||||||
struct group::implement
|
struct group::implement
|
||||||
{
|
{
|
||||||
label caption;
|
label caption;
|
||||||
place place_content;
|
place place_content;
|
||||||
|
|
||||||
unsigned gap{2};
|
unsigned gap{2};
|
||||||
|
std::string usr_div_str;
|
||||||
|
|
||||||
|
std::vector<std::unique_ptr<checkbox>> options;
|
||||||
|
radio_group * radio_logic{nullptr};
|
||||||
|
|
||||||
implement() = default;
|
implement() = default;
|
||||||
|
|
||||||
implement(window grp_panel, ::nana::string titel, bool vsb, unsigned gap=2)
|
implement(window grp_panel, ::nana::string titel, bool vsb, unsigned gap=2)
|
||||||
: caption (grp_panel, std::move(titel), vsb),
|
: caption (grp_panel, std::move(titel), vsb),
|
||||||
place_content{grp_panel},
|
place_content{grp_panel},
|
||||||
@ -43,6 +54,26 @@ namespace nana{
|
|||||||
caption.caption(STR(""));
|
caption.caption(STR(""));
|
||||||
place_content.bind(pnl);
|
place_content.bind(pnl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void update_div()
|
||||||
|
{
|
||||||
|
::nana::size sz = caption.measure(1000);
|
||||||
|
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "vert margin=[0," << gap << "," << gap + 5 << "," << gap << "]"
|
||||||
|
<< " <weight=" << sz.height << " <weight=5> <" << field_title << " weight=" << sz.width + 1 << "> >"
|
||||||
|
<< "<<vert margin=5 " << field_options << ">";
|
||||||
|
|
||||||
|
if (!usr_div_str.empty())
|
||||||
|
ss << "<" << usr_div_str << ">>";
|
||||||
|
else
|
||||||
|
ss << ">";
|
||||||
|
|
||||||
|
place_content.div(ss.str().c_str());
|
||||||
|
|
||||||
|
if (options.empty())
|
||||||
|
place_content.field_display(field_options, false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
group::group()
|
group::group()
|
||||||
@ -56,23 +87,68 @@ namespace nana{
|
|||||||
create(parent, r, vsb);
|
create(parent, r, vsb);
|
||||||
}
|
}
|
||||||
|
|
||||||
group::group( window parent, ///<
|
group::group(window parent, ::nana::string titel, bool formatted, unsigned gap, const rectangle& r, bool vsb)
|
||||||
::nana::string titel /*={}*/, ///<
|
|
||||||
bool format /*=false*/, ///<
|
|
||||||
unsigned gap /*=2*/, ///<
|
|
||||||
rectangle r /*={} */, ///<
|
|
||||||
bool vsb /*= true */ ///<
|
|
||||||
)
|
|
||||||
: panel(parent, r, vsb),
|
: panel(parent, r, vsb),
|
||||||
impl_(new implement(*this, std::move(titel), vsb, gap))
|
impl_(new implement(*this, std::move(titel), vsb, gap))
|
||||||
{
|
{
|
||||||
impl_->caption.format(format);
|
impl_->caption.format(formatted);
|
||||||
_m_init();
|
_m_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
group::~group()
|
group::~group()
|
||||||
{
|
{
|
||||||
|
delete impl_->radio_logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
void group::add_option(::nana::string text)
|
||||||
|
{
|
||||||
|
_THROW_IF_EMPTY()
|
||||||
|
|
||||||
|
impl_->options.emplace_back(new checkbox(handle()));
|
||||||
|
auto & opt = impl_->options.back();
|
||||||
|
opt->transparent(true);
|
||||||
|
opt->caption(std::move(text));
|
||||||
|
impl_->place_content[field_options] << *opt;
|
||||||
|
impl_->place_content.field_display(field_options, true);
|
||||||
|
impl_->place_content.collocate();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void group::radio_mode(bool enable)
|
||||||
|
{
|
||||||
|
_THROW_IF_EMPTY()
|
||||||
|
|
||||||
|
if (enable)
|
||||||
|
{
|
||||||
|
//Create radio_group if it is null
|
||||||
|
if (!impl_->radio_logic)
|
||||||
|
impl_->radio_logic = new ::nana::radio_group;
|
||||||
|
|
||||||
|
//add all options into the radio_group
|
||||||
|
for (auto & opt : impl_->options)
|
||||||
|
impl_->radio_logic->add(*opt);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
delete impl_->radio_logic;
|
||||||
|
impl_->radio_logic = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t group::option() const
|
||||||
|
{
|
||||||
|
_THROW_IF_EMPTY();
|
||||||
|
|
||||||
|
if (impl_->radio_logic)
|
||||||
|
return impl_->radio_logic->checked();
|
||||||
|
|
||||||
|
throw std::logic_error("the radio_mode of the group is disabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool group::option_checked(std::size_t pos) const
|
||||||
|
{
|
||||||
|
_THROW_IF_EMPTY();
|
||||||
|
return impl_->options.at(pos)->checked();
|
||||||
}
|
}
|
||||||
|
|
||||||
group& group::enable_format_caption(bool format)
|
group& group::enable_format_caption(bool format)
|
||||||
@ -86,7 +162,6 @@ namespace nana{
|
|||||||
return impl_->place_content;
|
return impl_->place_content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void group::collocate()
|
void group::collocate()
|
||||||
{
|
{
|
||||||
impl_->place_content.collocate();
|
impl_->place_content.collocate();
|
||||||
@ -96,13 +171,12 @@ namespace nana{
|
|||||||
{
|
{
|
||||||
::nana::size sz = impl_->caption.measure(1000);
|
::nana::size sz = impl_->caption.measure(1000);
|
||||||
|
|
||||||
std::stringstream ss;
|
if (div_str)
|
||||||
ss << "vert margin=[0," << impl_->gap << "," << impl_->gap << "," << impl_->gap << "]"
|
impl_->usr_div_str = div_str;
|
||||||
<< " <weight=" << sz.height << " <weight=5> <nanaGroupTitle2015 weight=" << sz.width + 1 << "> >"
|
else
|
||||||
<< " <"<<(div_str ? div_str : "")<<">";
|
impl_->usr_div_str.clear();
|
||||||
|
|
||||||
impl_->place_content.div(ss.str().c_str());
|
|
||||||
|
|
||||||
|
impl_->update_div();
|
||||||
}
|
}
|
||||||
|
|
||||||
group::field_reference group::operator[](const char* field)
|
group::field_reference group::operator[](const char* field)
|
||||||
@ -121,7 +195,7 @@ namespace nana{
|
|||||||
|
|
||||||
auto & outter = impl_->place_content;
|
auto & outter = impl_->place_content;
|
||||||
|
|
||||||
outter["nanaGroupTitle2015"] << impl_->caption;
|
outter[field_title] << impl_->caption;
|
||||||
outter.collocate();
|
outter.collocate();
|
||||||
|
|
||||||
color pbg = API::bgcolor(this->parent());
|
color pbg = API::bgcolor(this->parent());
|
||||||
@ -164,7 +238,8 @@ namespace nana{
|
|||||||
|
|
||||||
void group::_m_caption(::nana::string&& str)
|
void group::_m_caption(::nana::string&& str)
|
||||||
{
|
{
|
||||||
return impl_->caption.caption(std::move(str));
|
impl_->caption.caption(std::move(str));
|
||||||
|
impl_->update_div();
|
||||||
}
|
}
|
||||||
}//end namespace nana
|
}//end namespace nana
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user