/* text.hh * This file is part of ndk library * Copyright (c) 2003,2004 by Stanislav Ievlev * * This file is covered by the GNU Library General Public License, * which should be included with libndk as the file COPYING. */ #pragma once #include #include #include namespace ndk { struct color; } namespace ndk { // this is a simple container of the multi-line text struct text : frame { enum possible_events { // system events generated by text widget changed }; enum wrap_type { no_wrap, wrap }; explicit text (std::string const &title = "", panel *parent = 0, wrap_type wrapping = no_wrap); void add_text (color c, std::string const &str); // append text to the buffer void set_text (color c, std::string const &str); // set current text of the buffer, same as clear+add+draw template void add_text (color c, char const *fmt, Args const &...args) { char buf[BUFSIZ]; add_text (c, std::string (buf, snprintf (buf, sizeof buf, fmt, args...))); } bool right (); // move text viewport to the right bool left (); // move text viewport to the left bool up (); // move text viewport to the up bool down (); // move text viewport to the down void clear (); // clear all text int length () const; // total length of the text int last_line () const; // number of the last visible line virtual void resize (int w, int h); private: event::result at_keyboard (const keyboard &ev); virtual void draw (); // draw frame on the panel int string_height (const std::string &str); // number of strings int string_width (const std::string &str); // maximum string length int x_; // first viewport position coordinate int y_; // second viewport position coordinate pad pad_; // internal container for all inner text wrap_type wrapping_; // made or not wrapping of the inner strings }; }