===== TG classes =====
==== リンク ====
* [[https://root.cern.ch/root/html602/index.html|ROOT Reference Guide]] >> [[https://root.cern.ch/root/html602/GUI_Index.html|GUI]] >> [[https://root.cern.ch/root/html602/GUI_GUI_Index.html|GUI]]
* [[https://root.cern.ch/root/htmldoc/guides/users-guide/WritingGUI.html|Writing GUI]]
==== TGLayoutHints ====
* [[https://root.cern.ch/root/html602/TGLayoutHints.html|TGLayoutHints]](ULong_t hints, Int_t padleft, Int_t padright, Int_t padtop, Int_t padbottom) の padleft, padright, padtop, padbottom は左右上下の padding を px 単位で与える。hints には、配置したい場所を指定する。[[https://root.cern.ch/root/html602/src/TGLayoutManager.h.html#33|TGLayoutManager.h]] で定義される
enum ELayoutHints {
kLHintsNoHints = 0,
kLHintsLeft = BIT(0),
kLHintsCenterX = BIT(1),
kLHintsRight = BIT(2),
kLHintsTop = BIT(3),
kLHintsCenterY = BIT(4),
kLHintsBottom = BIT(5),
kLHintsExpandX = BIT(6),
kLHintsExpandY = BIT(7),
kLHintsNormal = (kLHintsLeft | kLHintsTop)
// bits 8-11 used by ETableLayoutHints
};
から指定する。kLHintsLeft | kLHintsTop | kLHintsExpandY というように、or ビット演算子 | を用いて複数指定できる。BIT は
==== Widget の配置 ====
* widget を縦から配置していく分には、MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) : TGMainFrame(p, w, h) クラス内で
fLbl1 = new TGLabel(this, "Label1");
AddFrame(fLbl1, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
fLbl2 = new TGLabel(this, "Label2");
AddFrame(fLbl2, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
のように書いていけば良い。横に widget を横に並べるには、
TGHorizontalFrame *hframe = new TGHorizontalFrame(this, 300, 20, kFixedWidth);
fLbl1 = new TGLabel(hframe, "Label1");
hframe->AddFrame(fLbl1, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
fLbl2 = new TGLabel(hframe, "Label2");
hframe->AddFrame(fLbl2, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
AddFrame(hframe, new TGLayoutHints(kLHintsExpandX, 10, 10, 2, 2));
のように書く。TGLabel を new するとき、 this ではなく hframe とするので注意。
==== TGFileBrowser ====
* void TGFileBrowser::DoubleClicked(TGListTreeItem *item, Int_t /*btn*/) {} の注意点
* TGFileBrowser の TF2 などのヒストグラム (名前を h4 とする) の TGListTreeItem をダブルクリックしたとき、以下のエラーが出る時がある。
Error: Symbol h4 is not defined in current scope (tmpfile):1:
Error: Failed to evaluate h4->Draw("colz")
*** Interpreter error recovered ***
これは、TGFileBrowser::DoubleClicked の問題と言えるかもしれないが、.root.mimes を
[root/th2]
pattern = TH2[CSFDI]
icon = h2_s.xpm h2_t.xpm
action = ->Draw("colz")
と編集し、さらに現在いるディレクトリからヒストグラム h4 が見えない (すなわち、h4 が違う TFile や TDirectoryFile にいて、現在のディレクトリで gApplication->ProcessLine(act.Data()) (ただし、act.Data() = "h4->Draw(\"colz\");") を実行しても h4 を参照できない) ときに生じるエラーである。(TH2 の action を .root.mimes から gClient->GetMimeTypeList()->GetAction(obj->IsA()->GetName(), action) という関数で取得し、"->Draw()" という文字列が action 内に含まれるかを act.Contains("->Draw()") という関数で判別している。) 解決方法としては、.root.mimes を編集することを諦め、
[root/th2]
pattern = TH2[CSFDI]
icon = h2_s.xpm h2_t.xpm
action = ->Draw()
というようにデフォルトに戻すか、TGListTreeItem をクリックした際に発生する DoubleClick のシグナルをフックし、current directory (gDirectory) を変更し h4 を見えるようにする。必要であれば、TGFileBrowser.cxx を書き換えても良い。もしこれがただのバグであれば、ROOT 開発チームに要望を出す。