add caption background mode for group

This commit is contained in:
Jinhao 2018-12-29 07:08:49 +08:00
parent bed829fa26
commit 345d65f6c9
2 changed files with 48 additions and 10 deletions

View File

@ -42,6 +42,13 @@ namespace nana{
using field_reference = place::field_reference; using field_reference = place::field_reference;
constexpr static const std::size_t npos = static_cast<std::size_t>(-1); constexpr static const std::size_t npos = static_cast<std::size_t>(-1);
enum class background_mode
{
none,
transparent,
blending
};
/// The default construction /// The default construction
group(); group();
@ -66,7 +73,8 @@ namespace nana{
checkbox& add_option(::std::string); checkbox& add_option(::std::string);
/// Modifies the alignment of the title /// Modifies the alignment of the title
void caption_align(align position); group& caption_align(align position);
group& caption_background_mode(background_mode mode);
/// 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);

View File

@ -36,6 +36,7 @@ namespace nana{
{ {
label caption; label caption;
align caption_align{ align::left }; align caption_align{ align::left };
background_mode caption_mode{ background_mode::blending };
place place_content; place place_content;
unsigned gap{2}; unsigned gap{2};
std::string usr_div_str; std::string usr_div_str;
@ -154,7 +155,7 @@ namespace nana{
return *impl_->options.back(); return *impl_->options.back();
} }
void group::caption_align(align position) group& group::caption_align(align position)
{ {
if (position != impl_->caption_align) if (position != impl_->caption_align)
{ {
@ -163,6 +164,32 @@ namespace nana{
impl_->place_content.collocate(); impl_->place_content.collocate();
API::refresh_window(*this); API::refresh_window(*this);
} }
return *this;
}
group& group::caption_background_mode(background_mode mode)
{
if (mode != impl_->caption_mode)
{
impl_->caption_mode = mode;
switch (mode)
{
case background_mode::none:
impl_->caption.bgcolor(this->bgcolor());
impl_->caption.transparent(false);
break;
case background_mode::blending:
impl_->caption.transparent(true);
impl_->caption.bgcolor(API::bgcolor(this->parent()).blend(colors::black, 0.025));
break;
case background_mode::transparent:
impl_->caption.transparent(true);
impl_->caption.bgcolor(API::bgcolor(this->parent()).blend(colors::black, 0.025));
break;
}
API::refresh_window(*this);
}
return *this;
} }
group& group::radio_mode(bool enable) group& group::radio_mode(bool enable)
@ -289,17 +316,20 @@ namespace nana{
), ),
3, 3, this->scheme().border, true, this->bgcolor()); 3, 3, this->scheme().border, true, this->bgcolor());
auto opt_r = API::window_rectangle(impl_->caption); if (background_mode::blending == impl_->caption_mode)
if (opt_r)
{ {
rectangle grad_r{ opt_r->position(), nana::size{ opt_r->width + 4, static_cast<unsigned>(top_round_line - opt_r->y) } }; auto opt_r = API::window_rectangle(impl_->caption);
if (opt_r)
{
rectangle grad_r{ opt_r->position(), nana::size{ opt_r->width + 4, static_cast<unsigned>(top_round_line - opt_r->y) } };
grad_r.y += top_round_line*2 / 3; grad_r.y += top_round_line * 2 / 3;
grad_r.x -= 2; grad_r.x -= 2;
graph.gradual_rectangle(grad_r, graph.gradual_rectangle(grad_r,
API::bgcolor(this->parent()), this->bgcolor(), true API::bgcolor(this->parent()), this->bgcolor(), true
); );
}
} }
}); });
} }