Support enabling start hats from themes (#3722)

* Support themes configuring the start hats of blocks. Add test themes
This commit is contained in:
Sam El-Husseini
2020-03-05 17:34:31 -08:00
committed by GitHub
parent 8c5c33902b
commit 21763b7e00
6 changed files with 103 additions and 4 deletions

View File

@@ -0,0 +1,62 @@
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
'use strict';
goog.provide('Blockly.TestThemes');
/**
* A theme with classic colours but enables start hats.
*/
Blockly.Themes.TestHats = new Blockly.Theme('testhats',
Blockly.Themes.Classic.blockStyles, Blockly.Themes.Classic.categoryStyles);
Blockly.Themes.TestHats.setStartHats(true);
/**
* A theme with classic colours but a different font.
*/
Blockly.Themes.TestFont = new Blockly.Theme('testfont',
Blockly.Themes.Classic.blockStyles, Blockly.Themes.Classic.categoryStyles);
Blockly.Themes.TestFont.setFontStyle({
'family': '"Times New Roman", Times, serif',
'weight': null, // Use default font-weight
'size': 16
});
/**
* Holds the test theme name to Theme instance mapping.
* @type {!Object<string, Blockly.Theme>}
* @private
*/
Blockly.Themes.testThemes_ = {
'Test Hats': Blockly.Themes.TestHats,
'Test Font': Blockly.Themes.TestFont
};
/**
* Get a test theme by name.
* @param {string} value The theme name.
* @return {Blockly.Theme} A theme object or undefined if one doesn't exist.
* @package
*/
function getTestTheme(value) {
return Blockly.Themes.testThemes_[value];
}
/**
* Populate the theme changer dropdown to list the set of test themes.
* @package
*/
function populateTestThemes() {
var themeChanger = document.getElementById('themeChanger');
var keys = Object.keys(Blockly.Themes.testThemes_);
for (var i = 0, key; (key = keys[i]); i++) {
var option = document.createElement('option');
option.setAttribute('value', key);
option.textContent = key;
themeChanger.appendChild(option);
}
}