Coverage Report

Created: 2025-11-11 07:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wt/src/Wt/WIcon.h
Line
Count
Source
1
// This may look like C code, but it's really -*- C++ -*-
2
/*
3
 * Copyright (C) 2013 Emweb bv, Herent, Belgium.
4
 *
5
 * See the LICENSE file for terms of use.
6
 */
7
#ifndef WICON_H_
8
#define WICON_H_
9
10
#include <Wt/WInteractWidget.h>
11
12
namespace Wt {
13
14
/*! \class WIcon Wt/WIcon.h Wt/WIcon.h
15
 *  \brief A widget that represents a Font-Aweswome icon.
16
 *
17
 * By default, Wt will load the default Font-Awesome included with it.
18
 * This is version 4.3.0. For a list of all icons, visit:
19
 * https://fontawesome.com/v4/icons/
20
 *
21
 * \see setName()
22
 */
23
class WT_API WIcon : public WInteractWidget
24
{
25
public:
26
  //! Creates an empty icon.
27
  WIcon();
28
29
  /*! \brief Creates an icon with the given name.
30
   *
31
   * \see setName()
32
   */
33
  WIcon(const std::string& name);
34
35
  /*! \brief Set the icon name.
36
   *
37
   * This sets the name of the icon. The name should be a the name of a
38
   * Font-Aweswome icon, without the `fa-` prefix.
39
   *
40
   * Usage example:
41
   * The "play" icon: https://fontawesome.com/v4/icon/play
42
   * can be included with:
43
   * \if cpp
44
   * \code
45
   *  auto app = Wt::WApplication::instance();
46
   *  app->root()->addNew<WIcon>("play");
47
   * \endcode
48
   * \elseif java
49
   * \code
50
   *  WApplication app = WApplication.getInstance();
51
   *  app.getRoot().addWidget(new WIcon("play"));
52
   * \endcode
53
   * \endif
54
   *
55
   * \note The name can be followed by sizing information
56
   *       separated by a space if the Font Aweswome version
57
   *       used allows it. E.g. \p "play fa-4"
58
   */
59
  void setName(const std::string& name);
60
61
  /*! \brief Returns the icon name.
62
   *
63
   * \see setName()
64
   */
65
0
  std::string name() const { return name_; }
66
67
  /*! \brief Changes the icon's size.
68
   *
69
   * \note This is done in CSS, not using the `fa-{size}` method.
70
   */
71
  void setSize(double factor);
72
73
  /*! \brief Returns the icon size.
74
   *
75
   * \see setSize()
76
   */
77
  double size() const;
78
79
  /*! \brief Loads the Font-Aweswome css style sheet.
80
   *
81
   * This is a convenience function that adds Font-Aweswome's CSS style
82
   * sheet to the list of used style sheets.
83
   *
84
   * By default this will load the stylesheet present at:
85
   * \p resources/font-awesome/css/font-awesome.min.css
86
   * The \p resources directory can be set with a command-line option,
87
   * namely \p --resources-dir,
88
   * see <a href="https://www.webtoolkit.eu/wt/doc/reference/html/overview.html#config_wthttpd">Wt's configuration options</a>.
89
   *
90
   * \note This is automatically called when needed by
91
   *       WIcon.
92
   */
93
  static void loadIconFont();
94
95
protected:
96
  virtual void updateDom(DomElement& element, bool all) override;
97
  virtual DomElementType domElementType() const override;
98
  virtual void propagateRenderOk(bool deep) override;
99
100
private:
101
  std::string name_;
102
  bool iconChanged_;
103
};
104
105
}
106
107
#endif // WICON_H_