nana/source/gui/widgets/group.cpp
2015-07-13 04:57:01 +08:00

87 lines
2.2 KiB
C++

/**
* A group widget implementation
* Nana C++ Library(http://www.nanaro.org)
* Copyright(C) 2015 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* @file: nana/gui/widgets/group.cpp
*
* @Author: Stefan Pfeifer(st-321), Ariel Vina-Rodriguez (qPCR4vir)
*
* @brief group is a widget used to visually group and layout other widgets.
*/
#include <nana/gui/widgets/group.hpp>
#include <nana/gui/widgets/label.hpp>
#include <nana/gui/drawing.hpp>
namespace nana{
struct group::implement
{
label caption;
};
group::group( window parent, ///<
std::wstring titel_ /*={}*/, ///<
bool format /*=false*/, ///<
unsigned gap /*=2*/, ///<
rectangle r /*={} */ ///<
)
: panel (parent, r),
impl_(new implement)
{
impl_->caption.create(*this);
impl_->caption.format(format);
::nana::size sz = impl_->caption.measure(1000);
std::stringstream ft;
ft << "vert margin=[0," << gap << "," << gap << "," << gap << "]"
<< " <weight=" << sz.height << " <weight=5> <titel weight=" << sz.width+1 << "> >"
<< " <content>";
plc_outer.div(ft.str().c_str());
plc_outer["titel" ] << impl_->caption;
plc_outer["content"] << content;
plc_outer.collocate();
color pbg = API::bgcolor( parent);
impl_->caption.bgcolor(pbg.blend(colors::black, 0.975) );
color bg=pbg.blend(colors::black, 0.950 );
bgcolor(pbg);
content.bgcolor(bg);
drawing dw(*this);
// This drawing function is owner by the onwer of dw (the outer panel of the group widget), not by dw !!
dw.draw([gap, sz, bg, pbg](paint::graphics& graph)
{
graph.rectangle(true, pbg);
graph.round_rectangle(rectangle(point(gap - 1, sz.height / 2),
nana::size(graph.width() - 2 * (gap - 1), graph.height() - sz.height / 2 - (gap - 1))
),
3, 3, colors::gray_border, true, bg);
});
}
group::~group()
{
}
::nana::string group::_m_caption() const
{
return impl_->caption.caption();
}
void group::_m_caption(::nana::string&& str)
{
return impl_->caption.caption(std::move(str));
}
}//end namespace nana