Belle II Software development
MultilineWidget Class Reference

Widget which contains the dynamic amount of TGLabel objects. More...

#include <MultilineWidget.h>

Inheritance diagram for MultilineWidget:

Public Member Functions

 MultilineWidget (const TGWindow *p=0, const char *title=0, int line_count=0)
 Create multiline widget with parent window p.
 
int getLineCount ()
 Return number of lines in widget.
 
void setLineCount (int count)
 Add or remove lines depending on current line count.
 
void removeLine (int line_id)
 Remove line with specified id.
 
void removeLastLine ()
 Removes last line from multiline widget and reduces line count.
 
void setLine (int line_id, const char *text)
 Set content of the specified line to 'text'.
 
void addLine (const char *text=0)
 Append line to multiline widget.
 

Private Attributes

std::vector< TGLabel * > lines
 Content of multiline widget.
 

Detailed Description

Widget which contains the dynamic amount of TGLabel objects.

Compared to TGTextView, this class allows to update lines frequently without without redrawing the entire text. There is no internal checks for the correctness of remove operations.

Definition at line 30 of file MultilineWidget.h.

Constructor & Destructor Documentation

◆ MultilineWidget()

MultilineWidget ( const TGWindow *  p = 0,
const char *  title = 0,
int  line_count = 0 
)

Create multiline widget with parent window p.

Definition at line 16 of file MultilineWidget.cc.

17 :
18 TGGroupFrame(p, title)
19{
20 SetLayoutManager(new TGVerticalLayout(this));
21
22 for (int i = 0; i < line_count; i++) {
23 addLine();
24 }
25}
void addLine(const char *text=0)
Append line to multiline widget.

◆ ~MultilineWidget()

~MultilineWidget ( )
virtual

Definition at line 27 of file MultilineWidget.cc.

28{
29 for (unsigned int i = 0; i < lines.size(); i++) {
30 delete lines[i];
31 }
32}
std::vector< TGLabel * > lines
Content of multiline widget.

Member Function Documentation

◆ addLine()

void addLine ( const char *  text = 0)

Append line to multiline widget.

Definition at line 75 of file MultilineWidget.cc.

76{
77 TGLabel* line = new TGLabel(this, text);
78
79 lines.push_back(line);
80 AddFrame(line, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
81 line->Paint();
82}

◆ getLineCount()

int getLineCount ( )

Return number of lines in widget.

Definition at line 34 of file MultilineWidget.cc.

35{
36 return lines.size();
37}

◆ removeLastLine()

void removeLastLine ( )

Removes last line from multiline widget and reduces line count.

Definition at line 62 of file MultilineWidget.cc.

63{
64 removeLine(lines.size() - 1);
65}
void removeLine(int line_id)
Remove line with specified id.

◆ removeLine()

void removeLine ( int  line_id)

Remove line with specified id.

Definition at line 52 of file MultilineWidget.cc.

53{
54 TGLabel* line = lines[line_id];
55
56 RemoveFrame(line);
57 lines.erase(lines.begin() + line_id);
58
59 delete line;
60}

◆ setLine()

void setLine ( int  line_id,
const char *  text 
)

Set content of the specified line to 'text'.

Definition at line 66 of file MultilineWidget.cc.

67{
68 if (line_id >= getLineCount())
69 setLineCount(line_id + 1);
70
71 TGLabel* line = lines[line_id];
72
73 line->SetText(text);
74}
int getLineCount()
Return number of lines in widget.
void setLineCount(int count)
Add or remove lines depending on current line count.

◆ setLineCount()

void setLineCount ( int  count)

Add or remove lines depending on current line count.

If the specified count is less than previous, lines are removed from the bottom of the widget.

Definition at line 39 of file MultilineWidget.cc.

40{
41 int prev_count = getLineCount();
42
43 if (new_count > prev_count) {
44 for (int i = new_count - prev_count; i > 0; i--)
45 addLine();
46 } else {
47 for (int i = prev_count - new_count; i > 0; i--)
48 removeLine(new_count);
49 }
50}

Member Data Documentation

◆ lines

std::vector<TGLabel*> lines
private

Content of multiline widget.

Definition at line 33 of file MultilineWidget.h.


The documentation for this class was generated from the following files: