Skip to content
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

Merged
merged 2 commits into from
Feb 26, 2016
Merged

Add block tap listeners #84

merged 2 commits into from
Feb 26, 2016

Conversation

tmickel
Copy link
Contributor

@tmickel tmickel commented Feb 24, 2016

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

@rachel-fenichel
Copy link
Collaborator

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.

@tmickel
Copy link
Contributor Author

tmickel commented Feb 24, 2016

@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?

@rachel-fenichel
Copy link
Collaborator

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.

@tmickel
Copy link
Contributor Author

tmickel commented Feb 24, 2016

@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.

@rachel-fenichel
Copy link
Collaborator

I think you would want to add a mouseUp (like you have in the main
workspace) instead of doing it on mouseDown_.

The block you would be tapping isn't actually in the target workspace, so
it's a bit concerning to me to send an event through that workspace. I
would almost rather have the tap listener be added on the workspace in the
flyout (even if it's the same tap listener) just to keep them properly
separated.

That said, I also can't list of specific side effects so maybe it's a
nonissue.

Separately, addBlockListeners_ has duplicated listeners, here and in
mainline blockly, which looks like an old mistake.

On Wed, Feb 24, 2016 at 12:16 PM Tim Mickel notifications@github.com
wrote:

@rachel-fenichel https://github.com/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.


Reply to this email directly or view it on GitHub
#84 (comment).

@tmickel
Copy link
Contributor Author

tmickel commented Feb 24, 2016

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.

@rschamp rschamp assigned rachel-fenichel and unassigned rschamp Feb 25, 2016
@rschamp
Copy link
Contributor

rschamp commented Feb 25, 2016

This LGTM but I think @rachel-fenichel may be the more appropriate reviewer.

@rachel-fenichel
Copy link
Collaborator

I merged my stuff so you now have a small conflict, but lgtm after that.

@tmickel
Copy link
Contributor Author

tmickel commented Feb 26, 2016

Merging with the note that we should move it to Neil's UI event system once he does that.

tmickel added a commit that referenced this pull request Feb 26, 2016
@tmickel tmickel merged commit dd087c8 into scratchfoundation:develop Feb 26, 2016
@tmickel tmickel deleted the feature/block-on-tap branch February 26, 2016 18:30
picklesrus pushed a commit to picklesrus/scratch-blocks that referenced this pull request Aug 4, 2017
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants