Iridescence 1.00
Embedded Graphic Framework
Loading...
Searching...
No Matches
DsView Class Reference

DsView is a base class that represents any view on the screen. More...

#include <ds_view.h>

Inheritance diagram for DsView:
[legend]

Classes

class  StateObserver
 StateObserver is a pure virtual class implementing the interface for notifying state observers of changes in the visibility of a DsView object. More...
 

Public Member Functions

 DsView (DsView *parent, const DsPoint &pos=DsPoint(), const DsSize &size=DsSize())
 Creates a DsView with an optional position and size.
 
 DsView (DsView *parent, DsOrientation layout_orientation)
 Creates a DsView with the auto-layout mode active. This view can align it's children automatically.
 
void addChild (DsView *view)
 Adds a child to the current DsView.
 
void removeChild (DsView *view)
 Removes a child to the current DsView.
 
void removeAllChildren (void)
 Removes all children of the current DsView.
 
void bringFront (void)
 Brings the current view to the top of the drawing order.
 
void sendBack (void)
 Sends the current view to the bottom of the drawing order.
 
DsViewgetParent (void) const
 Returns the parent of the current view.
 
void setParent (DsView *parent)
 Sets a new parent to the view.
 
const DsPointgetPosition (void) const
 Returns the position of the view in parent coordinates.
 
DsFPoint getCenterPoint (void) const
 Returns the center point of the view in current coordinates.
 
DsPoint translatePositionInParentCoordinates (const DsView *parent, DsPoint pos) const
 Translates position (x, y) in parent coordinate system.
 
DsPoint translatePositionInParentCoordinates (uint32_t parent_level, DsPoint pos) const
 Translates position (x, y) in parent coordinate system.
 
DsPoint getPositionInParentCoordinates (const DsView *parent) const
 Returns the position in the parent's coordinate system.
 
void setPosition (const DsPoint &pos)
 Sets the position of the view in parent coordinates.
 
void setCenterPosition (const DsPoint &pos)
 Sets the position of the center of the view in parent coordinates.
 
void centerVertically (DsView *view)
 Aligns vertically the center of the current view with the center of another view.
 
void centerHorizontally (DsView *view)
 Aligns horizontally the center of the current view with the center of another view.
 
const DsSizegetParentSize (void) const
 Returns the size of the parent view.
 
const DsSizegetSize (void) const
 Returns the size of the view.
 
void setMinimumSize (const DsSize &size)
 Returns the minimum size of the view.
 
void setSize (const DsSize &size)
 Sets the size of the view.
 
void setWidth (int32_t width)
 Sets the width of the view.
 
void setHeight (int32_t height)
 Sets the height of the view.
 
DsRect getRegion (void) const
 Returns a rectangle describing the space occupied by the current view in it's own coordinate system (X and Y coordinates are 0).
 
DsRect getRegionInParentCoordinates (const DsView *parent) const
 Returns a rectangle describing the space occupied by the current view in the parent's coordinate system.
 
void alignInParent (void)
 Aligns the view relative to it's parent.
 
void alignInParent (const DsAlignment &alignment, int32_t padding_top, int32_t padding_left, int32_t padding_bottom, int32_t padding_right)
 Aligns the view relative to it's parent.
 
DsViewsetPaddingTop (int16_t padding, uint16_t proportion=0)
 Sets the top padding used by the auto-layout.
 
DsViewsetPaddingBottom (int16_t padding, uint16_t proportion=0)
 Sets the bottom padding used by the auto-layout.
 
DsViewsetPaddingLeft (int32_t padding, uint16_t proportion=0)
 Sets the left padding used by the auto-layout.
 
DsViewsetPaddingRight (int16_t padding, uint16_t proportion=0)
 Sets the right padding used by the auto-layout.
 
DsViewsetPadding (int16_t padding, uint16_t proportion=0)
 Sets the padding used by the auto-layout.
 
DsViewsetPaddingHorizontal (int16_t padding, uint16_t proportion=0)
 Sets the horizontal padding used by the auto-layout.
 
DsViewsetPaddingVertical (int16_t padding, uint16_t proportion=0)
 Sets the vertical padding used by the auto-layout.
 
DsViewsetProportion (uint32_t proportion)
 Sets the view proportion used by the auto-layout.
 
