Feature #13813 ยป wt_WIcon_Bootstrap.patch
| src/Wt/WIcon.C | ||
|---|---|---|
|
namespace Wt {
|
||
|
|
||
|
WIcon::WIcon()
|
||
|
: iconChanged_(false)
|
||
|
: iconChanged_(false), iconSet_(IconFamily::FontAwesome)
|
||
|
{ }
|
||
|
|
||
|
WIcon::WIcon(IconFamily iconFam)
|
||
|
: iconChanged_(false), iconSet_(iconFam)
|
||
|
{ }
|
||
|
|
||
|
WIcon::WIcon(const std::string& name)
|
||
|
: iconChanged_(false)
|
||
|
: iconChanged_(false), iconSet_(IconFamily::FontAwesome)
|
||
|
{
|
||
|
setName(name);
|
||
|
}
|
||
|
|
||
|
WIcon::WIcon(const std::string& name, IconFamily iconFam)
|
||
|
: iconChanged_(false), iconSet_(iconFam)
|
||
|
{
|
||
|
setName(name);
|
||
|
}
|
||
| ... | ... | |
|
}
|
||
|
}
|
||
|
|
||
|
void WIcon::setIconFamily(IconFamily iconFam)
|
||
|
{
|
||
|
if(iconSet_ != iconFam)
|
||
|
{
|
||
|
iconSet_ = iconFam;
|
||
|
iconChanged_ = true;
|
||
|
repaint();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void WIcon::setSize(double factor)
|
||
|
{
|
||
|
decorationStyle().font().setSize(WLength(factor, LengthUnit::FontEm));
|
||
| ... | ... | |
|
sc = styleClass().toUTF8();
|
||
|
|
||
|
if (!name_.empty())
|
||
|
sc = Utils::addWord(sc, "fa fa-" + name_);
|
||
|
{
|
||
|
switch (iconSet_)
|
||
|
{
|
||
|
case IconFamily::FontAwesome:
|
||
|
sc = Utils::addWord(sc, "fa fa-" + name_);
|
||
|
break;
|
||
|
case IconFamily::Bootstrap:
|
||
|
sc = Utils::addWord(sc, "bi bi-" + name_);
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
sc = Utils::addWord(sc, "fa fa-" + name_);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
element.setProperty(Property::Class, sc);
|
||
|
|
||
| src/Wt/WIcon.h | ||
|---|---|---|
|
|
||
|
namespace Wt {
|
||
|
|
||
|
/**
|
||
|
* @brief Enum to switch between Icon Families
|
||
|
*
|
||
|
*/
|
||
|
enum class IconFamily
|
||
|
{
|
||
|
FontAwesome,
|
||
|
Bootstrap
|
||
|
};
|
||
|
|
||
|
/*! \class WIcon Wt/WIcon.h Wt/WIcon.h
|
||
|
* \brief A widget that represents a Font-Aweswome icon.
|
||
|
* \brief A widget that represents a Font-Aweswome icon but can also used to
|
||
|
* represent Bootstrap Icons.
|
||
|
*
|
||
|
* By default, Wt will load the default Font-Awesome included with it.
|
||
|
* This is version 4.3.0. For a list of all icons, visit:
|
||
| ... | ... | |
|
class WT_API WIcon : public WInteractWidget
|
||
|
{
|
||
|
public:
|
||
|
//! Creates an empty icon.
|
||
|
// ! Creates an empty icon.
|
||
|
WIcon();
|
||
|
|
||
|
//! Creates an empty icon with a Icon Family Set
|
||
|
WIcon(IconFamily iconFam);
|
||
|
|
||
|
/*! \brief Creates an icon with the given name.
|
||
|
*
|
||
|
* Defaults to IconFamily Font-Awesome
|
||
|
* \see setName()
|
||
|
*/
|
||
|
WIcon(const std::string& name);
|
||
|
|
||
|
/*! \brief Creates an icon with the given name and IconFamily.
|
||
|
*
|
||
|
* \see setName()
|
||
|
*/
|
||
|
WIcon(const std::string& name, IconFamily iconFam);
|
||
|
|
||
|
/*! \brief Set the icon name.
|
||
|
*
|
||
|
* This sets the name of the icon. The name should be a the name of a
|
||
|
* Font-Aweswome icon, without the `fa-` prefix.
|
||
|
* For Bootstrap Icons, without the `bi-` prefix.
|
||
|
*
|
||
|
* Usage example:
|
||
|
* Usage example Font-Awesome:
|
||
|
* The "play" icon: https://fontawesome.com/v4/icon/play
|
||
|
* can be included with:
|
||
|
* \if cpp
|
||
| ... | ... | |
|
* \endcode
|
||
|
* \endif
|
||
|
*
|
||
|
*
|
||
|
* Usage example Bootstrap Icons:
|
||
|
* The "play" icon: https://icons.getbootstrap.com/icons/play/
|
||
|
* can be included with:
|
||
|
* \if cpp
|
||
|
* \code
|
||
|
* auto app = Wt::WApplication::instance();
|
||
|
* app->root()->addNew<WIcon>("play", IconFamily::Bootstrap);
|
||
|
* \endcode
|
||
|
* \elseif java
|
||
|
* \code
|
||
|
* WApplication app = WApplication.getInstance();
|
||
|
* app.getRoot().addWidget(new WIcon("play", IconFamily::Bootstrap));
|
||
|
* \endcode
|
||
|
* \endif
|
||
|
*
|
||
|
* \note The name can be followed by sizing information
|
||
|
* separated by a space if the Font Aweswome version
|
||
|
* used allows it. E.g. \p "play fa-4"
|
||
|
* used allows it. E.g. \p "play fa-4".
|
||
|
*
|
||
|
* \note For Bootstrap Icons, additional style classes can be set after the name.
|
||
|
* E.g. \p "play opacity-50"
|
||
|
*/
|
||
|
void setName(const std::string& name);
|
||
|
|
||
| ... | ... | |
|
*/
|
||
|
std::string name() const { return name_; }
|
||
|
|
||
|
/*! \brief Set the icon Family.
|
||
|
*
|
||
|
* This sets the Family of the icon.
|
||
|
*
|
||
|
*/
|
||
|
void setIconFamily(IconFamily iconFam);
|
||
|
|
||
|
/*! \brief Returns the icon family.
|
||
|
*
|
||
|
* \see setIconFamily()
|
||
|
*/
|
||
|
IconFamily iconFamily() const { return iconSet_; }
|
||
|
|
||
|
/*! \brief Changes the icon's size.
|
||
|
*
|
||
|
* \note This is done in CSS, not using the `fa-{size}` method.
|
||
| ... | ... | |
|
private:
|
||
|
std::string name_;
|
||
|
bool iconChanged_;
|
||
|
IconFamily iconSet_;
|
||
|
};
|
||
|
|
||
|
}
|
||