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

Hide Toolbox in Minecraft Python Hour of Code #10234

Merged
merged 9 commits into from
Oct 15, 2024
8 changes: 8 additions & 0 deletions docs/writing-docs/tutorials/control-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ You can highlight the differences in code between the current step hint and the
### @diffs true
```

### Hide Toolbox

For text-based tutorials, you can choose to hide the toolbox altogether. This is done by specifying **@hideToolbox** in the metadata. The default is ``false``.

```
### @hideToolbox true
```

## Special blocks

### Templates
Expand Down
3 changes: 2 additions & 1 deletion localtypings/pxtarget.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,7 @@ declare namespace pxt.tutorial {
activities?: boolean; // tutorial consists of activities, then steps. uses `###` for steps
explicitHints?: boolean; // tutorial expects explicit hints in `#### ~ tutorialhint` format
flyoutOnly?: boolean; // no categories, display all blocks in flyout
hideToolbox?: boolean; // hide the toolbox in the tutorial
hideIteration?: boolean; // hide step control in tutorial
diffs?: boolean; // automatically diff snippets
noDiffs?: boolean; // don't automatically generated diffs
Expand Down Expand Up @@ -1347,4 +1348,4 @@ declare namespace pxt.auth {
type: "skillmap-completion";
sourceURL: string;
}
}
}
1 change: 1 addition & 0 deletions pxtlib/docsrender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace pxt.docs {
"activities": "<!-- activities -->",
"explicitHints": "<!-- hints -->",
"flyoutOnly": "<!-- flyout -->",
"hideToolbox": "<!-- hideToolbox -->",
"hideIteration": "<!-- iter -->",
"codeStart": "<!-- start -->",
"codeStop": "<!-- stop -->",
Expand Down
8 changes: 7 additions & 1 deletion pxtlib/tutorial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ namespace pxt.tutorial {
simThemeJson
} = computeBodyMetadata(body);

// For python HOC, hide the toolbox (we don't support flyoutOnly mode).
if (pxt.BrowserUtils.useOldTutorialLayout() && language === "python" && metadata.flyoutOnly) {
metadata.flyoutOnly = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is breaking the change that I made recently for getting rid of the icons for block snippets for flyoutOnly tutorials, based on one of the screenshots you included. To get rid of the icon, I'm checking that the metadata has flyoutOnly to true..

const hasCategories = !parent.state.tutorialOptions?.metadata?.flyoutOnly;

Maybe add, on this line, a check for if hideToolbox is true as well, because that would also mean that the tutorial wouldn't have categories.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Made your suggested change and updated the screenshot.

metadata.hideToolbox = true;
}

// noDiffs legacy
if (metadata.diffs === true // enabled in tutorial
|| (metadata.diffs !== false && metadata.noDiffs !== true // not disabled
Expand Down Expand Up @@ -406,7 +412,7 @@ ${code}
if (metadata.explicitHints !== undefined
&& pxt.appTarget.appTheme
&& pxt.appTarget.appTheme.tutorialExplicitHints)
metadata.explicitHints = true;
metadata.explicitHints = true;

return { metadata, body };
}
Expand Down
6 changes: 5 additions & 1 deletion theme/tutorial.less
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,10 @@ code.lang-filterblocks {
}
}

.hideToolbox #headers #flyoutHeader {
border-right: none;
}

