View

class mono::ui::View

Abstract interface for all UI Views, parent class for all views.

Abstract View class/interface. All UI view/widgets that paint to the screen must inherit from this class. Views handle repaint queues, touch inputs and painting to the display buffer automatically.

All views has a width and height, along with an absolute x,y coordinate. The coordinates define the upper left corner of the view rectangle.

As a design pattern, we chose that Views must not contain any state. They only draw data to the display. Therefore view might contain or have references to objects holding the actual state information.

The some simple views, like TextLabelView, are exceptions to this rule, since it is highly convenient to let them hold some state. (Like text content.)

Something on dependence of AppContext and Appctrl design pattern

See
ResponderView

Inherits from mono::IQueueItem

Subclassed by mono::ui::BackgroundView, mono::ui::ConsoleView< W, H >, mono::ui::GraphView, mono::ui::ImageView, mono::ui::ProgressBarView, mono::ui::ResponderView, mono::ui::StatusIndicatorView, mono::ui::TextLabelView

Public Types

enum Orientation

Define the 4 dirrerent orientations the of display. The display controller apply the orientation transformation to real display. For the UI Views the coordinate system remains the same, it just changes width and height. The orico is always the top left corner (defined relative to gravity), no matter the physical orientation of mono’s display.

Values:

PORTRAIT = 0

Expected standard orientation of mono, where the thick edge is at the bottom

PORTRAIT_BOTTOMUP =1

Upside-down of PORTRAIT, where the thick edge is at the top

LANDSCAPE_RIGHT = 2

PORTRAIT rotated 90 degrees clock-wise

LANDSCAPE_LEFT = 3

PORTRAIT rotated 90 degrees counter clock-wise

Public Functions

View()

Construct an empty view, you should not do this! You should not use View directly, subclass it instead.

View(geo::Rect rect)

Construct a view with dimensions, you should not do this! You should not use View directly, subclass it instead.

virtual void setPosition(geo::Point pos)

Change the views position on the screens coordinate system.

Changes the views position on the screen. Note that changing the position does not implicitly redraw the view. This means you will need to update the screen the affected areas to make the change visible.

Parameters
  • pos -

    The new position of the view

virtual void setSize(geo::Size siz)

Change the size (width, height) of the view.

Changes the views dimensions. The affect of size changes might depend on the specefic view subclass. Some views might use their size to calculate their internal layout - other might only support fixed sizes.

Note that changing the size here does not redraw the view. The screen needs to be redrawn the affected places, to make the size change visible.

Parameters
  • siz -

    The new size of the view

virtual void setRect(geo::Rect rect)

Set the views position and size, by providing a rectangle object.

Note that this method does not repaint the view, you must do that explicitly.

Parameters
  • rect -

    The view rectangle, containing size and position

virtual mono::geo::Point &Position()

Get the current position of the views upper left corner.

Return
A reference to the current position

virtual mono::geo::Size &Size()

Get the views current size rectangle.

Return
A reference to the views size rectangle

void scheduleRepaint()

Schedule this view for repaint at next display refresh.

This method add the view to the display systems re-paint queue. The queue is executed right after a display refresh. This helps prevent graphical artifacts, when running on a single display buffer system.

Because view has no state information, they do not know when to repaint themselves. You or classes using views, must manually call this repaint method when its time to repaint the view.

virtual bool Visible() const

Returns the views visibility.

Get the view visible state. Non-visible view are ignored by the method scheduleRepaint. You change the visibility state by using the methods show and hide

Return
true if the view can/should be painted on the screen, false otherwise.
See

show

hide

virtual void show()

Set the view to visible, and paint it.

Change the views visibility state to visible. This means it can be scheduled for repaint by scheduleRepaint. This method automatically schedules the view for repaint.

See

hide

Visible

virtual void hide()

Set the view to be invisible.

Change the views state to invisible. THis method will remove the view from the dirtyQueue, if it has already been scheduled for repaint.

Any calls to scheduleRepaint will be ignored, until the view is set visible again.

See

show

Visible

Public Static Functions

uint16_t DisplayWidth()

Returns the horizontal (X-axis) width of the display canvas, in pixels. The width is always defined as perpendicular to gravity

uint16_t DisplayHeight()

Returns the vertical (Y-axis) height of the display canvas, in pixels. The height axis is meant to be parallel to the gravitational axis.

View::Orientation DisplayOrientation()

Returns the current physical display orientation of the display The orientation is controlled by the IDisplayController

Public Static Attributes

uint32_t RepaintScheduledViewsTime

The CPU time used to repaint the latest set of dirty views. This measure includes both the painting algorithms and the transfer time used to comminicate with the disdplay hardware.

Protected Functions

void callRepaintScheduledViews()

A member method to call the static method repaintScheduledViews.

See
repaintScheduledViews

virtual void repaint() = 0

Repaint the view content, using the View::painter.

Re-paint the view content. This method should be called then the view content has changed. You can call this method directly, but it might cause graphics artifacts because the display is not double buffered. Instead you should schedule a repaint by calling the scheduleRepaint() method. This method will schedule the repaint, right after the next display update.

The display system will not schedule any repaints automatically. The view does not contain any state information, so you or other classes utilizing view must schedule repaints.

In subclasses of View, this method must be overwritten.

Protected Attributes

geo::Rect viewRect

The rect defines the position and size of this view on the screen. This defines where the view rectangles upper left corner is situated, and the width and height in pixels.

bool isDirty

Indicate is this view should be repainted on next display refresh.

bool visible

Views can be visible of non-visisble (hidden). When a view is not visible scheduleRepaint will ignore requests.

You should use the methods show and hide is toggle visibility.

See

show

hide

Visible

Protected Static Functions

void repaintScheduledViews()

This class method will run through the scheduled re-paints queue and call the repaint method on all of them.

This method is called automatically be the display system, you do not need to call it yourself.

Protected Static Attributes

mono::display::DisplayPainter painter

Global View painter object. Once the first View is included in the code, this painter is initialized on the stack. Every view object uses this painter to paint itself.

The painter is initialized with the display controller of the application context. If you want views to draw themselv on another display, you must subclass or change the current display controller of the mono::ApplicationContext object.

mono::GenericQueue<View> dirtyQueue

The global re-paint queue.

When you call the scheduleRepaint method, your views is added to the re-paint queue.