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

Behaviors

 
Post new topic   Reply to topic     Forum Index -> flowerd
View previous topic :: View next topic  
Author Message
simhau



Joined: 06 Feb 2007
Posts: 55

PostPosted: Fri Apr 04, 2008 8:01 am    Post subject: Behaviors Reply with quote

I've just checked the examples for htmlayout, and must say I'm thrilled of the possibilities. I'm really looking forward to the wrapped behaviors. Do you have any timeline for this?

Perhaps you could write a tutorial on how to write behaviors in D so other people more easily could help with this effort (I really want the gripper and grid Smile ).

I checked the C++ SDK, and all the behaviors weight in at 4200 lines. It shouldn't be too much trouble porting these (if everything else is ready, that is)
Back to top
View user's profile Send private message
bobef



Joined: 05 Jun 2005
Posts: 269

PostPosted: Fri Apr 04, 2008 11:04 am    Post subject: Reply with quote

I am not planning on porting Andrew's behaviors 1 to 1... Maybe to leech some ideas from them. Ideally HTMLayout for D will become popular, people will make behaviors and share them... Otherwise I will write behaviors when I need them and share them Smile

Anyway, it is really easy to write a behavior in D. You can check htmlayout/behaviors/translatable.d for example. I will explain briefly.

You need to make a new class and inherit from HBehavior.

Code:
class HBehaviorTranslatable : HBehavior
{
   this()
   {
      //this is important! you need unique name for the behavior. you will use it later in your css
      //here you also specify which events your behaviors will handle. see capi.d for list
      super("translatable",HANDLE_INITIALIZATION);
   }
}


Then you override the functions you will handle. HBehavior inherits from HEvent, so take a look at it for the list of functions. For example:

Code:
bool onInit(HInit p)
   {
      if(p.cmd==BEHAVIOR_ATTACH)
      {
         //do something
         return true;
      }
      else
      {
         //do something else
         return true;
      }
   }


You need to create one instance of the behavior to "register" it. I do it in the static constructor and it works fine. Just do it before loading your document (or HTMLayout).

Code:
static this()
{
   new HBehaviorTranslatable;
}


Finally you need to say to HTMLayout which elements will use this behavior. You can do it in your local styles or in the master stylesheet. For example, this will append a rule to the master CSS sheet that will cause every element that has attribute translatable="true" to use the behavior. I.e. onInit will be called for each such element.

Code:
myHLayoutInstance.masterCSS("*[translatable=true] {behavior: translatable;}",true);


Of course you need to import the behavior module somewhere and link it with your program. Sometimes you don't need a behavior to do the task. Just select the elements and handle the appropriate events.

Good luck.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> flowerd 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