From f4b2238523faf1f9774e6ca14750efa2d9a42c2f Mon Sep 17 00:00:00 2001 From: Francesco Spissu Date: Wed, 22 Jun 2022 11:29:36 +0200 Subject: [PATCH] sketchbook tree indentation --- .../sketchbook/sketchbook-tree-widget.tsx | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-tree-widget.tsx b/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-tree-widget.tsx index 240156472..a8581be40 100644 --- a/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-tree-widget.tsx +++ b/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-tree-widget.tsx @@ -1,5 +1,9 @@ import * as React from '@theia/core/shared/react'; -import { inject, injectable, postConstruct } from '@theia/core/shared/inversify'; +import { + inject, + injectable, + postConstruct, +} from '@theia/core/shared/inversify'; import { TreeNode } from '@theia/core/lib/browser/tree/tree'; import { CommandRegistry } from '@theia/core/lib/common/command'; import { @@ -22,6 +26,11 @@ import { SelectableTreeNode } from '@theia/core/lib/browser/tree/tree-selection' import { Sketch } from '../../contributions/contribution'; import { nls } from '@theia/core/lib/common'; +const customTreeProps: TreeProps = { + leftPadding: 20, + expansionTogglePadding: 6, +}; + @injectable() export class SketchbookTreeWidget extends FileTreeWidget { @inject(CommandRegistry) @@ -57,10 +66,14 @@ export class SketchbookTreeWidget extends FileTreeWidget { super.init(); // cache the current open sketch uri const currentSketch = await this.sketchServiceClient.currentSketch(); - this.currentSketchUri = (CurrentSketch.isValid(currentSketch) && currentSketch.uri) || ''; + this.currentSketchUri = + (CurrentSketch.isValid(currentSketch) && currentSketch.uri) || ''; } - protected override createNodeClassNames(node: TreeNode, props: NodeProps): string[] { + protected override createNodeClassNames( + node: TreeNode, + props: NodeProps + ): string[] { const classNames = super.createNodeClassNames(node, props); if ( @@ -73,7 +86,10 @@ export class SketchbookTreeWidget extends FileTreeWidget { return classNames; } - protected override renderIcon(node: TreeNode, props: NodeProps): React.ReactNode { + protected override renderIcon( + node: TreeNode, + props: NodeProps + ): React.ReactNode { if (SketchbookTree.SketchDirNode.is(node) || Sketch.isSketchFile(node.id)) { return
; } @@ -199,4 +215,13 @@ export class SketchbookTreeWidget extends FileTreeWidget { } event.stopPropagation(); } + + protected override getPaddingLeft(node: TreeNode, props: NodeProps): number { + return ( + props.depth * customTreeProps.leftPadding + + (this.needsExpansionTogglePadding(node) + ? customTreeProps.expansionTogglePadding + : 0) + ); + } }