/*******************************
Sidebar Tutorial
*******************************/
Expand Down Expand Up @@ -913,4 +917,4 @@ code.lang-filterblocks {
100% {
transform: rotate(0deg);
}
}
}
13 changes: 10 additions & 3 deletions webapp/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5034,7 +5034,11 @@ export class ProjectView
} else {
const tc = document.getElementById("tutorialcard");
if (tc) {
const flyoutOnly = this.state.editorState?.hasCategories === false || this.state.tutorialOptions?.metadata?.flyoutOnly;
const flyoutOnly =
this.state.editorState?.hasCategories === false
|| this.state.tutorialOptions?.metadata?.flyoutOnly
|| this.state.tutorialOptions?.metadata?.hideToolbox;

let headerHeight = 0;
if (flyoutOnly) {
const headers = document.getElementById("headers");
Expand Down Expand Up @@ -5257,7 +5261,9 @@ export class ProjectView
const inEditor = !!this.state.header && !inHome;
const { lightbox, greenScreen, accessibleBlocks } = this.state;
const hideTutorialIteration = inTutorial && tutorialOptions.metadata?.hideIteration;
const flyoutOnly = this.state.editorState?.hasCategories === false || (inTutorial && tutorialOptions.metadata?.flyoutOnly);
const hideToolbox = inTutorial && tutorialOptions.metadata?.hideToolbox;
// flyoutOnly has become a de facto css class for styling tutorials (especially minecraft HOC), so keep it if hideToolbox is true, even if flyoutOnly is false.
const flyoutOnly = this.state.editorState?.hasCategories === false || (inTutorial && (tutorialOptions.metadata?.flyoutOnly || hideToolbox));
const { hideEditorToolbar, transparentEditorToolbar } = targetTheme;
const hideMenuBar = targetTheme.hideMenuBar || hideTutorialIteration || (isTabTutorial && pxt.appTarget.appTheme.embeddedTutorial) || pxt.shell.isTimeMachineEmbed();
const isHeadless = simOpts && simOpts.headless;
Expand Down Expand Up @@ -5308,6 +5314,7 @@ export class ProjectView
logoWide ? "logo-wide" : "",
isHeadless ? "headless" : "",
flyoutOnly ? "flyoutOnly" : "",
hideToolbox ? "hideToolbox" : "",
hideTutorialIteration ? "hideIteration" : "",
this.editor != this.blocksEditor ? "editorlang-text" : "",
this.editor == this.textEditor && this.state.errorListState,
Expand Down Expand Up @@ -5356,7 +5363,7 @@ export class ProjectView
{isSidebarTutorial && flyoutOnly && inTutorial && <sidebarTutorial.SidebarTutorialCard ref={ProjectView.tutorialCardId} parent={this} pokeUser={this.state.pokeUserComponent == ProjectView.tutorialCardId} />}
{inTutorial && !isTabTutorial && <div id="maineditor" className={sandbox ? "sandbox" : ""} role="main">
{!(isSidebarTutorial && flyoutOnly) && inTutorial && <tutorial.TutorialCard ref={ProjectView.tutorialCardId} parent={this} pokeUser={this.state.pokeUserComponent == ProjectView.tutorialCardId} />}
{flyoutOnly && <tutorial.WorkspaceHeader parent={this} />}
{flyoutOnly && <tutorial.WorkspaceHeader parent={this} workspaceId={this.editor.getId()} />}
</div>}
<sidepanel.Sidepanel parent={this} inHome={inHome}
showKeymap={this.state.keymap && simOpts.keymap}
Expand Down
6 changes: 6 additions & 0 deletions webapp/src/monaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1326,8 +1326,14 @@ export class Editor extends toolboxeditor.ToolboxEditor {
|| this.currFile.isReadonly()
|| pxt.shell.isReadOnly()
|| this.isDebugging();

const hideForTutorial =
this.parent.isTutorial()
&& this.parent.state.header.tutorial?.metadata?.hideToolbox;

return pxt.appTarget.appTheme.monacoToolbox
&& !readOnly
&& !hideForTutorial
&& (this.fileType == "typescript" || this.fileType == "python");
}

Expand Down
2 changes: 1 addition & 1 deletion webapp/src/tutorial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ export class WorkspaceHeader extends data.Component<any, WorkspaceHeaderState> {
this.flyoutWidth = flyout.getBoundingClientRect().width;
}

const workspace = document.querySelector('#blocksArea');
const workspace = document.querySelector(`#${this.props.workspaceId || "blocksArea"}`);
if (workspace) {
this.workspaceWidth = workspace.clientWidth - this.flyoutWidth - 4;
}
Expand Down