Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
buttonTest.C File Reference

Detailed Description

This macro gives an example of how to set/change text button attributes.

To run it do either:

#include <TGButton.h>
#include <TGButtonGroup.h>
#include <TGLabel.h>
#include <TGNumberEntry.h>
#include <TG3DLine.h>
#include <TApplication.h>
//////////// auxilary class ///////////////////////////////////////////////////
class TextMargin : public TGHorizontalFrame {
protected:
TGNumberEntry *fEntry;
public:
TextMargin(const TGWindow *p, const char *name) : TGHorizontalFrame(p)
{
fEntry = new TGNumberEntry(this, 0, 6, -1, TGNumberFormat::kNESInteger);
AddFrame(fEntry, new TGLayoutHints(kLHintsLeft));
TGLabel *label = new TGLabel(this, name);
AddFrame(label, new TGLayoutHints(kLHintsLeft, 10));
}
TGTextEntry *GetEntry() const { return fEntry->GetNumberEntry(); }
};
////////////////////////////////////////////////////////////////////////////////
class ButtonWindow : public TGMainFrame {
protected:
TGTextButton *fButton; // button being tested
public:
void DoLeftMargin(char *);
void DoRightMargin(char *);
void DoTopMargin(char *);
void DoBottomMargin(char *);
};
//______________________________________________________________________________
ButtonWindow::ButtonWindow() : TGMainFrame(gClient->GetRoot(), 10, 10, kHorizontalFrame)
{
// Main test window.
SetCleanup(kDeepCleanup);
// Controls on right
AddFrame(controls, new TGLayoutHints(kLHintsRight | kLHintsExpandY, 5, 5, 5, 5));
// Separator
TGVertical3DLine *separator = new TGVertical3DLine(this);
AddFrame(separator, new TGLayoutHints(kLHintsRight | kLHintsExpandY));
// Contents
TGHorizontalFrame *contents = new TGHorizontalFrame(this);
AddFrame(contents, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5));
// The button for test
fButton = new TGTextButton(contents, "&This button has a multi-line label\nand shows features\n"
"available in the button classes");
fButton->Resize(300, 200);
fButton->ChangeOptions(fButton->GetOptions() | kFixedSize);
fButton->SetToolTipText("The assigned tooltip\ncan be multi-line also", 200);
contents->AddFrame(fButton, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 20, 20, 20, 20));
TGGroupFrame *group = new TGGroupFrame(controls, "Enable/Disable");
TGCheckButton *disable = new TGCheckButton(group, "Switch state\nEnable/Disable");
disable->SetOn();
disable->Connect("Toggled(Bool_t)", "TGButton", fButton, "SetEnabled(Bool_t)");
// control horizontal position of the text
TGButtonGroup *horizontal = new TGButtonGroup(controls, "Horizontal Position");
horizontal->SetButton(kTextCenterX);
horizontal->Connect("Pressed(Int_t)", "ButtonWindow", this, "DoHPosition(Int_t)");
// control vertical position of the text
TGButtonGroup *vertical = new TGButtonGroup(controls, "Vertical Position");
vertical->SetButton(kTextCenterY);
vertical->Connect("Pressed(Int_t)", "ButtonWindow", this, "DoVPosition(Int_t)");
// control margins of the text
TGGroupFrame *margins = new TGGroupFrame(controls, "Text Margins");
TextMargin *left = new TextMargin(margins, "Left");
margins->AddFrame(left, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
left->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow", this, "DoLeftMargin(char*)");
TextMargin *right = new TextMargin(margins, "Right");
margins->AddFrame(right, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
right->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow", this, "DoRightMargin(char*)");
TextMargin *top = new TextMargin(margins, "Top");
margins->AddFrame(top, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
top->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow", this, "DoTopMargin(char*)");
TextMargin *bottom = new TextMargin(margins, "Bottom");
margins->AddFrame(bottom, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
bottom->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow", this, "DoBottomMargin(char*)");
controls->AddFrame(margins, new TGLayoutHints(kLHintsExpandX));
controls->AddFrame(quit, new TGLayoutHints(kLHintsBottom | kLHintsExpandX, 0, 0, 0, 5));
quit->Connect("Pressed()", "TApplication", gApplication, "Terminate()");
Connect("CloseWindow()", "TApplication", gApplication, "Terminate()");
DontCallClose();
Resize();
SetWMSizeHints(GetDefaultWidth(), GetDefaultHeight(), 1000, 1000, 0, 0);
SetWindowName("Button Test");
MapRaised();
}
//______________________________________________________________________________
void ButtonWindow::DoHPosition(Int_t id)
{
// Horizontal position handler.
Int_t tj = fButton->GetTextJustify();
tj |= id;
fButton->SetTextJustify(tj);
}
//______________________________________________________________________________
void ButtonWindow::DoVPosition(Int_t id)
{
// Vertical position handler.
Int_t tj = fButton->GetTextJustify();
tj |= id;
fButton->SetTextJustify(tj);
}
//______________________________________________________________________________
void ButtonWindow::DoLeftMargin(char *val)
{
// Set left text margin.
fButton->SetLeftMargin(atoi(val));
gClient->NeedRedraw(fButton);
}
//______________________________________________________________________________
void ButtonWindow::DoRightMargin(char *val)
{
// Set right text margin.
fButton->SetRightMargin(atoi(val));
gClient->NeedRedraw(fButton);
}
//______________________________________________________________________________
void ButtonWindow::DoTopMargin(char *val)
{
// Set top text margin.
fButton->SetTopMargin(atoi(val));
gClient->NeedRedraw(fButton);
}
//______________________________________________________________________________
void ButtonWindow::DoBottomMargin(char *val)
{
// Set bottom text margin.
fButton->SetBottomMargin(atoi(val));
gClient->NeedRedraw(fButton);
}
////////////////////////////////////////////////////////////////////////////////
void buttonTest()
{
// Main program.
new ButtonWindow();
}
@ kHorizontalFrame
Definition GuiTypes.h:382
@ kFixedSize
Definition GuiTypes.h:390
int Int_t
Definition RtypesCore.h:45
#define ClassDef(name, id)
Definition Rtypes.h:342
R__EXTERN TApplication * gApplication
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gClient
Definition TGClient.h:157
@ kDeepCleanup
Definition TGFrame.h:42
@ kLHintsRight
Definition TGLayout.h:26
@ kLHintsExpandY
Definition TGLayout.h:31
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsCenterY
Definition TGLayout.h:28
@ kLHintsCenterX
Definition TGLayout.h:25
@ kLHintsBottom
Definition TGLayout.h:29
@ kLHintsExpandX
Definition TGLayout.h:30
@ kTextCenterX
Definition TGWidget.h:25
@ kTextLeft
Definition TGWidget.h:23
@ kTextBottom
Definition TGWidget.h:27
@ kTextTop
Definition TGWidget.h:26
@ kTextRight
Definition TGWidget.h:24
@ kTextCenterY
Definition TGWidget.h:28
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t SetWMSizeHints
char name[80]
Definition TGX11.cxx:110
Organizes TGButton widgets in a group.
Selects different options.
Definition TGButton.h:264
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
A composite frame with a border and a title.
Definition TGFrame.h:522
virtual void SetTitlePos(ETitlePos pos=kLeft)
Definition TGFrame.h:564
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:385
This class handles GUI labels.
Definition TGLabel.h:24
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:397
TGNumberEntry is a number entry input widget with up/down buttons.
TGNumberEntryField * GetNumberEntry() const
Get the number entry field.
@ kNESInteger
Style of number entry field.
Selects different options.
Definition TGButton.h:321
Yield an action as soon as it is clicked.
Definition TGButton.h:142
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
A vertical 3D line is a line that can be used to separate groups of widgets.
Definition TG3DLine.h:33
A composite frame that layout their children in vertical way.
Definition TGFrame.h:374
ROOT GUI Window base class.
Definition TGWindow.h:23
Author
Valeriy Onuchin 17/07/2007

Definition in file buttonTest.C.