Line | Count | Source |
1 | | // This may look like C code, but it's really -*- C++ -*- |
2 | | /* |
3 | | * Copyright (C) 2026 Emweb bv, Herent, Belgium. |
4 | | * |
5 | | * See the LICENSE file for terms of use. |
6 | | */ |
7 | | #ifndef WBADGE_H_ |
8 | | #define WBADGE_H_ |
9 | | |
10 | | #include "Wt/WText.h" |
11 | | |
12 | | namespace Wt { |
13 | | |
14 | | /*! \class WBadge Wt/WBadge.h Wt/WBadge.h |
15 | | * \brief A widget that represent a badge. |
16 | | * |
17 | | * A badge is a short text, often shown against a contrasting |
18 | | * background, which is used to convey important information at a |
19 | | * glance. |
20 | | * |
21 | | * For instance, in a shopping application, a badge with the |
22 | | * word "new" can be added to an article to show that this article |
23 | | * was recently added. |
24 | | * |
25 | | * Another example is to add a badge next to the channel in a chat |
26 | | * application to show the number of unread messages in that channel. |
27 | | * |
28 | | * A WBadge is an inline WText with a specific look. This look is |
29 | | * defined in any of %Wt's themes. Either they are "Wt-badge" for the |
30 | | * polished and default theme, or "badge" for any of the bootstrap |
31 | | * themes. For more information on the latter visit [Bootstrap's |
32 | | * documentation](https://getbootstrap.com/docs/5.3/components/badge) |
33 | | * |
34 | | * \sa WPushButton::setBadge(), WMenuItem::setBadge() |
35 | | * |
36 | | * \note With default %Wt themes, empty WBadges will not be shown. |
37 | | */ |
38 | | class WT_API WBadge: public WText |
39 | | { |
40 | | public: |
41 | | /*! \brief Creates an empty badge. |
42 | | * |
43 | | * \sa WText::WText() |
44 | | */ |
45 | | WBadge(); |
46 | | |
47 | | /*! \brief Creates a badge with the given text. |
48 | | * |
49 | | * \sa WText::WText(const WString&) |
50 | | */ |
51 | | WBadge(const WString& text); |
52 | | |
53 | | /*! \brief Creates a badge with the given text and format. |
54 | | * |
55 | | * \sa WText::WText(const WString&,TextFormat) |
56 | | */ |
57 | | WBadge(const WString& text, TextFormat textFormat); |
58 | | |
59 | 0 | bool isInline() const override { return true; } |
60 | | |
61 | | /*! \brief Sets whether the badge should use the default theme style |
62 | | * |
63 | | * If set to true, the badge will use the default theme style defined |
64 | | * in the current theme. |
65 | | * |
66 | | * We recommend setting this to false if you want to customize the |
67 | | * badge's style using setDecorationStyle() to avoid having the |
68 | | * default style overriding your custom style. This is currently only |
69 | | * important for the Bootstrap 5 theme. |
70 | | * |
71 | | * By default, this is set to true. |
72 | | */ |
73 | | void setUseDefaultStyle(bool use); |
74 | | |
75 | | /*! \brief Returns whether the badge uses the default style |
76 | | * |
77 | | * \sa setUseDefaultStyle() |
78 | | */ |
79 | 0 | bool useDefaultStyle() const { return useDefaultStyle_; } |
80 | | |
81 | | protected: |
82 | | void updateDom(DomElement& element, bool all) override; |
83 | | |
84 | | private: |
85 | | static const int BIT_USE_DEFAULT_STYLE_CHANGED = 0; |
86 | | |
87 | | std::bitset<1> flags_; |
88 | | |
89 | | bool useDefaultStyle_; |
90 | | }; |
91 | | |
92 | | } |
93 | | |
94 | | #endif //WBADGE_H_ |