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 » U++ Library support » U++ Callbacks and Timers » "Suicide Buttons Array" or how to re-index callbacks or...?
"Suicide Buttons Array" or how to re-index callbacks or...? [message #3502] Mon, 29 May 2006 12:08 Go to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Hi, I'm stuck with this piece of code:

#include <CtrlLib/CtrlLib.h>


struct App : TopWindow {
	StaticRect          work;
	Array<Button>       buts;
//change count to change work area width 
static  int const count = 10;
static  int const elw = 40;
static  int const vw=500;
static  int const ww = count*elw+50;
static  int const wh = 290;

	void Suicide(int i){
		//i=GetNewIndex(i);
		buts.Remove(i);
		//ReIndex();
	}

	typedef App CLASSNAME;

	App() {
		work.SetRect(50,50,ww,wh);
		work.Color(SRed);
		Add(work);
		
		for(int i=0;i<=count;i++){
			buts.Add();
			buts[i].SetRect(5+i*elw,20,30,20);
			buts[i].SetLabel(AsString(i));
			work.Add(buts[i]);
			buts[i].WhenAction=callback1(this,Suicide,i);  //incorrect due to lost index!...
		}

	}
};

GUI_APP_MAIN
{
	App().Title("Suicide Buttons Array").Sizeable().Zoomable().Run();
}


My problem is not for buttons ( this code is just visual representation of the problem. I know that I can hide buttons or remove them from parent Ctrl's. And I know that I can arrange remove buttons with "outside management".).
But my problem is something like "how to re-index "suicide" calbacks with dynamic containers".
Or what else can be used in such cases?
(Somehow I feel that my custom index management is not the best case with ntl libraries...)
Any ideas?

[Updated on: Mon, 29 May 2006 12:10]

Report message to a moderator

Re: "Suicide Buttons Array" or how to re-index callbacks or...? [message #3504 is a reply to message #3502] Mon, 29 May 2006 20:01 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
P.S. Or what could be a more effective way than:
	void ReIndex(){
		for(int i=0;i<buts.GetCount();i++){
			buts[i].SetLabel(AsString(i));
			buts[i].WhenAction=callback1(this,Suicide,i);
		}
.S. Or what could be a more effective way than:
void ReIndex(){
for(int i=0;i<buts.GetCount();i++){
buts[i].SetLabel(AsString(i));
buts[i].WhenAction=callback1(this,Suicide,i);
}
every time after removing?
Or maybe to mark them as dead and then to filter actions everywhere else?
Are there any better ways?
Re: "Suicide Buttons Array" or how to re-index callbacks or...? [message #3517 is a reply to message #3504] Tue, 30 May 2006 23:42 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
fudadmin wrote on Mon, 29 May 2006 14:01

P.S. Or what could be a more effective way than:
	void ReIndex(){
		for(int i=0;i<buts.GetCount();i++){
			buts[i].SetLabel(AsString(i));
			buts[i].WhenAction=callback1(this,Suicide,i);
		}
.S. Or what could be a more effective way than:
<CODE]
void ReIndex(){
for(int i=0;i<buts.GetCount();i++){
buts[i].SetLabel(AsString(i));
buts[i].WhenAction=callback1(this,Suicide,i);
}
</CODE
every time after removing?
Or maybe to mark them as dead and then to filter actions everywhere else?
Are there any better ways?




Well, I believe this is not very callback-specific... it is simply the problem of unique identification of item in the array...

Solution depends on what you exactly want to achieve. What you propose is not that bad solution - if you NEED index, I see (at the moment) no other algorithmic way.

Alternative solution would have to introduce another form of unique id per button - e.g. you could post pointer to button instead of index, or you could use UUID and Index....

Mirek
Previous Topic: what KillPostCallback is suppose to do
Next Topic: Question about PostCallback from Child Thread
Goto Forum:
  


Current Time: Fri Mar 29 07:47:34 CET 2024

Total time taken to generate the page: 0.01712 seconds