DsAlignment getParentAlignment (void) const
 Returns parent alignment mode of the view.
 
DsViewsetParentAlignment (const DsAlignment &alignment)
 Sets parent alignment mode of the view.
 
void reserveSpace (bool state)
 Configures if during auto-layout the view will reserve space even if it's hidden.
 
void setAutoLayout (DsOrientation orientation, bool enable)
 Enables or disables the auto-layout mode and sets the primary orientation.
 
virtual DsSize fitContent (void)
 Calculates the minimum size required by the view.
 
void doLayout (void)
 Runs the auto-layout algorithm.
 
void setBackgroundColor (DsColor color)
 Sets the background color of the view.
 
void setBackgroundImage (const DsSurface *surface)
 Sets the background image.
 
void setPanelColor (DsColor color)
 Sets the color of the panel.
 
void setPanelBorderColor (DsColor color)
 Sets the color of the panel border.
 
void setPanelCornerRadius (uint16_t radius)
 Sets the radius of the panel corners.
 
void setPanelBorderThickness (uint8_t thickness)
 Sets the thickness of the panel border.
 
DsScreengetScreen (void)
 Returns a reference to the screen to which this view belongs.
 
bool isFocused (void)
 Is the view focused?
 
bool getIsVisible (void) const
 Is the view visibility enabled?
 
bool isVisible (void) const
 Is the view actually visible on the screen?
 
bool isParentVisible (void) const
 Is the parent view actually visible on the screen?
 
bool show (void)
 Shortcut to setVisible(true).
 
bool hide (void)
 Shortcut to setVisible(false).
 
bool setVisible (bool is_visible)
 Changes the visibility of the view.
 
virtual void onShow (void)
 This virtual method is called when the view becomes visible on the screen.
 
virtual void onHide (void)
 This virtual method is called when the view becomes invisible (hidden) on the screen.
 
void enable (bool state)
 Enables or disables the view.
 
bool isEnabled (void) const
 Is the view enabled?
 
void enableTouch (bool state)
 Enables or disables processing of touch events.
 
bool isTouchEnabled (void) const
 Is the view enabled to process touch events?
 
void sendTap (DsPoint pos)
 Sends a tap event to the view.
 
void setOnTapCallback (const lambda< void(const DsPoint &p)> &cb)
 Sets the lambda to be executed when the user taps on the view.
 
void setOnLongTapCallback (const lambda< void(const DsPoint &p)> &cb)
 Sets the lambda to be executed when the user taps the view and holds for a specific time (set with setLongTapDetection()).
 
void setOnTouchActiveCallback (const lambda< void(const DsPoint &p)> &cb)
 Sets the lambda to be executed when the user touches the view.
 
void setOnTouchReleaseCallback (const lambda< void(void)> &cb)
 Sets the lambda to be executed when the user touch is released.
 
void setLongTapDetection (uint32_t delay_ms)
 Configures the long tap detection.
 
bool isInputInside (void) const
 Returns if there is user input (touch) inside the view.
 
const DsPointgetTouchPosition (void) const
 Returns the location of the user touch input inside the view.
 
void enableHorizontalScroll (bool state)
 Enables or disables the horizontal scroll of the view contents.
 
void enableVerticalScroll (bool state)
 Enables or disables the vertical scroll of the view contents.
 
void setScrollbarColor (DsColor color)
 Configure the color of the scroll bars.
 
virtual void invalidate (void)
 Invalidates the view.
 
virtual void invalidateRegion (DsRect region)
 Invalidates only a region of the view.
 
void addStateObserver (StateObserver *observer)
 Adds a state observer object.
 
void removeStateObserver (StateObserver *observer)
 Removes a state observer object.
 

Protected Member Functions

virtual void onChildAdd (DsView *child)
 This virtual method will be called when a new child had been added to the view.
 
virtual void onSizeChange (void)
 This virtual method will be called when the size of the view changes.
 
virtual void onPaint (DsRenderer &renderer)
 This virtual method will be called when the view needs to repaint it's content.
 
virtual void onPaintOver (DsRenderer &renderer)
 This virtual method will be called when the view needs to repaint it's content, but after the view and it's children had been painted.
 
virtual bool onTouch (const DsTouchEvent &event)
 This virtual method will be called when there is touch user input.
 
