UNPKG

cloud-blocks

Version:

Cloud Blocks is a library for building scratch computing interfaces with Luxrobo MODI.

105 lines (90 loc) 3.23 kB
/** * @license * Visual Blocks Editor * * Copyright 2017 Google Inc. * https://developers.google.com/blockly/ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @fileoverview Layout code for a vertical variant of the flyout. * @author Sophie */ 'use strict'; goog.provide('Blockly.CengageVerticalFlyout'); /** * overrides position */ /** * Class for a flyout. * @param {!Object} workspaceOptions Dictionary of options for the workspace. * @extends {Blockly.VerticalFlyout} * @constructor */ Blockly.CengageVerticalFlyout = function (workspaceOptions) { Blockly.CengageVerticalFlyout.superClass_.constructor.call( this, workspaceOptions ); this.workspace_ = new Blockly.CengageWorkspaceSvg(workspaceOptions); this.handleColumnResize_ = function (newWidth) { // modify flyout width value this.width_ = newWidth - this.parentToolbox_.HtmlDiv.clientWidth; // subtract category toolbox width this.svgGroup_.setAttribute('width', this.width_); this.svgGroup_.setAttribute('height', this.height_); this.setBackgroundPath_(this.width_, this.height_); // modify scroll position const scrollContentLeft = this.scrollbar_.oldHostMetrics_.contentLeft + 5; this.scrollbar_.setPosition_( this.width_ - scrollContentLeft, this.scrollbar_.position_.y ); this.workspace_.setMetrics({}); }; }; goog.inherits(Blockly.CengageVerticalFlyout, Blockly.VerticalFlyout); /** * Get the width of the flyout. * @return {number} The width of the flyout. */ Blockly.CengageVerticalFlyout.prototype.getWidth = function () { return this.width_ > 0 ? this.width_ : this.DEFAULT_WIDTH; }; Blockly.CengageVerticalFlyout.prototype.wheel_ = function (e) { if (!this.targetWorkspace_.tutorialOn) { // remove scrollTarget to stop auto scrolling in stepScrollAnimation this.scrollTarget = null; var delta = e.deltaY; if (delta) { // Firefox's mouse wheel deltas are a tenth that of Chrome/Safari. // DeltaMode is 1 for a mouse wheel, but not for a trackpad scroll event if (goog.userAgent.GECKO && e.deltaMode === 1) { delta *= 10; } var metrics = this.getMetrics_(); var pos = metrics.viewTop - metrics.contentTop + delta; var limit = metrics.contentHeight - metrics.viewHeight; pos = Math.min(pos, limit); pos = Math.max(pos, 0); this.scrollbar_.set(pos); // When the flyout moves from a wheel event, hide WidgetDiv and DropDownDiv. Blockly.WidgetDiv.hide(true); Blockly.DropDownDiv.hideWithoutAnimation(); } // Don't scroll the page. e.preventDefault(); // Don't propagate mousewheel event (zooming). e.stopPropagation(); } };