CanvasCV: canvascv::Widget Class Reference
CanvasCV  1.0.0

The Widget class. More...

#include <widget.h>

Inheritance diagram for canvascv::Widget:
canvascv::CompoundWidget canvascv::MatWidget canvascv::Text canvascv::AutoLayout canvascv::CheckBoxes canvascv::MsgBox canvascv::RadioButtons canvascv::SelectionBox canvascv::Button canvascv::HorizontalLayout canvascv::VerticalLayout canvascv::HFrame canvascv::VFrame

Public Types

typedef std::function< void(Widget *)> CBWidget
 signature of a callback which only gets the widget
 
typedef std::function< void(Widget *, State)> CBWidgetState
 signature of a callback which gets the State
 
typedef std::function< void(Widget *, int)> CBUserSelection
 signature of a callback which gets a user selection
 

Public Member Functions

 Widget (const cv::Point &pos=cv::Point(0, 0))
 constructor
 
virtual ~Widget ()
 virtual destructor
 
virtual const char * getType () const =0
 getType is always implemented by derived to return the same static pointer per widget. More...
 
void notifyOnChange (CBWidgetState cb)
 used to register for notifications on a widget More...
 
cv::Scalar getOutlineColor () const
 get the outline color
 
virtual void setOutlineColor (const cv::Scalar &value)
 set the outline color
 
cv::Scalar getFillColor () const
 get the bg color
 
virtual void setFillColor (const cv::Scalar &value)
 set the bg color
 
bool getVisible () const
 is the widget visible
 
virtual void setVisible (bool value)
 set the widget visible state
 
int getThickness () const
 get line thickness to use when drawing
 
virtual void setThickness (int value)
 set line thickness to use when drawing
 
int getLineType () const
 get the line type (LINE_4, LINE_8, LINE_AA)
 
virtual void setLineType (int value)
 set the line type (LINE_4, LINE_8, LINE_AA)
 
uchar getAlpha () const
 get the alpha value used for the widge background [0,255] => [transparent,opaque]
 
void setAlpha (uchar value)
 set the alpha value used for the widge background [0,255] => [transparent,opaque]
 
Anchor getLayoutAnchor () const
 getLayoutAnchor returns the anchor for using in the Layout we're in More...
 
void setLayoutAnchor (const Anchor &value)
 setLayoutAnchor sets the anchor for using in the Layout we're in More...
 
Anchor getFlowAnchor () const
 getFlowAnchor get internal widget alignment and direction of growth More...
 
void setFlowAnchor (const Anchor &value)
 setFlowAnchor set internal widget alignment and direction of growth More...
 
int getId ()
 Widgets have a unique id per instance.
 
virtual const std::string & getStatusMsg () const
 getStatusMsg More...
 
void setStatusMsg (const std::string &value)
 setStatusMsg More...
 
const cv::Point & getLocation () const
 get widget position in Canvas
 
virtual void setLocation (const cv::Point &value)
 set widget position in Canvas
 
virtual void translate (const cv::Point &translation)
 move the widget
 
bool getStretchX () const
 get if the Layout we're in should stretch us in the X direction
 
void setStretchX (bool value)
 set if the Layout we're in should stretch us in the X direction (and calls setStretchXToParent(false))
 
bool getStretchY () const
 get if the Layout we're in should stretch us in the Y direction
 
void setStretchY (bool value)
 set if the Layout we're in should stretch us in the Y direction (and calls setStretchYToParent(false))
 
cv::Scalar getSelectColor () const
 get the color to use when a widget is selected
 
virtual void setSelectColor (const cv::Scalar &value)
 set the color to use when a widget is selected
 
std::shared_ptr< WidgetrmvFromLayout ()
 get rid of the widget
 
bool getIsSelectable () const
 get if the widget should appear as selected when the mouse is over it
 
void setIsSelectable (bool value)
 set if the widget should appear as selected when the mouse is over it
 
int getForcedWidth () const
 get the forced width for this widget
 
void setForcedWidth (int value)
 set the forced width for this widget (and calls setStretchX/setStretchXToParent(false))
 
int getForcedHeight () const
 get the forced height for this widget
 
void setForcedHeight (int value)
 set the forced height for this widget (and calls setStretchY/setStretchYToParent(false))
 
void update ()
 removes 'dirty' state and invokes the derived 'recalc/recalcCompound'
 
bool isRemoved () const
 returns true if the widget has no layout and false if it does
 
virtual const cv::Rect & getRect ()=0
 Actual size the widget is occupying due to Layout manager.
 
bool getStretchXToParent () const
 get if this widget streches to parent layout width
 
void setStretchXToParent (bool value)
 set if this widget streches to parent layout width (and calls setStretchX(false))
 
bool getStretchYToParent () const
 get if this widget streches to parent layout height
 
void setStretchYToParent (bool value)
 set if this widget streches to parent layout height (and calls setStretchY(false))
 

Protected Member Functions

void setStateChangesBG ()
 widgets like buttons change bg on mouse events
 
void allocateBG (const cv::Size &size)
 invokes Theme::allocateBG()
 
virtual void recalc ()=0
 update self so next call to 'draw' will display correctly
 
void flatWidget ()
 delegate to Theme
 
void raisedWidget ()
 delegate to Theme
 
void sunkenWidget ()
 delegate to Theme
 
void selectedWidget ()
 delegate to Theme
 
virtual void renderOn (cv::Mat &dst)
 render the widget to dst More...
 
virtual void drawFG (cv::Mat &dst)=0
 dst is the roi of the widget size and not the full image
 
void callDrawFG (bool preAllocateMat=true)
 helper method which delgates to drawFG for derived
 
virtual const cv::Rect & getMinimalRect ()=0
 Minimal size the widget coould have occupy.
 
bool setDirty ()
 setDirty More...
 
virtual bool isAtPos (const cv::Point &pos)
 isAtPos More...
 

Detailed Description

Note
All widgets have a static create methods, which is the only way to create them. The create will return a shared_ptr<T> instance, which you don't have to keep since another one is kept by the Layout in which the widget is placed. Never use delete on a Widget pointer.
Examples:
example_add_theme.cpp, example_add_widget.cpp, example_checkboxes.cpp, example_msgbox.cpp, example_radiobuttons.cpp, example_selectbox.cpp, and example_shapes_widgets.cpp.

Member Enumeration Documentation

Used for both aligment in the Layout we belong to and internal widget alignments

See also
getLayoutAnchor(), setLayoutAnchor(), getFlowAnchor(), setFlowAnchor()
Enumerator
TOP 

top

BOTTOM 

bottom

LEFT 

left

RIGHT 

right

CENTER 

center

TOP_LEFT 

top-left

TOP_RIGHT 

top-right

BOTTOM_LEFT 

bottom-left

BOTTOM_RIGHT 

bottom-right

CENTER_TOP 

center-top

CENTER_BOTTOM 

center-bottom

CENTER_LEFT 

center-left

CENTER_RIGHT 

center-right

Enumerator
ENTER 

got gocus

LEAVE 

lost focus

PRESS 

mouse pressed

RELEASE 

mouse left

Member Function Documentation

Anchor canvascv::Widget::getFlowAnchor ( ) const
inline
Returns
the Anchor of our own flow
See also
VerticalLayout, HorizontalLayout, Text
Anchor canvascv::Widget::getLayoutAnchor ( ) const
inline
Returns
the Anchor related to the Layout we're in
See also
VerticalLayout, HorizontalLayout
virtual const std::string& canvascv::Widget::getStatusMsg ( ) const
virtual
Returns
a message to display during mouse hover
See also
Canvas::enableStatusMsg

Reimplemented in canvascv::CompoundWidget.

virtual const char* canvascv::Widget::getType ( ) const
pure virtual
virtual bool canvascv::Widget::isAtPos ( const cv::Point &  pos)
protectedvirtual
Parameters
pos
Returns
true or false if at location

Reimplemented in canvascv::CompoundWidget.

void canvascv::Widget::notifyOnChange ( CBWidgetState  cb)
Parameters
cbto invoke on widget state change
Examples:
example_add_widget.cpp.
virtual void canvascv::Widget::renderOn ( cv::Mat &  dst)
protectedvirtual
Parameters
dstis the full size image

Reimplemented in canvascv::CompoundWidget.

bool canvascv::Widget::setDirty ( )
protected

Mark us as 'dirty' so before the next draw, our 'update' will be called

Returns
true if marked as dirty for later or false if changes were done on the spot
void canvascv::Widget::setFlowAnchor ( const Anchor value)
Parameters
valueis used to set the flowAnchor
See also
VerticalLayout, HorizontalLayout, Text
void canvascv::Widget::setLayoutAnchor ( const Anchor value)
Parameters
valueis used to set the layoutAnchor
See also
VerticalLayout, HorizontalLayout
void canvascv::Widget::setStatusMsg ( const std::string &  value)
Parameters
valuea message to display during mouse hover
See also
Canvas::enableStatusMsg

The documentation for this class was generated from the following file:
  • CanvasCV-doxygen/src/canvascv/widgets/widget.h