cwidget
0.5.16
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
cwidget
columnify.h
1
// columnify.h -*-c++-*-
2
//
3
// Copyright 2000, 2005 Daniel Burrows
4
//
5
// This program is free software; you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation; either version 2 of the License, or
8
// (at your option) any later version.
9
//
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU 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; see the file COPYING. If not, write to
17
// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
// Boston, MA 02111-1307, USA.
19
//
20
// Support for creating column-formatted strings. Columns which exceed their
21
// size limit are truncated. Columns are collected into 'groups', each of
22
// which starts at a particular location. This allows things such as
23
// right-justification of text. If one column group overlaps another, the
24
// conflict is resolved by adjusting the column which is situated farthest to
25
// the right (by moving it farther to the right).
26
//
27
// Right-justification is now handled (somewhat hackily) by columnify; to
28
// use it, set the start_off to something negative. The group will be aligned
29
// so the the right edge of the column is start_off+1 characters from the
30
// right-hand screen edge -- so to align something exactly with the right-hand
31
// edge of the screen, set start_off to -1.
32
33
#ifndef COLUMNIFY_H
34
#define COLUMNIFY_H
35
36
#include <list>
37
#include <string>
38
#include <cwidget/generic/util/eassert.h>
39
40
namespace
cwidget
41
{
42
struct
column_disposition
43
{
44
std::wstring text;
// The contents of the columns
45
int
minx;
// The minimum x value to start this column at (useful for
46
// indenting stuff in trees)
47
48
column_disposition
(
const
std::wstring &_text,
int
_minx):text(_text), minx(_minx) {}
49
51
column_disposition
(
const
std::string &_text,
int
_minx,
52
const
char
*encoding=NULL);
53
};
54
55
struct
column
56
{
57
column_disposition
info;
58
int
width;
59
bool
expand, shrink;
60
61
column
(
const
column_disposition
&_info,
int
_width,
bool
_expand,
bool
_shrink)
62
:info(_info), width(_width), expand(_expand), shrink(_shrink)
63
{
64
eassert(_width>=0);
65
}
66
};
67
68
typedef
std::list<column> column_list;
69
70
typedef
std::list<column> layout;
71
72
/* \return a string formatted as requested. The string will be no
73
* wider than width columns. I could probably use printf-style
74
* strings, but with the groups it would probably turn into a major
75
* pain..
76
*/
77
std::wstring columnify(
const
layout &format,
int
width);
78
}
79
80
#endif
Generated on Tue Jun 26 2012 10:39:46 for cwidget by
1.8.1.1