add scheme and caption alignment to group widget.
This commit is contained in:
parent
fc7743cbe2
commit
e47f545b4d
@ -22,8 +22,20 @@
|
|||||||
#include <nana/gui/widgets/checkbox.hpp>
|
#include <nana/gui/widgets/checkbox.hpp>
|
||||||
|
|
||||||
namespace nana{
|
namespace nana{
|
||||||
|
|
||||||
|
namespace drawerbase
|
||||||
|
{
|
||||||
|
namespace group
|
||||||
|
{
|
||||||
|
struct scheme : public nana::widget_geometrics
|
||||||
|
{
|
||||||
|
color_proxy border{ colors::gray_border };
|
||||||
|
};
|
||||||
|
}// end namespace panel
|
||||||
|
}//end namespace drawerbase
|
||||||
|
|
||||||
class group
|
class group
|
||||||
: public panel<true>
|
: public widget_object<category::widget_tag, drawerbase::panel::drawer, general_events, drawerbase::group::scheme>
|
||||||
{
|
{
|
||||||
struct implement;
|
struct implement;
|
||||||
public:
|
public:
|
||||||
@ -53,6 +65,9 @@ namespace nana{
|
|||||||
/// Adds an option for user selection
|
/// Adds an option for user selection
|
||||||
checkbox& add_option(::std::string);
|
checkbox& add_option(::std::string);
|
||||||
|
|
||||||
|
/// Modifies the alignment of the title
|
||||||
|
void caption_align(align position);
|
||||||
|
|
||||||
/// Enables/disables the radio mode which is single selection
|
/// Enables/disables the radio mode which is single selection
|
||||||
group& radio_mode(bool);
|
group& radio_mode(bool);
|
||||||
|
|
||||||
|
|||||||
@ -35,6 +35,7 @@ namespace nana{
|
|||||||
struct group::implement
|
struct group::implement
|
||||||
{
|
{
|
||||||
label caption;
|
label caption;
|
||||||
|
align caption_align{ align::left };
|
||||||
place place_content;
|
place place_content;
|
||||||
unsigned gap{2};
|
unsigned gap{2};
|
||||||
std::string usr_div_str;
|
std::string usr_div_str;
|
||||||
@ -65,10 +66,30 @@ namespace nana{
|
|||||||
|
|
||||||
void update_div()
|
void update_div()
|
||||||
{
|
{
|
||||||
|
const std::size_t padding = 10;
|
||||||
caption_dimension = caption.measure(1000);
|
caption_dimension = caption.measure(1000);
|
||||||
|
caption_dimension.width += 1;
|
||||||
|
|
||||||
std::string div = "vert margin=[0," + std::to_string(gap) + "," + std::to_string(gap + 5) + "," + std::to_string(gap) + "]";
|
std::string div = "vert margin=[0," + std::to_string(gap) + "," + std::to_string(gap + 5) + "," + std::to_string(gap) + "]";
|
||||||
|
#if 0
|
||||||
div += "<weight=" + std::to_string(caption_dimension.height) + " <weight=5><" + field_title + " weight=" + std::to_string(caption_dimension.width + 1) + ">>";
|
div += "<weight=" + std::to_string(caption_dimension.height) + " <weight=5><" + field_title + " weight=" + std::to_string(caption_dimension.width + 1) + ">>";
|
||||||
|
#else
|
||||||
|
div += "<weight=" + std::to_string(caption_dimension.height) + " ";
|
||||||
|
|
||||||
|
if (align::left == caption_align)
|
||||||
|
div += "<weight=" + std::to_string(padding) + ">";
|
||||||
|
else
|
||||||
|
div += "<>"; //right or center
|
||||||
|
|
||||||
|
div += "<" + std::string{ field_title } + " weight=" + std::to_string(caption_dimension.width) + ">";
|
||||||
|
|
||||||
|
if (align::right == caption_align)
|
||||||
|
div += "<weight=" + std::to_string(padding) + ">";
|
||||||
|
else if (align::center == caption_align)
|
||||||
|
div += "<>";
|
||||||
|
|
||||||
|
div += ">";
|
||||||
|
#endif
|
||||||
div += "<<vert margin=5 " + std::string(field_options) + ">";
|
div += "<<vert margin=5 " + std::string(field_options) + ">";
|
||||||
|
|
||||||
if (!usr_div_str.empty())
|
if (!usr_div_str.empty())
|
||||||
@ -97,10 +118,15 @@ namespace nana{
|
|||||||
create(parent, r, vsb);
|
create(parent, r, vsb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using groupbase_type = widget_object<category::widget_tag, drawerbase::panel::drawer, general_events, drawerbase::group::scheme>;
|
||||||
|
|
||||||
group::group(window parent, ::std::string titel, bool formatted, unsigned gap, const rectangle& r, bool vsb)
|
group::group(window parent, ::std::string titel, bool formatted, unsigned gap, const rectangle& r, bool vsb)
|
||||||
: panel(parent, r, vsb),
|
|
||||||
impl_(new implement(*this, std::move(titel), vsb, gap))
|
|
||||||
{
|
{
|
||||||
|
this->create(parent, r, vsb);
|
||||||
|
this->bgcolor(API::bgcolor(parent));
|
||||||
|
|
||||||
|
impl_.reset(new implement(*this, std::move(titel), vsb, gap));
|
||||||
|
|
||||||
impl_->caption.format(formatted);
|
impl_->caption.format(formatted);
|
||||||
_m_init();
|
_m_init();
|
||||||
}
|
}
|
||||||
@ -128,6 +154,17 @@ namespace nana{
|
|||||||
return *impl_->options.back();
|
return *impl_->options.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void group::caption_align(align position)
|
||||||
|
{
|
||||||
|
if (position != impl_->caption_align)
|
||||||
|
{
|
||||||
|
impl_->caption_align = position;
|
||||||
|
impl_->update_div();
|
||||||
|
impl_->place_content.collocate();
|
||||||
|
API::refresh_window(*this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
group& group::radio_mode(bool enable)
|
group& group::radio_mode(bool enable)
|
||||||
{
|
{
|
||||||
_THROW_IF_EMPTY()
|
_THROW_IF_EMPTY()
|
||||||
@ -243,7 +280,7 @@ namespace nana{
|
|||||||
graph.round_rectangle(rectangle(point(gap_px, top_round_line),
|
graph.round_rectangle(rectangle(point(gap_px, top_round_line),
|
||||||
nana::size(graph.width() - 2 * gap_px, graph.height() - top_round_line - gap_px)
|
nana::size(graph.width() - 2 * gap_px, graph.height() - top_round_line - gap_px)
|
||||||
),
|
),
|
||||||
3, 3, colors::gray_border, true, this->bgcolor());
|
3, 3, this->scheme().border, true, this->bgcolor());
|
||||||
|
|
||||||
auto opt_r = API::window_rectangle(impl_->caption);
|
auto opt_r = API::window_rectangle(impl_->caption);
|
||||||
if (opt_r)
|
if (opt_r)
|
||||||
@ -263,11 +300,8 @@ namespace nana{
|
|||||||
|
|
||||||
void group::_m_complete_creation()
|
void group::_m_complete_creation()
|
||||||
{
|
{
|
||||||
panel::_m_complete_creation();
|
widget::_m_complete_creation();
|
||||||
|
|
||||||
impl_->create(handle());
|
impl_->create(handle());
|
||||||
|
|
||||||
|
|
||||||
_m_init();
|
_m_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* A Label Control Implementation
|
* A Label Control Implementation
|
||||||
* Nana C++ Library(http://www.nanapro.org)
|
* Nana C++ Library(http://www.nanapro.org)
|
||||||
* Copyright(C) 2003-208 Jinhao(cnjinhao@hotmail.com)
|
* Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com)
|
||||||
*
|
*
|
||||||
* Distributed under the Boost Software License, Version 1.0.
|
* Distributed under the Boost Software License, Version 1.0.
|
||||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user