FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Comparing controls

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
bennygui



Joined: 09 Aug 2007
Posts: 2

PostPosted: Thu Aug 09, 2007 10:11 pm    Post subject: Comparing controls Reply with quote

Hi,

I've been playing with DFL and I've tried implementing some simple layout managers. While doing this, I've encountered a problem when comparing controls to find controls that I've keep.

I've looked around in the DFL code and I think the problem is that when you add a control to a container, the control is not "really" created since it doesn't have an handle yet... Then, when the control is really created and has a handle, a new control is created... And there is no easy way to identify which control is which.

If I try to keep the controls that are added with the "controlAdded()" event (in an array or an associative array for example) and then later I try to change the "location" of those controls, it doesn't work because those controls are not the real controls that are now on the screen...

In the simple cases, I don't have to keep the controls because they are accessible from the "controls()" method... But when I must associate data (like constraints for the layout manager) with the control, I don't know how to do it.

Is there a way to link the control "before it had a handle" with the one that matches after it received a handle?

... Is my question clear enough?

Thanks,

Guillaume
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Fri Aug 10, 2007 12:52 pm    Post subject: Re: Comparing controls Reply with quote

The Control object doesn't change; comparing them should be fine. It's probably best to use the is operator.

I don't understand what's going wrong, so showing some code can be helpful.

Note that DFL 0.9.6 added property Control.hasLayout "Get or set whether or not this control currently has its bounds managed. Fires onHasLayoutChanged as needed.". dock sets and unsets this as necessary, and so can you, to ensure only one piece of code is managing a control's layout.
Back to top
View user's profile Send private message
bennygui



Joined: 09 Aug 2007
Posts: 2

PostPosted: Fri Aug 10, 2007 8:52 pm    Post subject: Re: Comparing controls Reply with quote

Hi,

While writing a small program to prove what I was saying, I saw that I wasn't using the right control in the "controlAdded()" event. I was doing something like this

Code:

void controlAddedEvent(Control sender, ControlEventArgs event) {
  // Wrong: Keep the control "sender"
  this.someMemberArray ~= sender;
}


instead off something like this:

Code:

void controlAddedEvent(Control sender, ControlEventArgs event) {
  // Right: Keep the control "event.control"
  this.someMemberArray ~= event.control;
}


Stupid error... Well, this seems to solve my problems!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group