X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=otk%2Flabel.cc;h=8ec03dd9b805b361408d57d306c1983e3864fd99;hb=838f76cd216aaadce186ab5dd4302845d89dd2f8;hp=751fff3421197c55954ef41404f8b1dc611e8ac1;hpb=115fedf432d73f17ade48eaa2fa12dfd333bfcaa;p=chaz%2Fopenbox diff --git a/otk/label.cc b/otk/label.cc index 751fff34..8ec03dd9 100644 --- a/otk/label.cc +++ b/otk/label.cc @@ -10,9 +10,21 @@ namespace otk { +Label::Label(int screen, EventDispatcher *ed, int bevel) + : Widget(screen, ed, Widget::Horizontal, bevel, true), + _text(""), + _font(0), + _justify_horz(RenderStyle::LeftTopJustify), + _justify_vert(RenderStyle::LeftTopJustify), + _highlight(false) +{ + styleChanged(*RenderStyle::style(screen)); +} + Label::Label(Widget *parent) : Widget(parent), _text(""), + _font(0), _justify_horz(RenderStyle::LeftTopJustify), _justify_vert(RenderStyle::LeftTopJustify), _highlight(false) @@ -49,12 +61,20 @@ void Label::setText(const ustring &text) std::string s = text.c_str(); // use a normal string, for its functionality _parsedtext.clear(); + _text = text; // parse it into multiple lines std::string::size_type p = 0; while (p != std::string::npos) { std::string::size_type p2 = s.find('\n', p); - _parsedtext.push_back(s.substr(p, (p2==std::string::npos?p2:p2-p))); + std::string s(s.substr(p, (p2==std::string::npos?p2:p2-p))); + + // turn tabs into spaces (multiples of 8) + std::string::size_type t; + while ((t = s.find('\t')) != std::string::npos) + s.replace(t, 1, std::string(8 - t % 8, ' ')); + + _parsedtext.push_back(s); _parsedtext.back().setUtf8(utf); p = (p2==std::string::npos?p2:p2+1); }