virtual void onVSync (void)
 This virtual method is be called at every vertical sync period.
 
virtual void onKeyboard (int32_t key)
 This virtual method is called when there is a keyboard event that needs to be processed.
 
void inputCapture (void)
 Captures the touch input.
 
bool isInputCaptured (void) const
 Is the input captured?
 
void skipInput (void)
 Skips receiving touch inputs until the end of the current touch event.
 
void forAllChildren (const lambda< void(DsView *child)> &lambda)
 Calls the supplied lambda for every view in the children list.
 
void forAllChildrenBackwards (const lambda< void(DsView *child)> &lambda)
 Calls the supplied lambda for every view in the children list.
 

Protected Attributes

DsPoint mScrollPosition
 
DsPoint mPreviousScrollPosition
 
DsPoint mScrollPositionBase
 
DsColor mScrollbarColor
 
DsPoint mTouchPos
 
uint32_t mTouchTimestamp
 

Friends

class DsScreen
 
class DsList
 
class DsGrid
 
class DsBookView
 

Detailed Description

DsView is a base class that represents any view on the screen.

All view classes, including custom ones written by the user must have DsView as a base class.

A DsView is a rectangular area on the screen. The area is defined by the view X,Y coordinates (position) and the view size (W, H). Each DsView contains a list of children views and a pointer to the parent view. Painting always happens from top down, recursively. First the parent is painted, followed by the children in the order in which they were created. After a view and all it's children are painted, the onPainOver() virtual method is called. This gives the oportunity to paint on top of the view's children. A view class can be in multiple states:

  1. Visible / Hidden - when a view is hidden, it's children are all hidden too
  2. Enabled / Disabled - when a view is disabled it will not accept user input, neither will all it's children. A darkening mask can also be applied on top.
  3. Focused / Not focused - when a view is focused it can receive keyboard events (or events from other input devices). Only one view can be focused at any given time.

Constructor & Destructor Documentation

◆ DsView() [1/2]

DsView::DsView ( DsView parent,
const DsPoint pos = DsPoint(),
const DsSize size = DsSize() 
)

Creates a DsView with an optional position and size.

Parameters
parentThe parent view
posThe position of the view in the parent coordinate system
sizeThe size of the view

◆ DsView() [2/2]

DsView::DsView ( DsView parent,
DsOrientation  layout_orientation 
)

Creates a DsView with the auto-layout mode active. This view can align it's children automatically.

Parameters
parentThe parent view of the DsView
layout_orientationThe orientation of the auto-layout. It can configure the DsView to act as a vertical or horizontal stack. This is the primary direction of the auto-layout.

Member Function Documentation

◆ addChild()

void DsView::addChild ( DsView view)

Adds a child to the current DsView.

Parameters
viewThe view to add as a child. The view will not be added if it already has a parent.

◆ addStateObserver()

void DsView::addStateObserver ( StateObserver observer)

Adds a state observer object.

The state observer will be notified when the view's visibility state changes.

Parameters
observerState observer

◆ alignInParent() [1/2]

void DsView::alignInParent ( const DsAlignment alignment,
int32_t  padding_top,
int32_t  padding_left,
int32_t  padding_bottom,
int32_t  padding_right 
)

Aligns the view relative to it's parent.

Parameters
alignmentThe alignment mode
padding_topTop padding
padding_leftLeft padding
padding_bottomBottom padding
padding_rightRight padding

◆ alignInParent() [2/2]

void DsView::alignInParent ( void  )

Aligns the view relative to it's parent.

The alignment is done according to the parent alignment mode set using setParentAlignment() and the view padding.

◆ bringFront()

void DsView::bringFront ( void  )

Brings the current view to the top of the drawing order.

This view will be drawn on top of it's other siblings.

◆ centerHorizontally()

void DsView::centerHorizontally ( DsView view)

Aligns horizontally the center of the current view with the center of another view.

Parameters
viewThe view to align the current view with

◆ centerVertically()

void DsView::centerVertically ( DsView view)

Aligns vertically the center of the current view with the center of another view.

Parameters
viewThe view to align the current view with

◆ doLayout()

void DsView::doLayout ( void  )

Runs the auto-layout algorithm.

This method only produces result if the auto-layout mode is enabled.

◆ enable()

void DsView::enable ( bool  state)

Enables or disables the view.

When a view is disabled, neither itself nor it's children can receive any events including user input.

Parameters
stateTrue to enable the view, false to disable

◆ enableHorizontalScroll()

void DsView::enableHorizontalScroll ( bool  state)

Enables or disables the horizontal scroll of the view contents.

If scrolling is enabled, the user can scroll the contents of this view by dragging it.

Parameters
stateTrue to enable or false to disable the horizontal scrolling

◆ enableTouch()

void DsView::enableTouch ( bool  state)

Enables or disables processing of touch events.

Parameters
stateTrue to enable processing of touch events, false to disable it

◆ enableVerticalScroll()

void DsView::enableVerticalScroll ( bool  state)

Enables or disables the vertical scroll of the view contents.

If scrolling is enabled, the user can scroll the contents of this view by dragging it.

Parameters
stateTrue to enable or false to disable the vertical scrolling

◆ fitContent()

virtual DsSize DsView::fitContent ( void  )
virtual

Calculates the minimum size required by the view.

This method only produces result if the auto-layout mode is enabled.
It recursively calls fitContent() of all it's children to get their minimum size and then calculates the minimum size of the current view, taking into consideration the padding for all it's children.
It also sets the minimum size of the view.

Returns
Minimum size required by the view.

Reimplemented in DsGrid, and DsLabel.

◆ forAllChildren()

void DsView::forAllChildren ( const lambda< void(DsView *child)> &  lambda)
protected

Calls the supplied lambda for every view in the children list.

This method travels through all the children of a view, from top to bottom (in order of painting on the screen) and it calls the specified lambda.

Parameters
lambdaLambda of type void(DsView* child) to call

◆ forAllChildrenBackwards()

void DsView::forAllChildrenBackwards ( const lambda< void(DsView *child)> &  lambda)
protected

Calls the supplied lambda for every view in the children list.

This method travels through all the children of a view, from bottom to top (in order of painting on the screen) and it calls the specified lambda.

Parameters
lambdaLambda of type void(DsView* child) to call

◆ getCenterPoint()

DsFPoint DsView::getCenterPoint ( void  ) const

Returns the center point of the view in current coordinates.

Returns
DsFPoint representing the position in current coordinates

◆ getIsVisible()

bool DsView::getIsVisible ( void  ) const

Is the view visibility enabled?

Returns
True if the view's visibility is enabled. This does not mean that the view is actually visible on the screen. If the view's isVisible flag is set but the parent view is not visible, the view will not be visible either.

◆ getParent()

DsView * DsView::getParent ( void  ) const

Returns the parent of the current view.

Returns
Pointer to the parent view

◆ getParentAlignment()

DsAlignment DsView::getParentAlignment ( void  ) const

Returns parent alignment mode of the view.

Returns
Parent alignment.

◆ getParentSize()

const DsSize & DsView::getParentSize ( void  ) const

Returns the size of the parent view.

Returns
Size of the parent view

◆ getPosition()

const DsPoint & DsView::getPosition ( void  ) const

Returns the position of the view in parent coordinates.

Returns
DsPoint representing the position in parent coordinates

◆ getPositionInParentCoordinates()

DsPoint DsView::getPositionInParentCoordinates ( const DsView parent) const

Returns the position in the parent's coordinate system.

Parameters
parentPointer to the parent to use for coordinate translation.
Returns
Translated position

◆ getRegion()

DsRect DsView::getRegion ( void  ) const

Returns a rectangle describing the space occupied by the current view in it's own coordinate system (X and Y coordinates are 0).

Returns
Region of the current view

◆ getRegionInParentCoordinates()

DsRect DsView::getRegionInParentCoordinates ( const DsView parent) const

Returns a rectangle describing the space occupied by the current view in the parent's coordinate system.

Parameters
parentPointer to the parent to use for coordinate translation.
Returns
Region of the current view

◆ getScreen()

DsScreen & DsView::getScreen ( void  )

Returns a reference to the screen to which this view belongs.

