mirror of
https://github.com/google/blockly.git
synced 2026-01-04 23:50:12 +01:00
Support enabling start hats from themes (#3722)
* Support themes configuring the start hats of blocks. Add test themes
This commit is contained in:
62
tests/themes/test_themes.js
Normal file
62
tests/themes/test_themes.js
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user