1 /// 2 module nanogui.theme; 3 4 /* 5 NanoGUI was developed by Wenzel Jakob <wenzel.jakob@epfl.ch>. 6 The widget drawing code is based on the NanoVG demo application 7 by Mikko Mononen. 8 9 All rights reserved. Use of this source code is governed by a 10 BSD-style license that can be found in the LICENSE.txt file. 11 */ 12 13 import nanogui.common : NanoContext, Color; 14 import nanogui.entypo; 15 16 /** 17 * Storage class for basic theme-related properties. 18 */ 19 class Theme 20 { 21 public: 22 this(NanoContext ctx) 23 { 24 mStandardFontSize = 16; 25 mButtonFontSize = 20; 26 mTextBoxFontSize = 20; 27 mIconScale = 0.77f; 28 29 mWindowCornerRadius = 2; 30 mWindowHeaderHeight = 30; 31 mWindowDropShadowSize = 10; 32 mButtonCornerRadius = 2; 33 mTabBorderWidth = 0.75f; 34 mTabInnerMargin = 5; 35 mTabMinButtonWidth = 20; 36 mTabMaxButtonWidth = 160; 37 mTabControlWidth = 20; 38 mTabButtonHorizontalPadding = 10; 39 mTabButtonVerticalPadding = 2; 40 mResizeAreaOffset = 10; 41 42 mDropShadow = Color(0, 0, 0, 128); 43 mTransparent = Color(0, 0, 0, 0); 44 mBorderDark = Color(29, 29, 29, 255); 45 mBorderLight = Color(92, 92, 92, 255); 46 mBorderMedium = Color(35, 35, 35, 255); 47 mTextColor = Color(255, 255, 255, 160); 48 mDisabledTextColor = Color(255, 255, 255, 80); 49 mTextColorShadow = Color(0, 0, 0, 160); 50 mIconColor = mTextColor; 51 52 mButtonGradientTopFocused = Color(64, 64, 64, 255); 53 mButtonGradientBotFocused = Color(48, 48, 48, 255); 54 mButtonGradientTopUnfocused = Color(74, 74, 74, 255); 55 mButtonGradientBotUnfocused = Color(58, 58, 58, 255); 56 mButtonGradientTopPushed = Color(41, 41, 41, 255); 57 mButtonGradientBotPushed = Color(29, 29, 29, 255); 58 59 /* Window-related */ 60 mWindowFillUnfocused = Color(43, 43, 43, 230); 61 mWindowFillFocused = Color(45, 45, 45, 230); 62 mWindowTitleUnfocused = Color(220, 220, 220, 160); 63 mWindowTitleFocused = Color(255, 255, 255, 190); 64 65 mWindowHeaderGradientTop = mButtonGradientTopUnfocused; 66 mWindowHeaderGradientBot = mButtonGradientBotUnfocused; 67 mWindowHeaderSepTop = mBorderLight; 68 mWindowHeaderSepBot = mBorderDark; 69 70 mWindowPopup = Color(50, 50, 50, 255); 71 mWindowPopupTransparent = Color(50, 50, 50, 0); 72 73 mCheckBoxIcon = Entypo.ICON_CHECK; 74 mMessageInformationIcon = Entypo.ICON_INFO_WITH_CIRCLE; 75 mMessageQuestionIcon = Entypo.ICON_HELP_WITH_CIRCLE; 76 mMessageWarningIcon = Entypo.ICON_WARNING; 77 mMessageAltButtonIcon = Entypo.ICON_CIRCLE_WITH_CROSS; 78 mMessagePrimaryButtonIcon = Entypo.ICON_CHECK; 79 mPopupChevronRightIcon = Entypo.ICON_CHEVRON_RIGHT; 80 mPopupChevronLeftIcon = Entypo.ICON_CHEVRON_LEFT; 81 mTabHeaderLeftIcon = Entypo.ICON_ARROW_BOLD_LEFT; 82 mTabHeaderRightIcon = Entypo.ICON_ARROW_BOLD_RIGHT; 83 mTextBoxUpIcon = Entypo.ICON_CHEVRON_UP; 84 mTextBoxDownIcon = Entypo.ICON_CHEVRON_DOWN; 85 86 import arsd.nanovega : createFontMem; 87 import nanogui.resources; 88 mFontNormal = ctx.createFontMem("sans", roboto_regular_ttf.ptr, 89 cast(int) roboto_regular_ttf.length, 0); 90 mFontBold = ctx.createFontMem("sans-bold", roboto_bold_ttf.ptr, 91 cast(int) roboto_bold_ttf.length, 0); 92 mFontIcons = ctx.createFontMem("icons", entypo_ttf.ptr, 93 cast(int) entypo_ttf.length, 0); 94 if (mFontNormal == -1 || mFontBold == -1 || mFontIcons == -1) 95 { 96 throw new Exception("Could not load fonts!"); 97 } 98 } 99 100 /* Fonts */ 101 /// The standard font face (default: `"sans"` from `resources/roboto_regular.ttf`). 102 int mFontNormal; 103 /// The bold font face (default: `"sans-bold"` from `resources/roboto_regular.ttf`). 104 int mFontBold; 105 /// The icon font face (default: `"icons"` from `resources/entypo.ttf`). 106 int mFontIcons; 107 /** 108 * The amount of scaling that is applied to each icon to fit the size of 109 * NanoGUI widgets. The default value is `0.77f`, setting to e.g. higher 110 * than `1.0f` is generally discouraged. 111 */ 112 float mIconScale; 113 114 /* Spacing-related parameters */ 115 /// The font size for all widgets other than buttons and textboxes (default: ` 16`). 116 int mStandardFontSize; 117 /// The font size for buttons (default: `20`). 118 int mButtonFontSize; 119 /// The font size for text boxes (default: `20`). 120 int mTextBoxFontSize; 121 /// Rounding radius for Window widget corners (default: `2`). 122 int mWindowCornerRadius; 123 /// Default size of Window widget titles (default: `30`). 124 int mWindowHeaderHeight; 125 /// Size of drop shadow rendered behind the Window widgets (default: `10`). 126 int mWindowDropShadowSize; 127 /// Rounding radius for Button (and derived types) widgets (default: `2`). 128 int mButtonCornerRadius; 129 /// The border width for TabHeader widgets (default: `0.75f`). 130 float mTabBorderWidth; 131 /// The inner margin on a TabHeader widget (default: `5`). 132 int mTabInnerMargin; 133 /// The minimum size for buttons on a TabHeader widget (default: `20`). 134 int mTabMinButtonWidth; 135 /// The maximum size for buttons on a TabHeader widget (default: `160`). 136 int mTabMaxButtonWidth; 137 /// Used to help specify what lies "in bound" for a TabHeader widget (default: `20`). 138 int mTabControlWidth; 139 /// The amount of horizontal padding for a TabHeader widget (default: `10`). 140 int mTabButtonHorizontalPadding; 141 /// The amount of vertical padding for a TabHeader widget (default: `2`). 142 int mTabButtonVerticalPadding; 143 144 int mResizeAreaOffset; 145 146 /* Generic colors */ 147 /** 148 * The color of the drop shadow drawn behind widgets 149 * (default: intensity=`0`, alpha=`128`; see `nanogui.Color.Color(int,int)`). 150 */ 151 Color mDropShadow; 152 /** 153 * The transparency color 154 * (default: intensity=`0`, alpha=`0`; see `nanogui.Color.Color(int,int)`). 155 */ 156 Color mTransparent; 157 /** 158 * The dark border color 159 * (default: intensity=`29`, alpha=`255`; see `nanogui.Color.Color(int,int)`). 160 */ 161 Color mBorderDark; 162 /** 163 * The light border color 164 * (default: intensity=`92`, alpha=`255`; see `nanogui.Color.Color(int,int)`). 165 */ 166 Color mBorderLight; 167 /** 168 * The medium border color 169 * (default: intensity=`35`, alpha=`255`; see `nanogui.Color.Color(int,int)`). 170 */ 171 Color mBorderMedium; 172 /** 173 * The text color 174 * (default: intensity=`255`, alpha=`160`; see `nanogui.Color.Color(int,int)`). 175 */ 176 Color mTextColor; 177 /** 178 * The disable dtext color 179 * (default: intensity=`255`, alpha=`80`; see `nanogui.Color.Color(int,int)`). 180 */ 181 Color mDisabledTextColor; 182 /** 183 * The text shadow color 184 * (default: intensity=`0`, alpha=`160`; see `nanogui.Color.Color(int,int)`). 185 */ 186 Color mTextColorShadow; 187 /// The icon color (default: \ref nanogui::Theme::mTextColor). 188 Color mIconColor; 189 190 /* Button colors */ 191 /** 192 * The top gradient color for buttons in focus 193 * (default: intensity=`64`, alpha=`255`; see `nanogui.Color.Color(int,int)`). 194 */ 195 Color mButtonGradientTopFocused; 196 /** 197 * The bottom gradient color for buttons in focus 198 * (default: intensity=`48`, alpha=`255`; see `nanogui.Color.Color(int,int)`). 199 */ 200 Color mButtonGradientBotFocused; 201 /** 202 * The top gradient color for buttons not in focus 203 * (default: intensity=`74`, alpha=`255`; see `nanogui.Color.Color(int,int)`). 204 */ 205 Color mButtonGradientTopUnfocused; 206 /** 207 * The bottom gradient color for buttons not in focus 208 * (default: intensity=`58`, alpha=`255`; see `nanogui.Color.Color(int,int)`). 209 */ 210 Color mButtonGradientBotUnfocused; 211 /** 212 * The top gradient color for buttons currently pushed 213 * (default: intensity=`41`, alpha=`255`; see `nanogui.Color.Color(int,int)`). 214 */ 215 Color mButtonGradientTopPushed; 216 /** 217 * The bottom gradient color for buttons currently pushed 218 * (default: intensity=`29`, alpha=`255`; see `nanogui.Color.Color(int,int)`). 219 */ 220 Color mButtonGradientBotPushed; 221 222 /* Window colors */ 223 /** 224 * The fill color for a Window that is not in focus 225 * (default: intensity=`43`, alpha=`230`; see `nanogui.Color.Color(int,int)`). 226 */ 227 Color mWindowFillUnfocused; 228 /** 229 * The fill color for a Window that is in focus 230 * (default: intensity=`45`, alpha=`230`; see `nanogui.Color.Color(int,int)`). 231 */ 232 Color mWindowFillFocused; 233 /** 234 * The title color for a Window that is not in focus 235 * (default: intensity=`220`, alpha=`160`; see `nanogui.Color.Color(int,int)`). 236 */ 237 Color mWindowTitleUnfocused; 238 /** 239 * The title color for a Window that is in focus 240 * (default: intensity=`255`, alpha=`190`; see `nanogui.Color.Color(int,int)`). 241 */ 242 Color mWindowTitleFocused; 243 244 /** 245 * The top gradient color for Window headings 246 * (default: \ref nanogui::Theme::mButtonGradientTopUnfocused). 247 */ 248 Color mWindowHeaderGradientTop; 249 /** 250 * The bottom gradient color for Window headings 251 * (default: \ref nanogui::Theme::mButtonGradientBotUnfocused). 252 */ 253 Color mWindowHeaderGradientBot; 254 /// The Window header top separation color (default: `nanogui.Theme.mBorderLight`). 255 Color mWindowHeaderSepTop; 256 /// The Window header bottom separation color (default: `nanogui.Theme.mBorderDark`). 257 Color mWindowHeaderSepBot; 258 259 /** 260 * The popup window color 261 * (default: intensity=`50`, alpha=`255`; see `nanogui.Color.Color(int,int)`). 262 */ 263 Color mWindowPopup; 264 /** 265 * The transparent popup window color 266 * (default: intensity=`50`, alpha=`0`; see `nanogui.Color.Color(int,int)`). 267 */ 268 Color mWindowPopupTransparent; 269 270 /// Icon to use for CheckBox widgets (default: `Entypo.ICON_CHECK`). 271 dchar mCheckBoxIcon; 272 /// Icon to use for informational MessageDialog widgets (default: `Entypo.ICON_INFO_WITH_CIRCLE`). 273 dchar mMessageInformationIcon; 274 /// Icon to use for interrogative MessageDialog widgets (default: `Entypo.ICON_HELP_WITH_CIRCLE`). 275 dchar mMessageQuestionIcon; 276 /// Icon to use for warning MessageDialog widgets (default: `Entypo.ICON_WARNING`). 277 dchar mMessageWarningIcon; 278 /// Icon to use on MessageDialog alt button (default: `Entypo.ICON_CIRCLE_WITH_CROSS`). 279 dchar mMessageAltButtonIcon; 280 /// Icon to use on MessageDialog primary button (default: `Entypo.ICON_CHECK`). 281 dchar mMessagePrimaryButtonIcon; 282 /// Icon to use for PopupButton widgets opening to the right (default: `Entypo.ICON_CHEVRON_RIGHT`). 283 dchar mPopupChevronRightIcon; 284 /// Icon to use for PopupButton widgets opening to the left (default: `Entypo.ICON_CHEVRON_LEFT`). 285 dchar mPopupChevronLeftIcon; 286 /// Icon to indicate hidden tabs to the left on a TabHeader (default: `Entypo.ICON_ARROW_BOLD_LEFT`). 287 dchar mTabHeaderLeftIcon; 288 /// Icon to indicate hidden tabs to the right on a TabHeader (default: `Entypo.ICON_ARROW_BOLD_RIGHT`). 289 dchar mTabHeaderRightIcon; 290 /// Icon to use when a TextBox has an up toggle (e.g. IntBox) (default: `Entypo.ICON_CHEVRON_UP`). 291 dchar mTextBoxUpIcon; 292 /// Icon to use when a TextBox has a down toggle (e.g. IntBox) (default: `Entypo.ICON_CHEVRON_DOWN`). 293 dchar mTextBoxDownIcon; 294 295 protected: 296 /// Default destructor does nothing; allows for inheritance. 297 ~this() { } 298 }