|
1 | 1 | ---
|
2 | 2 | title: "Colors and Styling for Visual Studio | Microsoft Docs"
|
3 | 3 | ms.custom: ""
|
4 |
| -ms.date: "04/26/2017" |
| 4 | +ms.date: "07/31/2017" |
5 | 5 | ms.reviewer: ""
|
6 | 6 | ms.suite: ""
|
7 | 7 | ms.technology:
|
@@ -459,272 +459,3 @@ catGUID);
|
459 | 459 | }
|
460 | 460 | }
|
461 | 461 | ```
|
462 |
| - |
463 |
| -## <a name="BKMK_DaytonaAndWebUI"></a> Daytona and web UI |
464 |
| - |
465 |
| -### Overview |
466 |
| -"Daytona" is a set of APIs, tools, and services that enable a user to create plugins with HTML, CSS, and JavaScript that can be used in a variety of hosts, like Visual Studio or F12. Plugins are composed of a portable component, which is written in HTML, CSS and JavaScript, and optional host-specific components. Each Daytona host can have its own set of UI conventions, either implicit or explicit, that a plugin must conform to in order to appear native to its environment. Some hosts, like Visual Studio, allow end users to make changes to the default "theme" so that the host's visual aspects cannot be statically targeted when authoring a style sheet. This poses a challenge to developers building portable plugins. This topic explains how to author web UI in Visual Studio using the Daytona host in a way that properly supports both theming and High Contrast. |
467 |
| - |
468 |
| -### Daytona theming mechanism |
469 |
| -The Daytona runtime provides a set of services that abstracts the UI conventions and theming capabilities of the host. These services ensure that plugins automatically conform to the visual expectations of the user based on the environment they are hosted in. This behavior is provided by three primary features: |
470 |
| - |
471 |
| -1. A runtime-injected style sheet (plugin.css) that transparently applies a set of CSS rules to a plugin's UI and styles the default set of HTML controls (for example, HTMLInputElement and HTMLButtonElement |
472 |
| - |
473 |
| -2. A set of host-provided tokens that can be used to style UI elements using values that are theme-based instead of hardcoded |
474 |
| - |
475 |
| - - a declarative syntax for accessing these tokens with CSS |
476 |
| - |
477 |
| - - an API for programmatically accessing theme tokens from JavaScript |
478 |
| - |
479 |
| -3. Notification of theme changes |
480 |
| - |
481 |
| -#### Runtime-injected style sheet |
482 |
| -The Daytona runtime coordinates with the host to inject a style sheet that automatically themes the standard UI elements of a plugin. This includes styling for the following concepts: |
483 |
| - |
484 |
| -- Environment font |
485 |
| - |
486 |
| -- Background colors |
487 |
| - |
488 |
| -- Hyperlinks |
489 |
| - |
490 |
| -- Form controls (for example: `<select>`, `<input>`, `<button>` |
491 |
| - |
492 |
| -- Tables |
493 |
| - |
494 |
| -- Headings |
495 |
| - |
496 |
| -- Scroll bars |
497 |
| - |
498 |
| -This means that if your UI is composed entirely of standard HTML UI controls, then no additional work should be needed to respond correctly to theme changes and to support High Contrast. |
499 |
| - |
500 |
| -#### Custom UI |
501 |
| -In almost every nontrivial case, the standard HTML UI controls will be insufficient for providing a complete experience for a plugin and custom UI must be introduced. In order to support proper font choice and color use, **theme tokens** should be used either declaratively in CSS or imperatively via the JavaScript API described below. The Daytona runtime will take care of updating the style sheets that use these tokens on plugin load and on theme changes. |
502 |
| - |
503 |
| -##### Theme tokens |
504 |
| -Both standard and host-specific theme tokens are available. Standard tokens are host-injected and always available. Using the standard tokens wherever possible is preferable. Standard tokens are guaranteed to be provided by all Daytona hosts, and using them makes your plugin inherently more portable. The set of standard tokens is subject to change, though only new tokens should be added and none should be removed. The Visual Studio 2013 version is documented below: |
505 |
| - |
506 |
| -| Token name | Description | |
507 |
| -| --- | --- | |
508 |
| -| `plugin-background-color` | The default background color for the plugin | |
509 |
| -| `plugin-color` | The default foreground color for the plugin | |
510 |
| -| `plugin-contextmenu-active-color` | The default foreground selection color for context menus when they are active (have focus) | |
511 |
| -| `plugin-contextmenu-background-color` | The default background color for context menus | |
512 |
| -| `plugin-contextmenu-border-color` | The default border color for context menus | |
513 |
| -| `plugin-contextmenu-color` | The default foreground color for context menus | |
514 |
| -| `plugin-contextmenu-hover-color` | The default hover background color for context menus | |
515 |
| -| `plugin-contextmenu-hover-text-color` | The default hover foreground color for context menus | |
516 |
| -| `plugin-contextmenu-icon-checkbox` | The default checkbox icon color for context menus | |
517 |
| -| `plugin-contextmenu-inactive-text-color` | The default foreground selection color for context menus when they are inactive | |
518 |
| -| `plugin-contextmenu-separator-color` | The default separator color for context menus | |
519 |
| -| `plugin-font-family` | The default font family to use for the plugin | |
520 |
| - |
521 |
| -In Visual Studio, the following `plugin-font` tokens are based on the Environment font settings: |
522 |
| - |
523 |
| -- `plugin-font-size` |
524 |
| - |
525 |
| -- `plugin-font-weight` |
526 |
| - |
527 |
| -- `plugin-highlight-background-color` |
528 |
| - |
529 |
| -- `plugin-highlight-color` |
530 |
| - |
531 |
| -- `plugin-inactive-color` |
532 |
| - |
533 |
| -The following `plugin-link` tokens are used to style `HTMLElements` (hyperlinks): |
534 |
| - |
535 |
| -- `plugin-link-color` |
536 |
| - |
537 |
| -- `plugin-link-active-color` |
538 |
| - |
539 |
| -- `plugin-link-hover-color` |
540 |
| - |
541 |
| -Plugin.css styles scrollbars by default using the following tokens to better support the themes in the various hosts (in particular, Visual Studio): |
542 |
| - |
543 |
| -- `plugin-scrollbar-arrow-color` |
544 |
| - |
545 |
| -- `plugin-scrollbar-background-color` |
546 |
| - |
547 |
| -- `plugin-scrollbar-face-color` |
548 |
| - |
549 |
| -The following `plugin-select` tokens are used to style the `HTMLSelectElement` (combo box drop-down): |
550 |
| - |
551 |
| -- `plugin-select-option-background-color` |
552 |
| - |
553 |
| -- `plugin-select-option-color` |
554 |
| - |
555 |
| -- `plugin-select-option-checked-background-color` |
556 |
| - |
557 |
| -- `plugin-select-option-checked-border-color` |
558 |
| - |
559 |
| -- `plugin-select-option-checked-foreground-color` |
560 |
| - |
561 |
| -- `plugin-select-option-hover-background-color` |
562 |
| - |
563 |
| -- `plugin-select-option-hover-border-color` |
564 |
| - |
565 |
| -- `plugin-select-option-hover-foreground-color` |
566 |
| - |
567 |
| -- `plugin-select-border-color` |
568 |
| - |
569 |
| -- `plugin-select-background-color` |
570 |
| - |
571 |
| -- `plugin-select-foreground-color` |
572 |
| - |
573 |
| -- `plugin-select-hover-background-color` |
574 |
| - |
575 |
| -- `plugin-select-hover-border-color` |
576 |
| - |
577 |
| -- `plugin-select-hover-foreground-color` |
578 |
| - |
579 |
| -- `plugin-table-border-color` |
580 |
| - |
581 |
| -- `plugin-table-header-background-color` |
582 |
| - |
583 |
| -- `plugin-table-header-color` |
584 |
| - |
585 |
| -- `plugin-textbox-border-color` |
586 |
| - |
587 |
| -- `plugin-textbox-background-color` |
588 |
| - |
589 |
| -- `plugin-textbox-color` |
590 |
| - |
591 |
| -- `plugin-textbox-disabled-background-color` |
592 |
| - |
593 |
| -- `plugin-textbox-disabled-border-color` |
594 |
| - |
595 |
| -- `plugin-textbox-disabled-color` |
596 |
| - |
597 |
| -These tokens should be used for *all* tree views and tables, because they have the correct defaults set in the various hosts to support themes and High Contrast: |
598 |
| - |
599 |
| -- `plugin-treeview-content-background-color` |
600 |
| - |
601 |
| -- `plugin-treeview-content-color` |
602 |
| - |
603 |
| -- `plugin-treeview-content-inactive-selected-color` |
604 |
| - |
605 |
| -- `plugin-treeview-content-mouseover-background-color` |
606 |
| - |
607 |
| -- `plugin-treeview-content-mouseover-color` |
608 |
| - |
609 |
| -- `plugin-treeview-content-inactive-selected-color` |
610 |
| - |
611 |
| -- `plugin-treeview-content-selected-background-color` |
612 |
| - |
613 |
| -- `plugin-treeview-content-selected-border-color` |
614 |
| - |
615 |
| -- `plugin-treeview-content-selected-color` |
616 |
| - |
617 |
| -##### Host-specific tokens |
618 |
| -In addition to supporting the standard set of tokens, hosts may also provide nonstandard tokens. The Visual Studio host does this by allowing the plugin to specify theme token aliases in a Visual Studio-specific section of the manifest. For example: |
619 |
| - |
620 |
| -``` |
621 |
| -"vs": { |
622 |
| - "theme_token_aliases": { |
623 |
| - "diagnostics-host-border": { |
624 |
| - "category": "f8a8b2a5-dd35-43f6-a382-fd6a61325c22", |
625 |
| - "key_type": "BackgroundColor", |
626 |
| - "name": "Border" |
627 |
| - }, |
628 |
| - ... |
629 |
| - } |
630 |
| -} |
631 |
| -``` |
632 |
| - |
633 |
| - This example introduces a theme token, named `diagnostics-host-border`, which can be referenced identically to the standard tokens mentioned above. The `category`, `key_type`, and `name` are used to resolve the color through the `IVsFontAndColorStorage` interface. In many cases, it's possible to find appropriate colors (along with the `category`, `key_type`, and `name` information) in the XML files located in `VSCommonContent\themes`. This same mechanism is used if your package introduces new configurable colors: match the `category`, `key_type`, and `name` to the color that you'd like to use. Plugin authors should attempt to use standard tokens whenever possible and only use host-specific tokens when absolutely necessary. |
634 |
| - |
635 |
| -##### Using theme tokens in CSS |
636 |
| - Theme tokens are referred to via a specifically formatted comment syntax. The rules for token parsing: |
637 |
| - |
638 |
| -1. The comment expression must be enclosed within square brackets (`[ ]`). |
639 |
| - |
640 |
| -2. All white space within the comment, but outside of the expression, is ignored. |
641 |
| - |
642 |
| -3. The comment expression must directly follow the property it replaces. |
643 |
| - |
644 |
| -4. Any leading or trailing white space within the expression will be trimmed. |
645 |
| - |
646 |
| -5. Each token name within the expression must be enclosed in curly braces (for example, `{font-family}` and `{button-hover-color}`). Otherwise, it will be treated as a literal value. |
647 |
| - |
648 |
| - The following are examples of how the token parser will replace CSS values, assuming that the `plugin-background-color` token has the value of `#000` and the `plugin-font-family` token has the value of `Verdana`. |
649 |
| - |
650 |
| -| Authored CSS | Parsed CSS | Notes | |
651 |
| -| --- | --- | --- | |
652 |
| -| `background-color: #fff; /*[{plugin-background-color}]*/` | `background-color: #000;` | The default value is replaced with the dynamic host-specific value. | |
653 |
| -| `background-color: #fff; /* [{plugin-background-color}] */` | `background-color: #000;` | The white space outside of the expression is ignored. | |
654 |
| -| `background-color: #fff; /*[ {plugin-background-color} ]*/` | `background-color: #000;` | The trailing and leading white space within the expression is trimmed. | |
655 |
| -| `background-color: #fff; /*{plugin-background-color}*/` | `background-color: #fff;` | The expression isn't enclosed in square brackets, and therefore the comment is ignored. | |
656 |
| -| `background-color: #fff; /*[plugin-background-color]*/` | `background-color: plugin-background-color;` | The token isn't enclosed in curly braces, and is therefore treated as a literal value. | |
657 |
| -| `/*[{plugin-background-color}]*/ background-color: #fff;` | `background-color: #fff;` | The comment doesn't follow the property value and is therefore ignored. | |
658 |
| -| `background-color: #fff; /*[{plugin-background-color}]*/` | `background-color: #fff;`| *Same as above* | |
659 |
| -| `/*[{plugin-background-color}]*/ background-color: #fff;` | `background-color: #fff;` | *Same as above* | |
660 |
| -| `font-family: Arial, sans-serif; /*[{plugin-font-family}, sans-serif]*/` | `font-family: Verdana, sans-serif;` | The token is replaced and the literal content is maintained. | |
661 |
| -| `background-image: linear-gradient(0% #000, 100% #ccc); /*[linear-gradient(0% #000, 100% {plugin-background-color})]*/` | `background-image: linear-gradient(0% #000, 100% #000);` | *Same as above* | |
662 |
| - |
663 |
| -If a CSS file includes theme tokens it must be marked by the `data-plugin-theme` attribute on the `link` element in the HTML file. For example: |
664 |
| - |
665 |
| -``` |
666 |
| -<link href="default.css" rel="stylesheet" data-plugin-theme="true" /> |
667 |
| -``` |
668 |
| - |
669 |
| -##### Using theme tokens from JavaScript |
670 |
| -While custom UI should be themed by CSS where possible, there are scenarios when the value of a theme token needs to be accessed programmatically. For example, if custom UI is being drawn onto a `CanvasElement` that doesn't inherit styling from CSS, or if a UI element is being dynamically created as opposed to referencing style sheets. The scenarios are enabled by using the Daytona API `Plugin.Theme.getValue`. This function returns a host-provided theme value when given a token name. |
671 |
| - |
672 |
| -| Not themed | Themed | |
673 |
| -| --- | --- | |
674 |
| -| `var surface = document.getElementById("surface").getContext("2d"); surface.fillStyle = "#ccc"; surface.fillRect(0, 0, 200, 200);` | `var surface = document.getElementById("surface").getContext("2d"); surface.fillStyle = ("plugin-background-color"); surface.fillRect(0, 0, 200, 200);` | |
675 |
| -| `var el = document.createElement("div"); el.style.backgroundColor = "#ccc";` | `var el = document.createElement("div"); el.style.backgroundColor = Plugin.Theme.getValue("plugin-background-color");` | |
676 |
| - |
677 |
| -If tokens are used from JavaScript, **the theme change event must be handled to respond to updates**. This is unnecessary for theme tokens used declaratively in CSS, as the Daytona runtime takes care of it for the plugin. The theme event can be handled in the following way: |
678 |
| - |
679 |
| -**Member (single handler)** |
680 |
| -``` |
681 |
| -Plugin.Theme.onchange = function () |
682 |
| -{ |
683 |
| - // re-draw dynamic UI here |
684 |
| -} |
685 |
| -``` |
686 |
| - |
687 |
| -**DOM-Event (multiple handlers)** |
688 |
| -``` |
689 |
| -Plugin.Theme.addEventListener("change", function () |
690 |
| -{ |
691 |
| - // re-draw dynamic UI here |
692 |
| -}); |
693 |
| -``` |
694 |
| - |
695 |
| -In this case, it would be very common to re-call `Plugin.Theme.getValue` in these handlers, as the value of the theme tokens likely changed when the theme changed. |
696 |
| - |
697 |
| -##### Standard token mapping |
698 |
| -The standard tokens are mapped to Environment and Shell colors. The list below gives a flavor of what those mappings are. |
699 |
| - |
700 |
| -| Token name | VS mapping (`EnvironmentColors`) | |
701 |
| -| --- | --- | |
702 |
| -| `plugin-color` | `ToolWindowTextColorKey` | |
703 |
| -| `plugin-background-color` | `ToolWindowBackgroundColorKey` | |
704 |
| -| `plugin-link-color` | `ControlLinkTextColorKey` | |
705 |
| -| `plugin-link-hover-color` | `ControlLinkTextHoverColorKey` | |
706 |
| -| `plugin-link-active-color` | `ControlLinkTextPressedColorKey` | |
707 |
| -| `plugin-highlight-color` | `HighlightTextColorKey` | |
708 |
| -| `plugin-highlight-background-color` | `HighlightColorKey` | |
709 |
| -| `plugin-table-header-background-color` | `GridHeadingBackgroundColorKey` | |
710 |
| -| `plugin-table-header-color` | `GridHeadingTextColorKey` | |
711 |
| -| `plugin-table-border-color` | `GridLineColorKey` | |
712 |
| -| `plugin-button-background-color` | `ButtonFaceColorKey` | |
713 |
| -| `plugin-button-hover-background-color` | `ButtonHighlightColorKey` | |
714 |
| -| `plugin-button-color` | `ButtonTextColorKey` | |
715 |
| -| `plugin-button-border-color` | `ButtonBorderColorKey` | |
716 |
| - |
717 |
| -##### Theme changes |
718 |
| -The Visual Studio host triggers plugin theme changes when an end user makes changes to the following settings: |
719 |
| - |
720 |
| -**Color theme:** |
721 |
| - |
722 |
| -<br />Color theme changes |
723 |
| - |
724 |
| -**Environment theme:** |
725 |
| - |
726 |
| -<br />Environment theme changes |
727 |
| - |
728 |
| -**Operating system theme** (only when changing to and from High Contrast): |
729 |
| - |
730 |
| -<br />Operating system theme changes |
0 commit comments