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

Workspace theme #3093

Merged
merged 8 commits into from
Sep 26, 2019
Merged

Workspace theme #3093

merged 8 commits into from
Sep 26, 2019

Conversation

samelhusseini
Copy link
Contributor

@samelhusseini samelhusseini commented Sep 26, 2019

The basics

  • I branched from develop
  • My pull request is against develop
  • My code follows the style guide

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

Screen Shot 2019-09-25 at 5 31 57 PM

Testing with Dark Theme.
Tested playground and multi-playground.
All tests pass.

Tested on:

  • Desktop Chrome
  • Desktop Safari

Documentation

Need to add documentation for how to configure themes.

Additional Information

Copy link
Contributor

@alschmiedt alschmiedt left a 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

};

/**
* Set the workspace theme, and refresh the workspace.
Copy link
Contributor

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

/**
* Updates all the blocks with new style.
* @param {!Array.<!Blockly.Block>} blocks List of blocks to update the style
* on.
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor Author

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing.

*/
this.themeManager_ = this.options.parentWorkspace ?
this.options.parentWorkspace.getThemeManager() :
new Blockly.ThemeManager(this.options.theme);
Copy link
Contributor

@alschmiedt alschmiedt Sep 26, 2019

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, agreed.

@samelhusseini samelhusseini merged commit 870824b into google:develop Sep 26, 2019
@samelhusseini samelhusseini deleted the workspace_theme branch September 26, 2019 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants