Skip to content

Instantly share code, notes, and snippets.

@petrstepanov
Created April 19, 2019 07:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save petrstepanov/551a286cf6d15d808d0105b6b161f4be to your computer and use it in GitHub Desktop.
TGListBox inside TGCanvas container not shrinks down
#include <TGClient.h>
#include <TGCanvas.h>
#include <TGListBox.h>
#include <TGFrame.h>
class MyMainFrame : public TGMainFrame {
public:
MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
virtual ~MyMainFrame();
ClassDef(MyMainFrame, 0)
};
MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) : TGMainFrame(p, w, h) {
// Create canvas with white background
TGCanvas* canvas = new TGCanvas(this);
TGCompositeFrame* container = new TGCompositeFrame(canvas->GetViewPort(), 10, 10, kOwnBackground);
container->SetBackgroundColor(TColor::Number2Pixel(kGray+1));
canvas->SetContainer(container);
AddFrame(canvas, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandX | kLHintsExpandY, 10, 10, 10, 10));
// Add child ListBox (breaks layout - scrollbars appear when decreasing window size)
TGListBox* listBox = new TGListBox(container);
container->AddFrame(listBox, new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY, 20, 20, 20, 20));
SetWindowName("TGCanvas issue");
SetWMSizeHints(300, 300, 1000, 1000, 1, 1);
MapSubwindows();
Resize(GetDefaultSize());
MapWindow();
}
MyMainFrame::~MyMainFrame(){
Cleanup();
}
void canvasResize(){
new MyMainFrame(gClient->GetRoot(), 300, 300);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment