-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add block tap listeners #84
Add block tap listeners #84
Conversation
Does this also work in the flyout? I think it should, since that's just another workspace, but want to confirm. This will conflict slightly with my refactor but should be easy to reconcile. |
@rachel-fenichel great question. Right now it only works with the main workspace (Blockly.mainWorkspace.flyout_.workspace_.addTapListener does not appear to work either). I'm not sure why it doesn't work with flyout.workspace - I'm guessing that onMouseUp events aren't fired there. I'm thinking I should extend Blockly.Flyout.prototype.onMouseMoveBlock_ for that purpose, and bubble up the event to targetWorkspace_. In that case I'd like to not pass the block ID but instead pass the block's name. Does this approach make sense to you or would you suggest something different? |
Whether to pass the block name or ID probably depends on how we're doing events in the flyout--that is, how ephemeral those blocks are. If those blocks will be added once and nothing happens to them when their particular tab of the flyout is opened or closed, block ID should work. What's that advantage of using block name? In the flyout targetWorkspace_ is the workspace that blocks will eventually end up in. Unconditionally bubbling that event up is almost certainly going to have weird side effects. For working in the flyout, the block listeners are set here and behaviour depends in part on whether the flyout is closeable. |
@rachel-fenichel Regarding names/IDs: my concern is that a Scratch VM will have no idea what a block ID from the flyout represents. Since Blockly's "create" events only seem to happen for blocks that are not in the flyout, we'll need to do some kind of lookup to tell what the desired operation for the block ID is. However I guess we should keep in mind that eventually we'd like to be editing field values in the flyout, etc., so maybe a lookup is actually most appropriate. Thanks for addBlockListeners_ - to me that verifies that blockMouseDown_ should be where we put a tap event. If we ever have a closeable flyout, I don't think a tappable block in the flyout makes that much sense (as it turns out, that already works because a new block is created and "tapped"). Where do you suggest we send an event instead of bubbling to targetWorkspace_? I'm not immediately thinking of the weird side effects. |
I think you would want to add a mouseUp (like you have in the main The block you would be tapping isn't actually in the target workspace, so That said, I also can't list of specific side effects so maybe it's a Separately, addBlockListeners_ has duplicated listeners, here and in On Wed, Feb 24, 2016 at 12:16 PM Tim Mickel notifications@github.com
|
Ah yes mouseUp definitely! Ok - I'll keep them separated. I'll expose a method on the main workspace that is "addFlyoutTapHandler" or similar. And for now I'll send both the block ID and the block name until we figure out how we want to do editing in the flyout/querying those changes. |
This LGTM but I think @rachel-fenichel may be the more appropriate reviewer. |
I merged my stuff so you now have a small conflict, but lgtm after that. |
Merging with the note that we should move it to Neil's UI event system once he does that. |
…dardized spacer variable (scratchfoundation#84). MenuBar Pass (scratchfoundation#130) * Standardized use of space units where appropriate * Reversed box classes for easier readability in Inspector * Sprite Area: removed unused info button * SpriteSelectorItems: fixed spacing between rows. Isolated layout + component CSS, now reusable in other context. Items per row is now easily configurable * MenuBar: refactored structure for clickable items
This adds listeners to the workspace for detecting when a block is tapped. We can register callbacks with the workspace, and they are called with the block ID and the root block ID (representing the stack). We can then pass this along to our VM/runtime for starting the stack that starts with the root block, or showing data associated with the block in the case of a reporter.
Taps are triggered by the block's mouseup_ (or touchend) events, when the drag hasn't been moved outside the DRAG_RADIUS (i.e., the block hasn't moved).
@rachel-fenichel