The DsScreen class is derived from DsView (it's a view as well) but it adds the event loop and many methods managing views, scheduling tasks in the UI thread and so on.

Returns
Reference to the DsScreen

◆ getSize()

const DsSize & DsView::getSize ( void  ) const

Returns the size of the view.

Returns
Size of the view

◆ getTouchPosition()

const DsPoint & DsView::getTouchPosition ( void  ) const

Returns the location of the user touch input inside the view.

It is only valid if isInputInside() returns true, otherwise it returns the last know location of user touch input.

Returns
Coordinates of the user touch input in the current view coordinates

◆ inputCapture()

void DsView::inputCapture ( void  )
protected

Captures the touch input.

When a view captures the touch input, all touch events will be routed to that view alone. No other view will receive touch inputs until the touch event is finished (user lift finger off the screen)

◆ invalidate()

virtual void DsView::invalidate ( void  )
virtual

Invalidates the view.

Invalidating a view marks it for repainting by the graphic framework.

◆ invalidateRegion()

virtual void DsView::invalidateRegion ( DsRect  region)
virtual

Invalidates only a region of the view.

Invalidating a region of the view marks it for repainting by the graphic framework. It is important to not invalidate the entire view if only a small portion of it needs to be refreshed.

◆ isEnabled()

bool DsView::isEnabled ( void  ) const

Is the view enabled?

Returns
True if the view is enabled and it can receive events and user input

◆ isFocused()

bool DsView::isFocused ( void  )

Is the view focused?

Only a focused view can receive user input events (keypresses for example)

Returns
True if the view is in focus

◆ isInputCaptured()

bool DsView::isInputCaptured ( void  ) const
protected

Is the input captured?

Returns
True if the input is captured by this view

◆ isInputInside()

bool DsView::isInputInside ( void  ) const

Returns if there is user input (touch) inside the view.

Returns
True if user input is detected inside

◆ isParentVisible()

bool DsView::isParentVisible ( void  ) const

Is the parent view actually visible on the screen?

Returns
True if the parent view is actually visibile on the screen (recursively, all it's parents are visible)

◆ isTouchEnabled()

bool DsView::isTouchEnabled ( void  ) const

Is the view enabled to process touch events?

Returns
True if the view can process touch events, false otherwise

◆ isVisible()

bool DsView::isVisible ( void  ) const

Is the view actually visible on the screen?

Returns
True if the view is actually visibile on the screen (recursively, all it's parents are visible)

◆ onChildAdd()

virtual void DsView::onChildAdd ( DsView child)
protectedvirtual

This virtual method will be called when a new child had been added to the view.

Parameters
childDsView child that has been added

◆ onKeyboard()

virtual void DsView::onKeyboard ( int32_t  key)
protectedvirtual

This virtual method is called when there is a keyboard event that needs to be processed.

Parameters
keyASCII code of the key

◆ onPaint()

virtual void DsView::onPaint ( DsRenderer renderer)
protectedvirtual

This virtual method will be called when the view needs to repaint it's content.

A derived class must override it and implement it's own content painting. In the default implementation, it implements the window scrolling mechanism.

Paint events are propagated recursively, from top down. First the view's own onPaint() is called, followed by painting it's children and finally its own onPaintAfter(). Views only receive the onPaint() event if they need to repaint their contents.

Parameters
rendererA DsRenderer object that can be used for painting operations. This object already has a DsSurface attached to it. This DsSurface object is a subsurface of the framebuffer representing only the area used by the view. All coordinates are zero based (in the current view coordinate system).

Reimplemented in DsLabel.

◆ onPaintOver()

virtual void DsView::onPaintOver ( DsRenderer renderer)
protectedvirtual

This virtual method will be called when the view needs to repaint it's content, but after the view and it's children had been painted.

This can be used to draw on top of all children of the current view. A derived class must override it and implement it's own content painting. In the default implementation, it implements the window scrolling mechanism.

Views only receive the onPaint() event if they need to repaint their contents.

Parameters
rendererA DsRenderer object that can be used for painting operations. This object already has a DsSurface attached to it. This DsSurface object is a subsurface of the framebuffer representing only the area used by the view. All coordinates are zero based (in the current view coordinate system).

◆ onSizeChange()

virtual void DsView::onSizeChange ( void  )
protectedvirtual

This virtual method will be called when the size of the view changes.

In the default implementation, it will run the auto-layout algorithm if enabled.

◆ onTouch()

virtual bool DsView::onTouch ( const DsTouchEvent event)
protectedvirtual

This virtual method will be called when there is touch user input.

A derived class must override it and implement it's own touch input processing. In the default implementation, it implements standard touch detection: tap / touch / release / drag to scroll. The default implementation is required for setOnTapCallback(), setOnLongTapCallback(), setOnTouchCallback(), setOnReleaseCallback() to work. Touch detection can be enabled / disabled using enableTouch() and setLongTapDetection().

The touch events propagate recursively, bottom up. It starting from the child view on the top of the painting order and gord up towards the parent. When onTouch() returns true, it signals that the view handleded the event. In this case, the event stops propagating towards the parents. If onTouch returns false, the parent will receive the same onTouch() event. In an overridden implementation of onTouch() it's important to detect early on if the event is of no interest to the view and call skipInput(). This will make it so the current touch event (until user removes the finger from the screen) will not make it to the current view anymore, allowing the parent views to handle the event.

Under normal conditions, if the touch coordinates exit a view, that view will not receive touch events. This may not be desirable in cases where the user is dragging in order to cause some change in the current view. For this reason, captureInput() can be called. This captures the input in the currnet view, making it so for the rest of the touch event, only the current view will receive touch events.

Parameters
eventThe touch event. This contains the touch mode, position in current view coordinates and timestamp of the touch event.
Returns
True if the method handled the touch event and does not wish for the event to propagate down to it's children.

◆ onVSync()

virtual void DsView::onVSync ( void  )
protectedvirtual

This virtual method is be called at every vertical sync period.

It can be used for timing, animations or to implement low granularity timers and timeouts.

◆ removeChild()

void DsView::removeChild ( DsView view)

Removes a child to the current DsView.

Parameters
viewThe view to remove from the children list. The view will not be removed if it's not already a child.

◆ removeStateObserver()

void DsView::removeStateObserver ( StateObserver observer)

Removes a state observer object.

Parameters
observerState observer to remove

◆ reserveSpace()

void DsView::reserveSpace ( bool  state)

Configures if during auto-layout the view will reserve space even if it's hidden.

This method has no effect if the parent auto-layout is not enabled.

Parameters
stateIf true, the view will reserve space in the layout of the parent even if it's hidden

◆ sendBack()

void DsView::sendBack ( void  )

Sends the current view to the bottom of the drawing order.

This view will be drawn under all of it's other siblings.

◆ sendTap()

void DsView::sendTap ( DsPoint  pos)

Sends a tap event to the view.

Parameters
posThe coordinates of the tap event

◆ setAutoLayout()

void DsView::setAutoLayout ( DsOrientation  orientation,
bool  enable 
)

Enables or disables the auto-layout mode and sets the primary orientation.

Parameters
orientationPrimary orientation of the auto-layout.
enableThe auto-layout state (enabled / disabled)

◆ setBackgroundColor()

void DsView::setBackgroundColor ( DsColor  color)

Sets the background color of the view.

Parameters
colorBackground color. If the alpha channel is set to zero, the view will not paint the background.

◆ setBackgroundImage()

void DsView::setBackgroundImage ( const DsSurface surface)

Sets the background image.

Parameters
surfaceBackground surface.

◆ setCenterPosition()

void DsView::setCenterPosition ( const DsPoint pos)

Sets the position of the center of the view in parent coordinates.

This is used to easily align the center of the view.

Parameters
posDsPoint representing the position in parent coordinates

◆ setHeight()

void DsView::setHeight ( int32_t  height)

Sets the height of the view.

Parameters
heightHeight of the view

◆ setLongTapDetection()

void DsView::setLongTapDetection ( uint32_t  delay_ms)

Configures the long tap detection.

Parameters
delay_msDelay in milliseconds to detect a long tap (tap and hold). If 0, it disables the long tap detection.

◆ setMinimumSize()

void DsView::setMinimumSize ( const DsSize size)

Returns the minimum size of the view.

Returns
Minimum size of the view

◆ setOnLongTapCallback()

void DsView::setOnLongTapCallback ( const lambda< void(const DsPoint &p)> &  cb)

Sets the lambda to be executed when the user taps the view and holds for a specific time (set with setLongTapDetection()).

Parameters
cbLambda of type void(const DsPoint &p). The parameter p is the position in the current view coordinates where the user tapped and held.

◆ setOnTapCallback()

void DsView::setOnTapCallback ( const lambda< void(const DsPoint &p)> &  cb)

Sets the lambda to be executed when the user taps on the view.

Parameters
cbLambda of type void(const DsPoint &p). The parameter p is the position in the current view coordinates where the user tapped.

◆ setOnTouchActiveCallback()

void DsView::setOnTouchActiveCallback ( const lambda< void(const DsPoint &p)> &  cb)

Sets the lambda to be executed when the user touches the view.

Parameters
cbLambda of type void(const DsPoint &p). The parameter p is the position in the current view coordinates where the user touched.

◆ setOnTouchReleaseCallback()

void DsView::setOnTouchReleaseCallback ( const lambda< void(void)> &  cb)

Sets the lambda to be executed when the user touch is released.

Parameters
cbLambda of type void(void)

◆ setPadding()

DsView * DsView::setPadding ( int16_t  padding,
uint16_t  proportion = 0 
)

Sets the padding used by the auto-layout.

This is the space left between the current view and the other neighboring views during auto-layout.

Parameters
paddingPadding (applied to top, left, bottom, right)
proportionThe proportion used for padding
Returns
THIS pointer. This way, other calls to member functions can be daisy chained.

◆ setPaddingBottom()

DsView * DsView::setPaddingBottom ( int16_t  padding,
uint16_t  proportion = 0 
)

Sets the bottom padding used by the auto-layout.

This is the space left between the current view and the view to the bottom during auto-layout.

Parameters
paddingBottom padding
proportionThe proportion used for padding
Returns
THIS pointer. This way, other calls to member functions can be daisy chained.

◆ setPaddingHorizontal()

DsView * DsView::setPaddingHorizontal ( int16_t  padding,
uint16_t  proportion = 0 
)

Sets the horizontal padding used by the auto-layout.

This is the space left between the current view and the other neighboring views during auto-layout.

Parameters
paddingHorizontal padding (left and right)
proportionThe proportion used for the horizontal padding
Returns
THIS pointer. This way, other calls to member functions can be daisy chained.

◆ setPaddingLeft()

DsView * DsView::setPaddingLeft ( int32_t  padding,
uint16_t  proportion = 0 
)

Sets the left padding used by the auto-layout.

This is the space left between the current view and the view to the left during auto-layout.

Parameters
paddingLeft padding
proportionThe proportion used for padding
Returns
THIS pointer. This way, other calls to member functions can be daisy chained.

◆ setPaddingRight()

DsView * DsView::setPaddingRight ( int16_t  padding,
uint16_t  proportion = 0 
)

Sets the right padding used by the auto-layout.

This is the space left between the current view and the view to the right during auto-layout.

Parameters
paddingRight padding
proportionThe proportion used for padding
Returns
THIS pointer. This way, other calls to member functions can be daisy chained.

◆ setPaddingTop()

DsView * DsView::setPaddingTop ( int16_t  padding,
uint16_t  proportion = 0 
)

Sets the top padding used by the auto-layout.

This is the space left between the current view and the view to the top during auto-layout.

Parameters
paddingTop padding
proportionThe proportion used for padding
Returns
THIS pointer. This way, other calls to member functions can be daisy chained.

◆ setPaddingVertical()

DsView * DsView::setPaddingVertical ( int16_t  padding,
uint16_t  proportion = 0 
)

Sets the vertical padding used by the auto-layout.

This is the space left between the current view and the other neighboring views during auto-layout.

Parameters
paddingVertical padding (top and bottom)
proportionThe proportion used for the vertical padding
Returns
THIS pointer. This way, other calls to member functions can be daisy chained.

◆ setPanelBorderColor()

void DsView::setPanelBorderColor ( DsColor  color)

Sets the color of the panel border.

Parameters
colorPanel border color

◆ setPanelBorderThickness()

void DsView::setPanelBorderThickness ( uint8_t  thickness)

Sets the thickness of the panel border.

Parameters
thicknessPanel border thickness

◆ setPanelColor()

void DsView::setPanelColor ( DsColor  color)

Sets the color of the panel.

Parameters
colorPanel color. If the alpha channel is set to zero, the view will not paint a panel.

◆ setPanelCornerRadius()

void DsView::setPanelCornerRadius ( uint16_t  radius)

Sets the radius of the panel corners.

Parameters
radiusPanel corner radius

◆ setParent()

void DsView::setParent ( DsView parent)

Sets a new parent to the view.

The view will be removed from it's old parent and added to the new parent. If "parent" is nullptr, the view will become orphan.

Parameters
parentNew parent view.

◆ setParentAlignment()

DsView * DsView::setParentAlignment ( const DsAlignment alignment)

Sets parent alignment mode of the view.

This aligment mode applies when the parent view has auto-layout enabled. This method has no effect if the parent auto-layout is not enabled. The parent view will use the alignment mode to align it's children in the secondary direction. The primary direction of a view with the auto-layout mode enabled is the one set in the constructor. The secondary direction is the direction perpendicular to the primary direction.

Example: If the DsView is created using DsView(parent, DS_VERTICAL), the primary direction is vertical and secondary direction is horizontal.

If the alignment mode is DS_ALIGN_FIT, the view will be expanded in the secondary direction to fit the parent.

Parameters
alignmentAlignment mode
Returns
THIS pointer. This way, other calls to member functions can be daisy chained.

◆ setPosition()

void DsView::setPosition ( const DsPoint pos)

Sets the position of the view in parent coordinates.

Parameters
posDsPoint representing the position in parent coordinates

◆ setProportion()

DsView * DsView::setProportion ( uint32_t  proportion)

Sets the view proportion used by the auto-layout.

The proportion is used by the parent auto-layout to distribute surplus available size to it's children in the primary direction. This method has no effect if the parent auto-layout is not enabled.

Example: If the DsView is created using DsView(parent, DS_VERTICAL), the primary direction is vertical and secondary direction is horizontal.

Each child will receive size proportional to it's proportion divided by the sum of all proportion values of all it's siblings.

Example:

A DsView has auto-layout enabled and the orientation set to DS_VERTICAL. It contains 3 children:

Child 1: proportion = 0
Child 2: proportion = 2
Child 3: proportion = 1

The auto-layout calculates the minimum size a child requires by calling the fitContent() method of each child. Since the orientation is set to DS_VERTICAL, the view will arrange it's children vertically, in the order in which they were added. If the parent has extra size available in the vertical direction (H of parent > sum of H of all children) then it will distribute that remaining size to it's children in the following way:

Child 1 receives 0 / 3 of the extra size
Child 2 receives 2 / 3 of the extra size
Child 3 receives 1 / 3 of the extra size
Parameters
proportionProportion
Returns
THIS pointer. This way, other calls to member functions can be daisy chained.
See also
DsView::fitContent()

◆ setScrollbarColor()

void DsView::setScrollbarColor ( DsColor  color)

Configure the color of the scroll bars.

Scrollbars appear if scrolling is enabled and the user is actively scrolling the contents of the view.

Parameters
colorScrollbar color. If the alpha channel is zero, the scrollbars will not be painted.

◆ setSize()

void DsView::setSize ( const DsSize size)

Sets the size of the view.

If the view's auto-layout is enabled it computes the layout as well using the new size.

Parameters
sizeSize of the view

◆ setVisible()

bool DsView::setVisible ( bool  is_visible)

Changes the visibility of the view.

The change is propagated to all it's children.

Parameters
is_visibleVisibility state
Returns
True if the visibility of the view was changed

◆ setWidth()

void DsView::setWidth ( int32_t  width)

Sets the width of the view.

Parameters
widthWidth of the view

◆ translatePositionInParentCoordinates() [1/2]

DsPoint DsView::translatePositionInParentCoordinates ( const DsView parent,
DsPoint  pos 
) const

Translates position (x, y) in parent coordinate system.

Parameters
parentPointer to the parent to use for coordinate translation.
posPosition to translate in parent coordinate system
Returns
Translated position

◆ translatePositionInParentCoordinates() [2/2]

DsPoint DsView::translatePositionInParentCoordinates ( uint32_t  parent_level,
DsPoint  pos 
) const

Translates position (x, y) in parent coordinate system.

Parameters
parent_levelThe parent to use for translation. 0 = immediate parent, 1 = grandparent, ...
posPosition to translate in parent coordinate system
Returns
Translated position

The documentation for this class was generated from the following file: