How to dinamically enable/disable borders? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
Parduz
I live to help wx-kind
I live to help wx-kind
Posts: 188
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

How to dinamically enable/disable borders?

Post by Parduz »

Sorry if this have been already answered, but I google and searched but all i can find is this question and i can't get what it means.

I need to enable or disable some of the borders of a panel (well, a simplenotebook really, but i think it is the same) and i can't find how to access them.

So, suppose that i want to enable the TOP and LEFT borders of myPanel, what should i do?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to dinamically enable/disable borders?

Post by doublemax »

The post you linked talks about borders in the sense of gaps, not visible borders. Which ones do you mean?

For visible borders you can't select individual sides, they're either on or off. (wxBORDER_NONE, wxBORDER_SIMPLE etc.). But even these border flags don't work for all controls.
Use the source, Luke!
User avatar
Parduz
I live to help wx-kind
I live to help wx-kind
Posts: 188
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

Re: How to dinamically enable/disable borders?

Post by Parduz »

doublemax wrote: Fri Dec 13, 2019 10:56 am The post you linked talks about borders in the sense of gaps, not visible borders. Which ones do you mean?
The gaps, specified along alignment, expand etc... You can also specify how much pixel they are.

wxCrafter calls them "sizer flags", and are that "blueish" buttons on this picture:
Image
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to dinamically enable/disable borders?

Post by doublemax »

Like already mentioned in the link you posted, you can't define a border for a single item (like a padding in CSS). You can only define borders when adding an item to a sizer. So i guess you could just have one initial sizer and then add another sizer with the gaps/borders you want and then start adding items in the inner sizer. That should create the same effect.
Use the source, Luke!
User avatar
Parduz
I live to help wx-kind
I live to help wx-kind
Posts: 188
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

Re: How to dinamically enable/disable borders?

Post by Parduz »

If i've right understood, as i'd need to change the borders depending on the page the simplebook is showing, i should:
manage the simplebook pagechange event and there create a new sizer, assign it to the existing parent, and then add the existing simplebook to this new sizer setting the borders as i want.

Questions:
do i have to ... remove the simplebook from his existing sizer?
should i delete the old sizers?
if yes could you pass a short (pseudo)code so i see what i have to manage and how to "transfer" an object from one sizer to another?
what layout() or other resizing/refreshing functions should i call? this part is still so foggy for me...
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to dinamically enable/disable borders?

Post by doublemax »

I've never done that, but looking at the API it should be possible to change the border of an existing sizer. wxSizer::Add returns a wxSizerItem* and there are methods to set border(size) and flags.
https://docs.wxwidgets.org/trunk/classw ... 65ffe639db
https://docs.wxwidgets.org/trunk/classw ... f44a1aadfb
Use the source, Luke!
User avatar
Parduz
I live to help wx-kind
I live to help wx-kind
Posts: 188
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

Re: How to dinamically enable/disable borders?

Post by Parduz »

Sorry to seems pedantic, but i'm struggling with this...


if i have a tree like this:

Code: Select all

mainform
    |
    +---- Sizer1
            |
            +---- Sizer2
            |       |
            |       +---- Panel1
            |
            +---- Sizer3
                    |
                    +---- Panel2
                    |
                    +---- Panel3
how do i get a pointer to Sizer3?
Or
how do i get a pointer to the Panel3 wxSizerItem?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to dinamically enable/disable borders?

Post by doublemax »

how do i get a pointer to Sizer3?
You store it in a member variable when you create it.
ow do i get a pointer to the Panel3 wxSizerItem?
You store the result of the wxSizer::Add() call when you put the panel into its sizer.
Use the source, Luke!
User avatar
Parduz
I live to help wx-kind
I live to help wx-kind
Posts: 188
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

Re: How to dinamically enable/disable borders?

Post by Parduz »

doublemax wrote: Fri Dec 13, 2019 4:38 pm
how do i get a pointer to Sizer3?
You store it in a member variable when you create it.
ow do i get a pointer to the Panel3 wxSizerItem?
You store the result of the wxSizer::Add() call when you put the panel into its sizer.
Well, i "can't" 'cause the creating function is "automated" by wxCrafter, so i should'nt tamper with the generated code.

BUT

seems that this way works:

Code: Select all

        panel3->GetContainingSizer()->GetItem(panel3)->SetFlag(wxLEFT|wxEXPAND);
        panel3->GetParent()->Layout();
        panel3->Refresh();
The first line sets the borders i want
The second one "updates" the panel3 borders and position (without it you don't see any difference)
The third line is there 'cause (in my app) i'm drawing on a child panel and got a bunch of "bitmap not ok" errors, so my guess is that everything inside panel3 needs to be refreshed/resized/recreated.

Do you have any tip/suggestion/warning about this code?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to dinamically enable/disable borders?

Post by doublemax »

Looks fine to me.
Use the source, Luke!
Post Reply