OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef UI_VIEWS_STYLE_TYPOGRAPHY_H_ | |
6 #define UI_VIEWS_STYLE_TYPOGRAPHY_H_ | |
7 | |
8 #include "ui/views/views_export.h" | |
9 | |
10 namespace views { | |
11 | |
12 // An enum class that can be extended by embedders without losing type safety or | |
13 // the ability to use values in switch statements. Except for the way the values | |
14 // are declared, the syntax for using an ExtendableEnum should be the same as a | |
15 // regular enum class. Uses default copy constructor and assignment operators | |
16 // but note that conversion/assignment between different template types is not | |
17 // permitted. | |
18 template <class ENUM> | |
19 class ExtendableEnum { | |
20 public: | |
21 // Used to declare the enum constants. | |
22 class Value; // Inherits from this, so can't be defined inline. | |
23 | |
24 // The enum value, available at compile time when using a Value directly. | |
25 constexpr int value() const { return value_; } | |
26 | |
27 protected: | |
28 explicit constexpr ExtendableEnum(int value) : value_(value) {} | |
29 | |
30 private: | |
31 int value_; | |
32 }; | |
33 | |
34 template <class ENUM> | |
35 class ExtendableEnum<ENUM>::Value : public ExtendableEnum<ENUM> { | |
36 public: | |
37 // Allows use in switch case statements. | |
38 constexpr operator int() const { return this->value(); } | |
39 | |
40 // Allow implicit initialization from an integer literal. | |
41 constexpr Value(int const_value) : ExtendableEnum(const_value) {} | |
42 }; | |
43 | |
44 // Where a piece of text appears in the UI. This influences size and weight, but | |
45 // typically not style or color. | |
46 class VIEWS_EXPORT TextContext : public ExtendableEnum<TextContext> { | |
47 public: | |
48 // A title for a dialog window. Usually 15pt. Multi-line OK. | |
49 static constexpr const Value DIALOG_TITLE = 1; | |
Peter Kasting
2017/03/15 10:01:48
I don't think you need both constexpr and const on
tapted
2017/03/16 11:13:39
You are correct! (but, no longer using this)
| |
50 | |
51 // "Body 2". Usually 12pt. | |
52 static constexpr const Value CONTROL_LABEL = 3; | |
Peter Kasting
2017/03/15 10:01:48
Skipped 2
tapted
2017/03/16 11:13:39
no longer using this (it is perilous, clearly ;)
| |
53 | |
54 // A text field. Usually matches CONTROL_LABEL. | |
55 static constexpr const Value FIELD = 4; | |
56 | |
57 // Text that appears on a button control. Usually 12pt. | |
58 static constexpr const Value BUTTON_TEXT = 5; | |
59 | |
60 // Allow implicit conversion from the constants above. | |
61 constexpr TextContext(const Value& value) : ExtendableEnum(value.value()) {} | |
62 | |
63 // Allow declaration without assignment. | |
64 constexpr TextContext() : ExtendableEnum(0) {} | |
65 | |
66 protected: | |
67 enum { VIEWS_MAX = 15 }; | |
Peter Kasting
2017/03/15 10:01:48
15? (2 places)
tapted
2017/03/15 11:04:07
I guess I was going for
- a buffer
- not too big
Peter Kasting
2017/03/15 17:52:47
Do we need a buffer? That's only important if the
tapted
2017/03/16 11:13:39
buffer thinking was that there would be less chanc
| |
68 }; | |
69 | |
70 // How a piece of text should be presented. This influences color and style, but | |
71 // typically not size. | |
72 class VIEWS_EXPORT TextStyle : public ExtendableEnum<TextStyle> { | |
73 public: | |
74 // Primary text: solid black, normal weight. Converts to DISABLED in some | |
75 // contexts (e.g. BUTTON_TEXT, FIELD). | |
76 static constexpr const Value PRIMARY = 1; | |
77 | |
78 // Disabled "greyed out" text. | |
79 static constexpr const Value DISABLED = 2; | |
80 | |
81 // A solid shade of blue. | |
82 static constexpr const Value LINK = 3; | |
83 | |
84 // Active tab in a tabbed pane. | |
85 static constexpr const Value ACTIVE_TAB = 4; | |
86 | |
87 // Inactive tab in a tabbed pane. | |
88 static constexpr const Value INACTIVE_TAB = 5; | |
89 | |
90 // Hovered tab in a tabbed pane. | |
91 static constexpr const Value HOVERED_TAB = 6; | |
92 | |
93 constexpr TextStyle(const Value& value) : ExtendableEnum(value.value()) {} | |
94 constexpr TextStyle() : ExtendableEnum(0) {} | |
95 | |
96 protected: | |
97 enum { VIEWS_MAX = 15 }; | |
98 }; | |
99 | |
100 } // namespace views | |
101 | |
102 #endif // UI_VIEWS_STYLE_TYPOGRAPHY_H_ | |
OLD | NEW |