In example wxWidgets\samples\notebook\notebook.cpp, I try to set the width, but failed. It always use the internal rectangle to do it.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Closed #25839 as not planned.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
The size of wxBookCtrl in the sample is determined by the sizer that it is in, if you use a standalone wxTreeBook you should be able to set its size just fine.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
After change this lines
to
m_bookctrl = new wxTreeCtrl ( this, id, pos, // wxDefaultPosition, size, // wxDefaultSize, wxBORDER_THEME | wxTR_DEFAULT_STYLE | wxTR_HIDE_ROOT | wxTR_SINGLE );
My demo code works fine.
#include <wx/wx.h> #include <wx/treebook.h> class MyApp : public wxApp { public: bool OnInit() override; }; wxIMPLEMENT_APP(MyApp); class MyFrame : public wxFrame { public: MyFrame(); private: wxTreebook* m_treebook; }; bool MyApp::OnInit() { MyFrame* frame = new MyFrame(); frame->Show(true); return true; } const int TREEBOOK_WIDTH = 250; MyFrame::MyFrame() : wxFrame(nullptr, wxID_ANY, "wxTreebook Demo", wxDefaultPosition, wxSize(800, 600)) { m_treebook = new wxTreebook(this, wxID_ANY, wxDefaultPosition, wxSize(TREEBOOK_WIDTH, 500), wxBK_LEFT); // Node 1 with button wxPanel* page1 = new wxPanel(m_treebook, wxID_ANY); new wxButton(page1, wxID_ANY, "Button 1: Welcome", wxPoint(20, 30)); m_treebook->AddPage(page1, "Node 1"); // Node 2 with button wxPanel* page2 = new wxPanel(m_treebook, wxID_ANY); new wxButton(page2, wxID_ANY, "Button 2: Settings", wxPoint(20, 30)); m_treebook->AddPage(page2, "Node 2"); // Subnode with button wxPanel* subPage = new wxPanel(m_treebook, wxID_ANY); new wxButton(subPage, wxID_ANY, "Subnode Button: More", wxPoint(20, 30)); m_treebook->InsertSubPage(1, subPage, "Subnode"); }
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
So need me make a PR for it?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Are you asking about the size of wxTreeBook (what you wrote) or the size of wxTreeCtrl inside it (what it looks like you meant)?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
The code have used pos and size in wxControl::Create(parent, id, pos, size, ..., but not use them in new wxTreeCtrl(..., so it should apply them also.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
The code have used pos and size in
wxControl::Create(parent, id, pos, size, ..., but not use them innew wxTreeCtrl(..., so it should apply them also.
It obviously shouldn't apply them, using the size of the total control for the size of its child doesn't make sense.
Could you please formulate what problem exactly do you have? This would really help to make this discussion more productive. I think that you want to change the width of the controller control in wxTreeBook, but I'm not sure at all I understand you correctly, so it would be useful to clearly state what the problem is before solving it.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
I just want to be able to customize the width of the tree control, because when users use the wxTreeBook control, the labels of the items in it may be relatively long. If the width of the tree control is fixed, this may cause inconvenience to users when viewing.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Reopened #25839.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Maybe we need to add another variable specifically for recording the width of the tree control?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
OK, this is what I thought (and I've updated the issue title to correspond to the actual problem). And this indeed can't be done now. We could add wxBookCtrlBase::SetControllerSize() and implement it for the book controls for which it makes sense and a PR doing this would indeed be welcome. However it's also wrong that the tree control in your screenshot isn't wide enough to show its items, it's supposed to adjust to them and I don't know why it doesn't happen for you, so there might be another bug here which would need to be reproduced and debugged.
Independently of this there is also #25840 but this is just cosmetic.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
If the tree control can automatically adapt to the text width of its internal nodes, it may be a suitable solution. However, if the text of a node is particularly long, it will be another problem that affects the aesthetics.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Just to be clear, the control is already supposed to adjust the width of the controller to its labels (via GetBestWidth() call), so it would be necessary to understand why it doesn't work for you (it does for me, tested under wxMSW and wxGTK).
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
This is beyond my ability, in fact, I am just getting started with wxWidgets.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Can you at least describe what are you doing to make it come out truncated like this? Just launching the sample and selecting "Treebook" from the "Type" submenu shows the control correctly (not counting the "&" in the label), so I wonder if you're doing something else?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Could it be a version difference? I'm using v3.3.1, not the master branch.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
I don't think anything has changed in this code since quite some time.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
I will run the demo again tomorrow.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
I discovered the root cause of the problem. When the tree control has only one level of items, wxTreeBook behaves as expected. However, when a tree control item has nested subitems, the expanded width of these subitems isn't factored into the calculation of the tree control's optimal width. Therefore, our fix is to improve the GetBestWidth() function.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Here is the other test , I just make the node text long enough, it will looks better.
image.png (view on web)—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Closed #25839 as completed via 471c710.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()