X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=otk%2Ffocuslabel.cc;h=846d035ebb78de0317161796e1009535b505db32;hb=67fbe8354f27386235e0c8dc57bd036e34a4fe5e;hp=24f3ff52d27bbf60bc9a5869a03e80576e60eb96;hpb=033e9843bcec8340c9e657fe0f0519f86075424b;p=chaz%2Fopenbox diff --git a/otk/focuslabel.cc b/otk/focuslabel.cc index 24f3ff52..846d035e 100644 --- a/otk/focuslabel.cc +++ b/otk/focuslabel.cc @@ -13,6 +13,7 @@ namespace otk { FocusLabel::FocusLabel(Widget *parent) : FocusWidget(parent), _text("") { + setStyle(_style); } FocusLabel::~FocusLabel() @@ -28,13 +29,50 @@ void FocusLabel::setStyle(RenderStyle *style) setUnfocusTexture(style->labelUnfocusBackground()); } +void FocusLabel::fitString(const std::string &str) +{ + const Font *ft = style()->labelFont(); + fitSize(ft->measureString(str), ft->height()); +} -void FocusLabel::renderForeground(void) +void FocusLabel::fitSize(int w, int h) { + unsigned int sidemargin = _bevel_width * 2; + resize(w + sidemargin * 2, h + _bevel_width * 2); +} + +void FocusLabel::update() +{ + if (_dirty) { + int w = _rect.width(), h = _rect.height(); + const Font *ft = style()->labelFont(); + unsigned int sidemargin = _bevel_width * 2; + if (!_fixed_width) + w = ft->measureString(_text) + sidemargin * 2; + if (!_fixed_height) + h = ft->height(); + + // enforce a minimum size + if (w > _rect.width()) { + if (h > _rect.height()) + internalResize(w, h); + else + internalResize(w, _rect.height()); + } else if (h > _rect.height()) + internalResize(_rect.width(), h); + } + FocusWidget::update(); +} + + +void FocusLabel::renderForeground() +{ + FocusWidget::renderForeground(); + const Font *ft = style()->labelFont(); RenderColor *text_color = (isFocused() ? style()->textFocusColor() : style()->textUnfocusColor()); - unsigned int sidemargin = style()->bevelWidth() * 2; + unsigned int sidemargin = _bevel_width * 2; ustring t = _text; // the actual text to draw int x = sidemargin; // x coord for the text @@ -66,7 +104,7 @@ void FocusLabel::renderForeground(void) } display->renderControl(_screen)-> - drawString(*_surface, *ft, x, 0, *text_color, t); + drawString(*_surface, *ft, x, _bevel_width, *text_color, t); } }