Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Can a ctrl remove itself?
Can a ctrl remove itself? [message #50080] Mon, 16 July 2018 11:54 Go to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Is there a way for a ctrl to remove itself?
Re: Can a ctrl remove itself? [message #50081 is a reply to message #50080] Mon, 16 July 2018 12:11 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1092
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


[Updated on: Mon, 16 July 2018 12:18]

Report message to a moderator

Re: Can a ctrl remove itself? [message #50082 is a reply to message #50081] Mon, 16 July 2018 15:50 Go to previous messageGo to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Thanks!
Re: Can a ctrl remove itself? [message #50094 is a reply to message #50081] Thu, 26 July 2018 10:32 Go to previous message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Good answer Smile

Best regards
IƱaki

[Updated on: Thu, 26 July 2018 10:34]

Report message to a moderator

Previous Topic: Formatting text with percent sign
Next Topic: small issue in CompDir Example
Goto Forum:
  


Current Time: Tue Apr 23 17:43:29 CEST 2024

Total time taken to generate the page: 0.02244 seconds