-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Workspace theme #3093
Workspace theme #3093
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few small things but otherwise lgtm
core/theme_manager.js
Outdated
}; | ||
|
||
/** | ||
* Set the workspace theme, and refresh the workspace. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'and refresh all subscribed workspaces and components' ?
core/workspace.js
Outdated
/** | ||
* Updates all the blocks with new style. | ||
* @param {!Array.<!Blockly.Block>} blocks List of blocks to update the style | ||
* on. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent
core/toolbox.js
Outdated
@@ -175,7 +178,8 @@ Blockly.Toolbox.prototype.init = function() { | |||
oneBasedIndex: workspace.options.oneBasedIndex, | |||
horizontalLayout: workspace.horizontalLayout, | |||
toolboxPosition: workspace.options.toolboxPosition, | |||
renderer: workspace.options.renderer | |||
renderer: workspace.options.renderer, | |||
theme: workspace.options.theme |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this here? I think the workspace is just going to end up using the parent's themeManager
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I got rid of all the others, this one snuck through.
core/block.js
Outdated
@@ -990,10 +990,10 @@ Blockly.Block.prototype.setColour = function(colour) { | |||
* @throws {Error} if the block style does not exist. | |||
*/ | |||
Blockly.Block.prototype.setStyle = function(blockStyleName) { | |||
var theme = Blockly.getTheme(); | |||
var theme = this.workspace.getTheme(); | |||
if (!theme) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this check anymore? Since theme should never be able to be null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing.
core/workspace.js
Outdated
*/ | ||
this.themeManager_ = this.options.parentWorkspace ? | ||
this.options.parentWorkspace.getThemeManager() : | ||
new Blockly.ThemeManager(this.options.theme); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we set a default theme here if there are none on the options? There was a bug that the code we deleted fixed for headless workspaces. Issue #2605
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, agreed.
The basics
The details
Resolves
#2733
Proposed Changes
Move the theme so it's attached to the parent workspace (and no longer a global). This allows us to have multiple instances of Blockly with different themes.
Created a new object
Blockly.ThemeManager
that stores the current workspace theme and is in charge of registering subscribed workspaces, and registering subscribed UI components.Subscribed workspaces are refreshed when the theme changes.
Throughout our codebase we can also register Blockly UI components with the theme, letting the theme manager know what component name to use, and what style property to set to. Whenever the theme changes, the UI component is updated with the new value for the component name it's interested in.
This happens at runtime, so developers are able to switch themes, and have all the styles reflected.
Added Dark theme for testing.
Reason for Changes
No way to configure UI component styles.
Test Coverage
Testing with Dark Theme.
Tested playground and multi-playground.
All tests pass.
Tested on:
Documentation
Need to add documentation for how to configure themes.
Additional Information