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