Rakonda / jsvectoreditor

Automatically exported from code.google.com/p/jsvectoreditor
0 stars 0 forks source link

Need better events system #10

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I need to hide some page elements (fill/stroke settings) when no shapes are 
selected, and show them accordingly to the shape type when the shape is 
selected.

The second ask is solved well with the "selected" event.
But what touches the unselect/unselected events...

I can set the unselected event and it works well when I unselect some shape 
by clicking somewhere in the canvas. But when the shape is unselected by 
clicking (and selecting) another shape, this event is fired too, and looks 
that it's fired _after_ the select event, as my elements are not visible 
after it.

Original issue reported on code.google.com by emiro...@gmail.com on 5 Jan 2010 at 5:48

GoogleCodeExporter commented 9 years ago
You could constantly poll for editor.selected.length==0 as a hack for the time 
being

Original comment by Antimatter15 on 5 Jan 2010 at 7:25

GoogleCodeExporter commented 9 years ago
Okay, this worked: if (!editor.selected.length && (editor.mode == "select"))

Original comment by emiro...@gmail.com on 5 Jan 2010 at 11:20

GoogleCodeExporter commented 9 years ago
Another related issue (and another argument for the scheme I propose - 2 
events).
When the shape is selected I wish the properties elements to reflect its state 
(colors, etc).
I do it on selected event, setting the selector color to the shape's attribute. 
The 
latter trigs the listener that sets the editor's fill/stroke color.
As the event is fired _before_ the shape is actually selected the following 
occurs:
1) I select some shape
2) The editor fill color is set to its fill color
3) I click on another shape
4) The 1st shape is still selected, but the selected event is fired
5) The event listener gets the 2nd shape as its argument
6) The event listener gets the 2nd shape fill color and sets it to the color 
selector, which trigs the event that globally sets this fill color for the 
editor
7) As the 1st shape is actually selected (from the editor's point of view) the 
latter 
changes causes this 1st shape to get the 2nd shape's fill color

All of this could be probably solved by firing the event after the actual 
selection 
(and any other processing), as I mentioned.
So, repeating myself, the before-event will allow user making validations and 
preventing main processing, while the after-event will allow performing related 
actions.

Original comment by emiro...@gmail.com on 6 Jan 2010 at 12:16

GoogleCodeExporter commented 9 years ago
P.S. As a workaround I have manually put the color in the css background of the 
selector preview element - the action that is automatically done when the text 
element 
value is changed

Original comment by emiro...@gmail.com on 6 Jan 2010 at 12:22