Skip to content

Commit

Permalink
PoC for secondary icons
Browse files Browse the repository at this point in the history
Part of #120241
  • Loading branch information
Tyriar committed Apr 8, 2021
1 parent 6062a54 commit 84711ff
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/vs/base/browser/ui/iconLabel/iconLabel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface IIconLabelMarkdownString {

export interface IIconLabelValueOptions {
title?: string | IIconLabelMarkdownString;
annotatedIcon?: string;
descriptionTitle?: string;
hideIcon?: boolean;
extraClasses?: string[];
Expand Down
14 changes: 14 additions & 0 deletions src/vs/base/browser/ui/iconLabel/iconLabels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ export function renderLabelWithIcons(text: string): Array<HTMLSpanElement | stri

const [, escaped, codicon] = match;
elements.push(escaped ? `$(${codicon})` : renderIcon({ id: codicon }));
if (codicon === 'terminal') {
const secondaryIcon = renderIcon({ id: 'warning' });
secondaryIcon.style.position = 'absolute';
secondaryIcon.style.top = '10px';
secondaryIcon.style.left = '10px';
secondaryIcon.style.fontSize = '8px';
secondaryIcon.style.color = '#990';
elements.push(secondaryIcon);
}
}

if (textStart < text.length) {
Expand All @@ -30,5 +39,10 @@ export function renderLabelWithIcons(text: string): Array<HTMLSpanElement | stri
export function renderIcon(icon: CSSIcon): HTMLSpanElement {
const node = dom.$(`span`);
node.classList.add(...CSSIcon.asClassNameArray(icon));
if (icon.id === 'terminal') {
node.style.verticalAlign = 'text-bottom';
node.style.clipPath = 'polygon(0% 0%, 100% 0%, 100% 60%, 60% 60%, 60% 100%, 0% 100%)';
node.style.marginRight = '2px';
}
return node;
}
1 change: 1 addition & 0 deletions src/vs/base/browser/ui/iconLabel/iconlabel.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

.monaco-icon-label > .monaco-icon-label-container > .monaco-icon-name-container > .label-name {
color: inherit;
position: relative;
white-space: pre; /* enable to show labels that include multiple whitespaces */
}

Expand Down
17 changes: 10 additions & 7 deletions src/vs/workbench/contrib/terminal/browser/terminalTabsWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ITerminalInstance, ITerminalService, ITerminalTab } from 'vs/workbench/
import { localize } from 'vs/nls';
import * as dom from 'vs/base/browser/dom';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Codicon } from 'vs/base/common/codicons';
import { IconLabel, IIconLabelValueOptions } from 'vs/base/browser/ui/iconLabel/iconLabel';

const $ = dom.$;

Expand Down Expand Up @@ -116,8 +116,10 @@ class TerminalTabsRenderer implements ITreeRenderer<ITabTreeNode, never, ITermin
templateId = 'terminal.tabs';

renderTemplate(container: HTMLElement): ITerminalTabEntryTemplate {
const labelElement = dom.append(container, $('.terminal-tabs-entry'));
return {
labelElement: dom.append(container, $('.terminal-tabs-entry')),
labelElement,
label: new IconLabel(labelElement, { supportHighlights: true, supportDescriptionHighlights: true, supportIcons: true })
};
}

Expand All @@ -126,15 +128,16 @@ class TerminalTabsRenderer implements ITreeRenderer<ITabTreeNode, never, ITermin
let item = node.element;
if ('terminalInstances' in item) {
if (item.terminalInstances.length === 1) {
label = item.terminalInstances[0].title;
const instance = item.terminalInstances[0];
label = `$(${instance.icon.id}) ${instance.title}`;
} else if (item.terminalInstances.length > 1) {
label = `Terminals (${item.terminalInstances.length})`;
}
} else {
label = item.title;
label = `$(${item.icon.id}) ${item.title}`;
}
template.labelElement.textContent = label;
template.labelElement.title = label;
const options: IIconLabelValueOptions = Object.create(null);
template.label.setLabel(label, 'desc', options);
}

disposeTemplate(templateData: ITerminalTabEntryTemplate): void {
Expand All @@ -143,7 +146,7 @@ class TerminalTabsRenderer implements ITreeRenderer<ITabTreeNode, never, ITermin

interface ITerminalTabEntryTemplate {
labelElement: HTMLElement;
icon?: Codicon;
label: IconLabel;
}

type ITabTreeNode = ITerminalTab | ITerminalInstance;
Expand Down

0 comments on commit 84711ff

Please sign in to comment.