toolbar: show text inside the button
Added function/method both to toolbar and item_proxy: void textout(size_type index, bool show); ///< Show/Hide the text inside the button Before: button without image weren't display Now: button without image is display as empty square. In case the textout is on the text is show
This commit is contained in:
parent
5422c43002
commit
67f5d1743f
@ -55,6 +55,8 @@ namespace nana
|
|||||||
std::string toggle_group() const; ///< Returns the toggle group associated with the tool (only if tool style is toggle).
|
std::string toggle_group() const; ///< Returns the toggle group associated with the tool (only if tool style is toggle).
|
||||||
item_proxy& toggle_group(const ::std::string& group); ///< Adds the tool to a toggle group (only if tool style is toggle).
|
item_proxy& toggle_group(const ::std::string& group); ///< Adds the tool to a toggle group (only if tool style is toggle).
|
||||||
|
|
||||||
|
item_proxy& textout(bool show); ///< Show/Hide the text inside the button
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nana::toolbar* const tb_;
|
nana::toolbar* const tb_;
|
||||||
std::size_t const pos_;
|
std::size_t const pos_;
|
||||||
@ -73,6 +75,8 @@ namespace nana
|
|||||||
bool toggle{ false };
|
bool toggle{ false };
|
||||||
std::string group;
|
std::string group;
|
||||||
|
|
||||||
|
bool textout{ false };
|
||||||
|
|
||||||
item_type(const std::string& text, const nana::paint::image& img, tool_type type)
|
item_type(const std::string& text, const nana::paint::image& img, tool_type type)
|
||||||
:text(text), image(img), type(type)
|
:text(text), image(img), type(type)
|
||||||
{}
|
{}
|
||||||
@ -148,6 +152,8 @@ namespace nana
|
|||||||
std::string toggle_group(size_type index) const; ///< Returns the toggle group associated with the tool (only if tool style is toggle).
|
std::string toggle_group(size_type index) const; ///< Returns the toggle group associated with the tool (only if tool style is toggle).
|
||||||
void toggle_group(size_type index, const ::std::string& group); ///< Adds the tool to a toggle group (only if tool style is toggle).
|
void toggle_group(size_type index, const ::std::string& group); ///< Adds the tool to a toggle group (only if tool style is toggle).
|
||||||
|
|
||||||
|
void textout(size_type index, bool show); ///< Show/Hide the text inside the button
|
||||||
|
|
||||||
void scale(unsigned s); ///< Sets the scale of control button.
|
void scale(unsigned s); ///< Sets the scale of control button.
|
||||||
|
|
||||||
/// Enable to place buttons at right part. After calling it, every new button is right aligned.
|
/// Enable to place buttons at right part. After calling it, every new button is right aligned.
|
||||||
|
@ -156,8 +156,8 @@ namespace nana
|
|||||||
enum class state_t{normal, highlighted, selected};
|
enum class state_t{normal, highlighted, selected};
|
||||||
const static unsigned extra_size = 6;
|
const static unsigned extra_size = 6;
|
||||||
|
|
||||||
item_renderer(nana::paint::graphics& graph, bool textout, unsigned scale, const ::nana::color& bgcolor)
|
item_renderer(nana::paint::graphics& graph, unsigned scale, const ::nana::color& bgcolor, const ::nana::color& fgcolor)
|
||||||
:graph(graph), textout(textout), scale(scale), bgcolor(bgcolor)
|
:graph(graph), scale(scale), bgcolor(bgcolor), fgcolor(fgcolor)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void operator()(int x, int y, unsigned width, unsigned height, item_type& item, state_t state)
|
void operator()(int x, int y, unsigned width, unsigned height, item_type& item, state_t state)
|
||||||
@ -207,17 +207,17 @@ namespace nana
|
|||||||
width -= scale;
|
width -= scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(textout)
|
if(item.textout)
|
||||||
{
|
{
|
||||||
graph.string({ x + static_cast<int>(width - item.textsize.width) / 2, y + static_cast<int>(height - item.textsize.height) / 2 }, item.text);
|
graph.string({ x + static_cast<int>(width - item.textsize.width) / 2, y + static_cast<int>(height - item.textsize.height) / 2 }, item.text, fgcolor );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
nana::paint::graphics& graph;
|
nana::paint::graphics& graph;
|
||||||
bool textout;
|
|
||||||
unsigned scale;
|
unsigned scale;
|
||||||
::nana::color bgcolor;
|
::nana::color bgcolor;
|
||||||
|
::nana::color fgcolor;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct drawer::drawer_impl_type
|
struct drawer::drawer_impl_type
|
||||||
@ -226,7 +226,6 @@ namespace nana
|
|||||||
paint::graphics* graph_ptr{ nullptr };
|
paint::graphics* graph_ptr{ nullptr };
|
||||||
|
|
||||||
unsigned scale{16};
|
unsigned scale{16};
|
||||||
bool textout{false};
|
|
||||||
size_type which{npos};
|
size_type which{npos};
|
||||||
item_renderer::state_t state{item_renderer::state_t::normal};
|
item_renderer::state_t state{item_renderer::state_t::normal};
|
||||||
|
|
||||||
@ -263,10 +262,11 @@ namespace nana
|
|||||||
int x = 2, y = 2;
|
int x = 2, y = 2;
|
||||||
|
|
||||||
auto bgcolor = API::bgcolor(widget_->handle());
|
auto bgcolor = API::bgcolor(widget_->handle());
|
||||||
|
auto fgcolor = API::fgcolor(widget_->handle());
|
||||||
graph.palette(true, bgcolor);
|
graph.palette(true, bgcolor);
|
||||||
graph.gradual_rectangle(rectangle{ graph.size() }, bgcolor.blend(colors::white, 0.1), bgcolor.blend(colors::black, 0.05), true);
|
graph.gradual_rectangle(rectangle{ graph.size() }, bgcolor.blend(colors::white, 0.1), bgcolor.blend(colors::black, 0.05), true);
|
||||||
|
|
||||||
item_renderer ir(graph, impl_->textout, impl_->scale, bgcolor);
|
item_renderer ir(graph, impl_->scale, bgcolor, fgcolor);
|
||||||
size_type index = 0;
|
size_type index = 0;
|
||||||
|
|
||||||
for (auto item : impl_->items.container())
|
for (auto item : impl_->items.container())
|
||||||
@ -449,11 +449,19 @@ namespace nana
|
|||||||
if (item->text.size())
|
if (item->text.size())
|
||||||
item->textsize = impl_->graph_ptr->text_extent_size(item->text);
|
item->textsize = impl_->graph_ptr->text_extent_size(item->text);
|
||||||
|
|
||||||
if (item->image.empty() == false)
|
if(item->image.empty())
|
||||||
|
{
|
||||||
|
if(item->textsize.width && item->textout)
|
||||||
|
item->pixels = item->textsize.width + 8;
|
||||||
|
else
|
||||||
|
item->pixels = impl_->scale + item_renderer::extra_size;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
item->pixels = impl_->scale + item_renderer::extra_size;
|
item->pixels = impl_->scale + item_renderer::extra_size;
|
||||||
|
if(item->textsize.width && item->textout)
|
||||||
if (item->textsize.width && impl_->textout)
|
item->pixels += item->textsize.width + 8;
|
||||||
item->pixels += item->textsize.width + 8;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//class drawer
|
//class drawer
|
||||||
@ -501,6 +509,12 @@ namespace nana
|
|||||||
return tb_->toggle_group(pos_);
|
return tb_->toggle_group(pos_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
item_proxy& item_proxy::textout(bool show)
|
||||||
|
{
|
||||||
|
tb_->textout(pos_, show);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
item_proxy& item_proxy::toggle_group(const ::std::string& group)
|
item_proxy& item_proxy::toggle_group(const ::std::string& group)
|
||||||
{
|
{
|
||||||
tb_->toggle_group(pos_, group);
|
tb_->toggle_group(pos_, group);
|
||||||
@ -654,7 +668,22 @@ namespace nana
|
|||||||
if(m && (m->group != group))
|
if(m && (m->group != group))
|
||||||
{
|
{
|
||||||
m->group = group;
|
m->group = group;
|
||||||
API::refresh_window(this->handle()); //XXX
|
API::refresh_window(this->handle());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void toolbar::textout(size_type index, bool show)
|
||||||
|
{
|
||||||
|
auto & items = get_drawer_trigger().items();
|
||||||
|
|
||||||
|
if(items.size() > index)
|
||||||
|
{
|
||||||
|
auto m = items.at(index);
|
||||||
|
if(m && (m->textout != show))
|
||||||
|
{
|
||||||
|
m->textout = show;
|
||||||
|
API::refresh_window(this->handle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user