Drawing or cloning new objects.

Workarounds and usability notes.

Drawing or cloning new objects.

Postby John Robin Dove » Tue Jan 20, 2015 6:06 am

Is it possible to create new objects at runtime? I need to create a series of small rectangles each with a unique name and they need to be draggable. I can create objects on an embedded HTML using canvas but they're not draggable and don't have names. I looked for pgClone :D
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Drawing or cloning new objects.

Postby Clifton » Tue Jan 20, 2015 9:12 am

Why not just use several fields, which can be made draggable with createDraggableObject()? Initially they can be left hidden until they are needed in your application. Regarding naming them, just use PowerPac's userProperty() to create unique identifiers for each one that is relevant to your program.

If a rectangle needs a particular size and shape when shown, you could attach a stylesheet using pgExtFiles() and just set the class name of the rectangle from one in the stylesheet before it is shown. In this way you could even include graphics and other special effects and animations too. The userProperty() can set the class name of ToolBook objects and it works very nicely, though sometimes you have to use the "!important" expression in your stylesheet to override ToolBook's inline styles (that is, if you are manipulating one of them).

It is possible to clone objects, but it is unnecessarily complicated and events are lost in cloning. Whatever you are trying to accomplish will probably be more fun and interesting with the approach suggested, rather than doing down the road of cloning.
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: Drawing or cloning new objects.

Postby John Robin Dove » Tue Jan 20, 2015 9:24 am

OK. Thanks I had thought about preparing the objects in advance like this but I don't know exactly how many the user will require. Is there a limit to the number of objects I can 'set aside' to be used if necessary? 50 ... 100?
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: Drawing or cloning new objects.

Postby Clifton » Tue Jan 20, 2015 10:12 am

You should be fine regardless of the number of objects used. Just make sure to use fields, not rectangles because ToolBook will attempt to load a lot of graphics. Fields have very little overhead on the DOM; especially if they are empty (no text).
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 7 guests

cron