Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "E4/CSS/SWT Mapping"
(63 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | <table cellpadding=" | + | {{Warning|This page has been migrated to to https://github.com/eclipse-platform/eclipse.platform.ui/blob/master/docs/CSS.md.}} |
+ | |||
+ | |||
+ | Many SWT property setting methods can be accessed via CSS. These tables show the equivalent mapping from SWT method to CSS property. They also show pseudo selectors which can be used to choose styling based on widget state. | ||
+ | ==Mapping of SWT method to CSS property== | ||
+ | ===Widget: Control=== | ||
+ | <table cellpadding="5" border="1"> | ||
<tr> | <tr> | ||
− | |||
<th>SWT Method</th> | <th>SWT Method</th> | ||
<th>CSS Property Name</th> | <th>CSS Property Name</th> | ||
Line 7: | Line 12: | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
− | |||
<td>setBackground(Color)</td> | <td>setBackground(Color)</td> | ||
<td>background-color</td> | <td>background-color</td> | ||
Line 13: | Line 17: | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
− | <td> | + | <td>(vertical gradient)</td> |
+ | <td>background-color</td> | ||
+ | <td>Button { background-color: #FF0000 #00FF00 100% }</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>(horizontal gradient)</td> | ||
+ | <td>background-color</td> | ||
+ | <td>Button { background-color: #FF0000 #00FF00 100% false }</td> | ||
+ | </tr> | ||
+ | <tr> | ||
<td>setBackgroundImage(Image)</td> | <td>setBackgroundImage(Image)</td> | ||
<td>background-image</td> | <td>background-image</td> | ||
Line 19: | Line 32: | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
− | |||
<td></td> | <td></td> | ||
<td>border-color</td> | <td>border-color</td> | ||
− | <td>Button { border-color: | + | <td>Button { border-color: #FF0000; }</td> |
</tr> | </tr> | ||
<tr> | <tr> | ||
− | |||
<td></td> | <td></td> | ||
<td>border-width</td> | <td>border-width</td> | ||
Line 31: | Line 42: | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
− | |||
<td></td> | <td></td> | ||
<td>border-style</td> | <td>border-style</td> | ||
Line 37: | Line 47: | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
− | <td> | + | <td>setCursor(Cursor)</td> |
− | + | ||
<td>cursor</td> | <td>cursor</td> | ||
<td>Shell { cursor:crosshair }</td> | <td>Shell { cursor:crosshair }</td> | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
− | |||
<td>setFont(Font)</td> | <td>setFont(Font)</td> | ||
+ | <td>font</td> | ||
+ | <td>Label { font: italic 12 bold "Terminal"; }</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td></td> | ||
<td>font-style<br> | <td>font-style<br> | ||
font-size<br> | font-size<br> | ||
font-weight<br> | font-weight<br> | ||
font-family</td> | font-family</td> | ||
− | <td>Label { font-style: italic;<br> | + | <td>Label { font-style: italic;<br/> |
− | + | font-size: 12; <br/> | |
− | + | font-weight: bold;<br/> | |
− | + | font-family: "Terminal"; }</td> | |
</tr> | </tr> | ||
<tr> | <tr> | ||
− | |||
<td>setForeground(Color)</td> | <td>setForeground(Color)</td> | ||
<td>color</td> | <td>color</td> | ||
<td>Button { color: #FF0000 }</td> | <td>Button { color: #FF0000 }</td> | ||
</tr> | </tr> | ||
+ | </table> | ||
+ | <br> | ||
+ | |||
+ | ===Widget: Button=== | ||
+ | <table cellpadding="5" border="1"> | ||
<tr> | <tr> | ||
− | < | + | <th>SWT Method</th> |
− | < | + | <th>CSS Property Name</th> |
− | < | + | <th>CSS Example</th> |
− | + | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
− | <td> | + | <td>setAlignment(int)</td> |
− | + | <td>swt-alignment</td> | |
− | <td> | + | <td>Label { swt-alignment: up; } /* if pushbutton mode */</td> |
− | <td> | + | |
</tr> | </tr> | ||
+ | </table> | ||
+ | <br> | ||
+ | |||
+ | ===Widget: Label=== | ||
+ | <table cellpadding="5" border="1"> | ||
<tr> | <tr> | ||
− | < | + | <th>SWT Method</th> |
− | < | + | <th>CSS Property Name</th> |
− | < | + | <th>CSS Example</th> |
− | + | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
− | <td> | + | <td>setAlignment(int)</td> |
− | + | <td>swt-alignment</td> | |
− | <td> | + | <td>Label { swt-alignment: center; }</td> |
− | <td> | + | |
</tr> | </tr> | ||
+ | |||
+ | </table> | ||
+ | <br> | ||
+ | |||
+ | ===Widget: CTabFolder=== | ||
+ | <table cellpadding="5" border="1"> | ||
<tr> | <tr> | ||
− | < | + | <th>SWT Method</th> |
− | < | + | <th>CSS Property Name</th> |
− | < | + | <th>CSS Example</th> |
− | + | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
− | <td> | + | <td>setBorderVisible(boolean)</td> |
− | + | <td>border-visible</td> | |
− | <td> | + | <td>CTabFolder { border-visible: true }</td> |
− | <td>CTabFolder { | + | |
</tr> | </tr> | ||
<tr> | <tr> | ||
− | <td> | + | <td>setMaximized(boolean)</td> |
− | + | <td>swt-maximized</td> | |
− | <td> | + | <td>CTabFolder { swt-maximized: true }</td> |
− | <td>CTabFolder { | + | |
</tr> | </tr> | ||
<tr> | <tr> | ||
− | <td> | + | <td>setMinimized(boolean)</td> |
− | + | <td>swt-minimized</td> | |
− | <td> | + | <td>CTabFolder { swt-minimized: true }</td> |
− | <td>CTabFolder { | + | |
</tr> | </tr> | ||
<tr> | <tr> | ||
− | <td> | + | <td>setMaximizeVisible(boolean)</td> |
− | + | <td>swt-maximize-visible</td> | |
− | <td> | + | <td>CTabFolder { swt-maximize-visible: true }</td> |
− | <td>CTabFolder { | + | |
</tr> | </tr> | ||
<tr> | <tr> | ||
− | <td>CTabFolder</td> | + | <td>setMinimizeVisible(boolean)</td> |
− | <td>setUnselectedCloseVisible( | + | <td>swt-minimize-visible</td> |
− | <td> | + | <td>CTabFolder {swt- minimize-visible: true }</td> |
− | <td>CTabFolder { | + | </tr> |
+ | <tr> | ||
+ | <td>setMRUVisible(boolean)</td> | ||
+ | <td>swt-mru-visible</td> | ||
+ | <td>CTabFolder { swt-mru-visible: true }</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>setSimple(boolean)</td> | ||
+ | <td>swt-simple</td> | ||
+ | <td>CTabFolder { swt-simple: true }</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>setSingle(boolean)</td> | ||
+ | <td>swt-single</td> | ||
+ | <td>CTabFolder { swt-single: true }</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>setUnselectedCloseVisible(boolean)</td> | ||
+ | <td>swt-unselected-close-visible</td> | ||
+ | <td>CTabFolder { swt-unselected-close-visible: true }</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>setUnselectedImageVisible(boolean)</td> | ||
+ | <td>swt-unselected-image-visible</td> | ||
+ | <td>CTabFolder { swt-unselected-image-visible: true }</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>setRenderer(CTabFolderRenderer)</td> | ||
+ | <td>swt-tab-renderer</td> | ||
+ | <td>CTabFolder { swt-tab-renderer: url('bundleclass://org.eclipse.e4.ui.workbench.renderers.swt/org.eclipse.e4.ui.workbench.renderers.swt.CTabRendering'); }</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>setSelectionBackground(Color[],int[])</td> | ||
+ | <td>swt-selected-tabs-background</td> | ||
+ | <td>CTabFolder { swt-selected-tabs-background: #FF0000 #FFFFFF 100%; }</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>setBackground(Color[],int[])</td> | ||
+ | <td>swt-unselected-tabs-color</td> | ||
+ | <td>CTabFolder { | ||
+ | swt-unselected-tabs-color: #FF0000 #FFFFFF 100%; }</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>setTabHeight(int)</td> | ||
+ | <td>swt-tab-height</td> | ||
+ | <td>CTabFolder { swt-tab-height: 10px; }</td> | ||
+ | </tr> | ||
+ | </table> | ||
+ | <br> | ||
+ | |||
+ | ===Widget: CTabItem=== | ||
+ | <table cellpadding="5" border="1"> | ||
+ | <tr> | ||
+ | <th>SWT Method</th> | ||
+ | <th>CSS Property Name</th> | ||
+ | <th>CSS Example</th> | ||
+ | </tr> | ||
+ | |||
+ | <tr> | ||
+ | <td>setShowClose(boolean)</td> | ||
+ | <td>swt-show-close</td> | ||
+ | <td>CTabItem { swt-show-close: true }</td> | ||
+ | </tr> | ||
+ | |||
+ | </table> | ||
+ | <br> | ||
+ | |||
+ | ===Widget: CTabFolder with e4Renderer === | ||
+ | Note: The following examples assume that you have first set the tab-renderer to use CTabRendering (see the tab-renderer CSS property in the CTabFolder table above) | ||
+ | <table cellpadding="5" border="1"> | ||
+ | <tr> | ||
+ | <th>e4Renderer Method</th> | ||
+ | <th>CSS Property Name</th> | ||
+ | <th>CSS Example</th> | ||
+ | </tr> | ||
+ | |||
+ | <tr> | ||
+ | <td>setOuterKeyline(Color)</td> | ||
+ | <td>swt-outer-keyline-color</td> | ||
+ | <td>CTabFolder { | ||
+ | swt-outer-keyline-color: #B6BCCC; }</td> | ||
+ | </tr> | ||
+ | |||
+ | <tr> | ||
+ | <td>setCornerRadius(int)</td> | ||
+ | <td>swt-corner-radius</td> | ||
+ | <td>CTabFolder { | ||
+ | swt-corner-radius: 20; }</td> | ||
+ | </tr> | ||
+ | |||
+ | <tr> | ||
+ | <td>setShadowVisible(boolean)</td> | ||
+ | <td>swt-shadow-visible</td> | ||
+ | <td>CTabFolder { | ||
+ | swt-shadow-visible: false; }</td> | ||
+ | </tr> | ||
+ | |||
+ | <tr> | ||
+ | <td>setShadowColor(Color)</td> | ||
+ | <td>swt-shadow-color</td> | ||
+ | <td>CTabFolder { | ||
+ | swt-shadow-color: #F79402; }</td> | ||
+ | </tr> | ||
+ | |||
+ | <tr> | ||
+ | <td>setSelectedTabFill(Color)</td> | ||
+ | <td>swt-selected-tab-fill</td> | ||
+ | <td>CTabFolder { | ||
+ | swt-selected-tab-fill: #F79402; }</td> | ||
+ | </tr> | ||
+ | |||
+ | <tr> | ||
+ | <td>setTabOutline(Color)</td> | ||
+ | <td>swt-tab-outline</td> | ||
+ | <td>CTabFolder { | ||
+ | swt-tab-outline: #F79402; }</td> | ||
+ | </tr> | ||
+ | |||
+ | </table> | ||
+ | <br> | ||
+ | |||
+ | ==Pseudo classes which can be used in CSS to style SWT widgets== | ||
+ | <table cellpadding="5" border="1"> | ||
+ | <tr> | ||
+ | <th>SWT Widgets</th> | ||
+ | <th>CSS Pseudo Selector</th> | ||
+ | <th>CSS Example</th> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>Control</td> | ||
+ | <td>:focus †</td> | ||
+ | <td>CTabFolder:focus { background-color: #FF0000; } | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>Control</td> | ||
+ | <td>:visible †</td> | ||
+ | <td>Shell:visible { background-color: #FF0000; } | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>Control</td> | ||
+ | <td>:enabled †</td> | ||
+ | <td>Text:enabled { background-color: #FF0000; } | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>Control</td> | ||
+ | <td>:disabled †</td> | ||
+ | <td>Text:disabled { background-color: #FF0000; } | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>Shell</td> | ||
+ | <td>:active</td> | ||
+ | <td>Shell:active { background-color: #FF0000; } | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>Button</td> | ||
+ | <td>:checked</td> | ||
+ | <td>Button:checked { background-color: #FF0000; } | ||
</tr> | </tr> | ||
<tr> | <tr> | ||
<td>CTabFolder</td> | <td>CTabFolder</td> | ||
− | <td> | + | <td>:selected</td> |
− | <td> | + | <td>CTabFolder:selected { background-color: #FF0000; } |
− | <td> | + | </tr> |
+ | <tr> | ||
+ | <td>CTabItem</td> | ||
+ | <td>:selected</td> | ||
+ | <td>CTabItem:selected { font-weight: bold; } | ||
</tr> | </tr> | ||
</table> | </table> | ||
+ | <br> | ||
+ | † As of yet styles are only applied when SWT UI is initially loaded, if widget state is changed afterwards, changes will not take effect |
Latest revision as of 09:41, 5 February 2024
Many SWT property setting methods can be accessed via CSS. These tables show the equivalent mapping from SWT method to CSS property. They also show pseudo selectors which can be used to choose styling based on widget state.
Contents
Mapping of SWT method to CSS property
Widget: Control
SWT Method | CSS Property Name | CSS Example |
---|---|---|
setBackground(Color) | background-color | Button { background-color: #FF0000 } |
(vertical gradient) | background-color | Button { background-color: #FF0000 #00FF00 100% } |
(horizontal gradient) | background-color | Button { background-color: #FF0000 #00FF00 100% false } |
setBackgroundImage(Image) | background-image | Button { background-image: some url } |
border-color | Button { border-color: #FF0000; } | |
border-width | Button { border-width: 3 } | |
border-style | Button { border-style: dotted } | |
setCursor(Cursor) | cursor | Shell { cursor:crosshair } |
setFont(Font) | font | Label { font: italic 12 bold "Terminal"; } |
font-style font-size |
Label { font-style: italic; font-size: 12; |
|
setForeground(Color) | color | Button { color: #FF0000 } |
Widget: Button
SWT Method | CSS Property Name | CSS Example |
---|---|---|
setAlignment(int) | swt-alignment | Label { swt-alignment: up; } /* if pushbutton mode */ |
Widget: Label
SWT Method | CSS Property Name | CSS Example |
---|---|---|
setAlignment(int) | swt-alignment | Label { swt-alignment: center; } |
Widget: CTabFolder
SWT Method | CSS Property Name | CSS Example |
---|---|---|
setBorderVisible(boolean) | border-visible | CTabFolder { border-visible: true } |
setMaximized(boolean) | swt-maximized | CTabFolder { swt-maximized: true } |
setMinimized(boolean) | swt-minimized | CTabFolder { swt-minimized: true } |
setMaximizeVisible(boolean) | swt-maximize-visible | CTabFolder { swt-maximize-visible: true } |
setMinimizeVisible(boolean) | swt-minimize-visible | CTabFolder {swt- minimize-visible: true } |
setMRUVisible(boolean) | swt-mru-visible | CTabFolder { swt-mru-visible: true } |
setSimple(boolean) | swt-simple | CTabFolder { swt-simple: true } |
setSingle(boolean) | swt-single | CTabFolder { swt-single: true } |
setUnselectedCloseVisible(boolean) | swt-unselected-close-visible | CTabFolder { swt-unselected-close-visible: true } |
setUnselectedImageVisible(boolean) | swt-unselected-image-visible | CTabFolder { swt-unselected-image-visible: true } |
setRenderer(CTabFolderRenderer) | swt-tab-renderer | CTabFolder { swt-tab-renderer: url('bundleclass://org.eclipse.e4.ui.workbench.renderers.swt/org.eclipse.e4.ui.workbench.renderers.swt.CTabRendering'); } |
setSelectionBackground(Color[],int[]) | swt-selected-tabs-background | CTabFolder { swt-selected-tabs-background: #FF0000 #FFFFFF 100%; } |
setBackground(Color[],int[]) | swt-unselected-tabs-color | CTabFolder { swt-unselected-tabs-color: #FF0000 #FFFFFF 100%; } |
setTabHeight(int) | swt-tab-height | CTabFolder { swt-tab-height: 10px; } |
Widget: CTabItem
SWT Method | CSS Property Name | CSS Example |
---|---|---|
setShowClose(boolean) | swt-show-close | CTabItem { swt-show-close: true } |
Widget: CTabFolder with e4Renderer
Note: The following examples assume that you have first set the tab-renderer to use CTabRendering (see the tab-renderer CSS property in the CTabFolder table above)
e4Renderer Method | CSS Property Name | CSS Example |
---|---|---|
setOuterKeyline(Color) | swt-outer-keyline-color | CTabFolder { swt-outer-keyline-color: #B6BCCC; } |
setCornerRadius(int) | swt-corner-radius | CTabFolder { swt-corner-radius: 20; } |
setShadowVisible(boolean) | swt-shadow-visible | CTabFolder { swt-shadow-visible: false; } |
setShadowColor(Color) | swt-shadow-color | CTabFolder { swt-shadow-color: #F79402; } |
setSelectedTabFill(Color) | swt-selected-tab-fill | CTabFolder { swt-selected-tab-fill: #F79402; } |
setTabOutline(Color) | swt-tab-outline | CTabFolder { swt-tab-outline: #F79402; } |
Pseudo classes which can be used in CSS to style SWT widgets
SWT Widgets | CSS Pseudo Selector | CSS Example |
---|---|---|
Control | :focus † | CTabFolder:focus { background-color: #FF0000; } |
Control | :visible † | Shell:visible { background-color: #FF0000; } |
Control | :enabled † | Text:enabled { background-color: #FF0000; } |
Control | :disabled † | Text:disabled { background-color: #FF0000; } |
Shell | :active | Shell:active { background-color: #FF0000; } |
Button | :checked | Button:checked { background-color: #FF0000; } |
CTabFolder | :selected | CTabFolder:selected { background-color: #FF0000; } |
CTabItem | :selected | CTabItem:selected { font-weight: bold; } |
† As of yet styles are only applied when SWT UI is initially loaded, if widget state is changed afterwards, changes will not take effect