Widget.hpp

Widgets maintain individual components on a web page and link to Elements.

Each HTML Widget has all of its details stored in a WidgetInfo object; Multiple Widgets can be attached to the same WidgetInfo, simplifying the usage. All the library user needs to worry about is the Widget object itself; the WidgetInfo will be managed behind the scenes.

WidgetInfo contains the basic information for all Widgets Widget is a generic base class, with a shared pointer to WidgetInfo WidgetFacet is a template that allows Set* methods to return derived return-type.

In other files, Widgets will be used to define specific elements. ELEMENTInfo maintains information about the specific widget (derived from WidgetInfo) ELEMENT interfaces to ELEMENTInfo so multiple elements use same core; derived from WidgetFacet

Library users should not need to access Widgets directly, only specific derived types.

Tips for using widgets:

  1. If you are about to make a lot of changes at once, run Freeze(), make the changes, and then run Activate() again. Freeze prevents widgets from being updated immediately.

  2. Trust the Widget to handle all of the manipulation behind the scenes

class Widget
#include <Widget.hpp>

Widget is effectively a smart pointer to a WidgetInfo object, plus some basic accessors.

Subclassed by DocuExtras

Public Functions

Widget(const std::string &id)

When Widgets are first created, they should be provided with an ID.

Widget(WidgetInfo *in_info = nullptr)
inline Widget(const Widget &in)
inline Widget &operator=(const Widget &in)
virtual ~Widget()
inline bool IsNull() const

Test if this widget is valid.

std::string GetInfoTypeName() const

Some debugging helpers…

bool IsInactive() const

Test if the activity state of this widget is currently INACTIVE.

bool IsWaiting() const

Test if the activity state of this widget is currently WAITING.

bool IsFrozen() const

Test if the activity state of this widget is currently FROZEN.

bool IsActive() const

Test if the activity state of this widget is currently ACTIVE.

bool AppendOK() const

Is it okay to add more internal Widgets into this one?

void PreventAppend()

Disallow further appending to this Widget.

inline bool IsButton() const
inline bool IsCanvas() const
inline bool IsDiv() const
inline bool IsImage() const
inline bool IsInput() const
inline bool IsSelector() const
inline bool IsTable() const
inline bool IsText() const
inline bool IsTextArea() const
inline bool IsTextFeed() const
inline bool IsD3Visualization() const
const std::string &GetID() const

What is the HTML string ID for this Widget?

virtual const std::string &GetCSS(const std::string &setting) const

Retrieve a specific CSS trait associated with this Widget. Note: CSS-related options may be overridden in derived classes that have multiple styles.

virtual bool HasCSS(const std::string &setting)

Determine is a CSS trait has been set on this Widget.

virtual const std::string &GetAttr(const std::string &setting) const

Retrieve a specific attribute associated with this Widget.

virtual bool HasAttr(const std::string &setting)

Determine is an attribute has been set on this Widget.

inline bool operator==(const Widget &in) const

Are two Widgets refering to the same HTML object?

inline bool operator!=(const Widget &in) const

Are two Widgets refering to different HTML objects?

inline operator bool() const

Conver Widget to bool (I.e., is this Widget active?)

inline const std::string &GetTitle() const
double GetXPos()

Get current tooltip on this widget.

Get the X-position of this Widget within its parent.

double GetYPos()

Get the Y-position of this Widget within its parent.

double GetWidth()

Get the width of this Widget on screen.

double GetHeight()

Get the height of this Widget on screen.

double GetInnerWidth()

Get the width of this Widget not including padding.

double GetInnerHeight()

Get the height of this Widget not including padding.

double GetOuterWidth()

Get the width of this Widget including all padding.

double GetOuterHeight()

Get the height of this Widget including all padding.

void Activate()

Make this widget live, so changes occur immediately (once document is ready)

void Freeze()

Record changes internally, but keep static screen until Activate() is called.

virtual void Deactivate(bool top_level = true)

Record changes internally and REMOVE from screen until Activate is called. (Argument is for recursive, internal use only.)

bool ToggleActive()

Toggle between Active and Deactivated.

void Redraw()

Clear and redraw the current widget on the screen.

Widget &Find(const std::string &test_name)

Look up previously created elements, by type.

Widget &AddDependant(const Widget &w)

Add a dependant to this Widget that should be redrawn when it is.

inline virtual void PrepareAppend()

Setup << operator to redirect to Append; option preparation can be overridden.

template<typename IN_TYPE>
Widget operator<<(IN_TYPE &&in_val)
std::string GetInfoType() const

Debug…

Protected Types

enum ActivityState

Four activity states for any widget: INACTIVE - Not be in DOM at all. WAITING - Will become active once the page finishes loading. FROZEN - Part of DOM, but not updating on the screen. ACTIVE - Fully active; changes are reflected as they happen.

Values:

enumerator INACTIVE
enumerator WAITING
enumerator FROZEN
enumerator ACTIVE

Protected Functions

template<typename FWD_TYPE>
Widget &ForwardAppend(FWD_TYPE &&arg)

If an Append doesn’t work with current class, forward it to the parent and try there.

Widget &SetInfo(WidgetInfo *in_info)

Set the information associated with this widget.

inline WidgetInfo *operator->()

Internally, we can treat a Widget as a pointer to its WidgetInfo.

Protected Attributes

WidgetInfo *info

Information associated with this widget.

Protected Static Functions

static inline WidgetInfo *Info(const Widget &w)

Give derived classes the ability to access widget info.

Protected Static Attributes

static const std::string no_name = "(none)"

Default name for un-initialized widgets.