1 // 2 // This file is part of libyacurs. 3 // Copyright (C) 2013 Rafael Ostertag 4 // 5 // This program is free software: you can redistribute it and/or 6 // modify it under the terms of the GNU General Public License as 7 // published by the Free Software Foundation, either version 3 of the 8 // License, or (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, but 11 // WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 // General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program. If not, see 17 // <http://www.gnu.org/licenses/>. 18 // 19 // 20 // $Id$ 21 22 #include <cassert> 23 #include <cstdlib> 24 25 #include "dynlabel.h" 26 #include "yacursex.h" 27 28 using namespace YACURS; 29 30 // 31 // Private 32 // 33 34 // 35 // Protected 36 // 37 38 // 39 // Public 40 // DynLabel(const std::string & l)41DynLabel::DynLabel(const std::string& l) : Label(l) {} 42 ~DynLabel()43DynLabel::~DynLabel() {} 44 label(const std::string & l)45void DynLabel::label(const std::string& l) { 46 _label = l; 47 48 if (realization() == REALIZED) refresh(true); 49 } 50 label() const51const std::string& DynLabel::label() const { return _label; } 52 size_available(const Size & s)53void DynLabel::size_available(const Size& s) { 54 assert(s.rows() > 0); 55 WidgetBase::size_available(s); 56 _size = Size(1, s.cols()); 57 } 58 size_hint() const59Size DynLabel::size_hint() const { return Size(1, 0); } 60 reset_size()61void DynLabel::reset_size() { _size = Size::zero(); } 62 refresh(bool immediate)63void DynLabel::refresh(bool immediate) { 64 if (realization() != REALIZED && realization() != REALIZING) return; 65 66 assert(widget_subwin() != 0); 67 68 // Make sure there are no left overs in case of text being set by 69 // a call to label() case we're realized. 70 71 widget_subwin()->erase(); 72 CurStr tmp(_label, Coordinates(), color()); 73 widget_subwin()->addstrx(tmp); 74 75 Widget::refresh(immediate); 76 } 77