Home » Community » Newbie corner » Can a ctrl remove itself?
|
Re: Can a ctrl remove itself? [message #50081 is a reply to message #50080] |
Mon, 16 July 2018 12:11   |
Oblivion
Messages: 1202 Registered: August 2007
|
Senior Contributor |
|
|
Hello Giorgio,
Quote:Is there a way for a ctrl to remove itself?
Yes, you can have a ctrl remove itself, by calling Ctrl::Remove().
E.g.
class Foo : public TopWindow {
Button bt;
public:
Foo() {
SetRect(0,0, 640, 480);
CenterScreen();
bt.SetLabel("Press to remove me!") << [=] { bt.Remove(); };
Add(bt.HCenterPosZ(120).VCenterPosZ(24));
}
};
This works, because:
Quote:
Ctrl Tree
Ultimate++ uses a linked list for all the child Ctrl's that have been Add()ed to it, partaking of its drawing space. The Ctrl does NOT own its children, but simply references them (Ptr<Ctrl>). They should be owned by your application, somewhere in a U++ container, i.e. Array<Label> or they are already made members of your application when using Layout files. If a Ctrl is added to another, it is ensured to be properly removed from its previous parent, thus a Ctrl cant be part of 2 trees.
https://www.ultimatepp.org/srcdoc$CtrlCore$CtrlDesignConcept s_en-us.html
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Mon, 16 July 2018 12:18] Report message to a moderator
|
|
|
|
|
Goto Forum:
Current Time: Sat Apr 26 15:11:50 CEST 2025
Total time taken to generate the page: 0.01181 seconds
|