| 1 |
sf-pippijn |
1.1 |
/* text.hh |
| 2 |
|
|
* This file is part of ndk library |
| 3 |
|
|
* Copyright (c) 2003,2004 by Stanislav Ievlev |
| 4 |
|
|
* |
| 5 |
|
|
* This file is covered by the GNU Library General Public License, |
| 6 |
|
|
* which should be included with libndk as the file COPYING. |
| 7 |
|
|
*/ |
| 8 |
|
|
#pragma once |
| 9 |
|
|
|
| 10 |
|
|
#include <ndk/color.hh> |
| 11 |
|
|
#include <ndk/frame.hh> |
| 12 |
|
|
#include <ndk/pad.hh> |
| 13 |
|
|
|
| 14 |
|
|
namespace ndk |
| 15 |
|
|
{ |
| 16 |
|
|
struct color; |
| 17 |
|
|
} |
| 18 |
|
|
|
| 19 |
|
|
namespace ndk |
| 20 |
|
|
{ |
| 21 |
|
|
// this is a simple container of the multi-line text |
| 22 |
|
|
struct text |
| 23 |
|
|
: frame |
| 24 |
|
|
{ |
| 25 |
|
|
enum possible_events |
| 26 |
|
|
{ |
| 27 |
|
|
// system events generated by text widget |
| 28 |
|
|
changed |
| 29 |
|
|
}; |
| 30 |
|
|
|
| 31 |
|
|
enum wrap_type |
| 32 |
|
|
{ |
| 33 |
|
|
no_wrap, |
| 34 |
|
|
wrap |
| 35 |
|
|
}; |
| 36 |
|
|
|
| 37 |
|
|
explicit text (std::string const &title = "", panel *parent = 0, wrap_type wrapping = no_wrap); |
| 38 |
|
|
|
| 39 |
|
|
void add_text (color c, std::string const &str); // append text to the buffer |
| 40 |
|
|
void set_text (color c, std::string const &str); // set current text of the buffer, same as clear+add+draw |
| 41 |
|
|
|
| 42 |
|
|
template<typename... Args> |
| 43 |
|
|
void add_text (color c, char const *fmt, Args const &...args) |
| 44 |
|
|
{ |
| 45 |
|
|
char buf[BUFSIZ]; |
| 46 |
|
|
add_text (c, std::string (buf, snprintf (buf, sizeof buf, fmt, args...))); |
| 47 |
|
|
} |
| 48 |
|
|
|
| 49 |
|
|
bool right (); // move text viewport to the right |
| 50 |
|
|
bool left (); // move text viewport to the left |
| 51 |
|
|
bool up (); // move text viewport to the up |
| 52 |
|
|
bool down (); // move text viewport to the down |
| 53 |
|
|
|
| 54 |
|
|
void clear (); // clear all text |
| 55 |
|
|
|
| 56 |
|
|
int length () const; // total length of the text |
| 57 |
|
|
int last_line () const; // number of the last visible line |
| 58 |
|
|
|
| 59 |
|
|
virtual void resize (int w, int h); |
| 60 |
|
|
|
| 61 |
|
|
private: |
| 62 |
|
|
event::result at_keyboard (const keyboard &ev); |
| 63 |
|
|
|
| 64 |
|
|
virtual void draw (); // draw frame on the panel |
| 65 |
|
|
|
| 66 |
|
|
int string_height (const std::string &str); // number of strings |
| 67 |
|
|
int string_width (const std::string &str); // maximum string length |
| 68 |
|
|
|
| 69 |
|
|
int x_; // first viewport position coordinate |
| 70 |
|
|
int y_; // second viewport position coordinate |
| 71 |
|
|
pad pad_; // internal container for all inner text |
| 72 |
|
|
wrap_type wrapping_; // made or not wrapping of the inner strings |
| 73 |
|
|
}; |
| 74 |
|
|
} |