Page 1 of 1

How to dinamically enable/disable borders?

Posted: Fri Dec 13, 2019 10:52 am
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?

Re: How to dinamically enable/disable borders?

Posted: Fri Dec 13, 2019 10:56 am
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.

Re: How to dinamically enable/disable borders?

Posted: Fri Dec 13, 2019 12:01 pm
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

Re: How to dinamically enable/disable borders?

Posted: Fri Dec 13, 2019 2:10 pm
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.

Re: How to dinamically enable/disable borders?

Posted: Fri Dec 13, 2019 3:07 pm
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...

Re: How to dinamically enable/disable borders?

Posted: Fri Dec 13, 2019 3:24 pm
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

Re: How to dinamically enable/disable borders?

Posted: Fri Dec 13, 2019 4:05 pm
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?

Re: How to dinamically enable/disable borders?

Posted: Fri Dec 13, 2019 4:38 pm
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.

Re: How to dinamically enable/disable borders?

Posted: Fri Dec 13, 2019 4:56 pm
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?

Re: How to dinamically enable/disable borders?

Posted: Fri Dec 13, 2019 5:28 pm
by doublemax
Looks fine to me.