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 input and painting to the display buffer automatically.
All views have a width and height, along with an absolute x,y coordinate that defines the upper left corner of the view rectangle.
Views must not contain any state. They only draw data to the display. Therefore views might contain or have references to objects holding the actual state information. 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 origo 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
-
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.
-
void
setPosition
(geo::Point pos)¶ Change the view’s position on the screens coordinate system.
Changes the view’s 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
-
void
setSize
(geo::Size siz)¶ Change the size (width, height) of the view.
Changes the view’s dimensions. The effect of size changes might depend on the specefic view subclass. Some views might use their size to calculate their internal layout - others might only support fixed size.
Note that changing the size here does not redraw the view. The screen needs to be redrawn to make the size change visible.
- Parameters
siz
: The new size of the view
-
void
setRect
(geo::Rect rect)¶ Set the view’s 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
-
mono::geo::Point &
Position
()¶ Get the current position of the view’s upper left corner.
- Return
- A reference to the current position
-
mono::geo::Size &
Size
()¶ Get the view’s current size rectangle.
- Return
- A reference to the view’s size rectangle
-
const mono::geo::Rect &
ViewRect
() const¶ Get the views view rect
This method returns a reference to the views current view rect.
-
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 views have no state information, they do not know when to repaint themselves. You, or classes using views, must call this repaint method when the view is ready to be repainted.
-
bool
Visible
() const¶ Returns the view’s 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
-
void
show
()¶ Set the view to visible, and paint it.
Change the view’s visibility state to visible. This means it can be scheduled for repaint by scheduleRepaint. This method automatically schedules the view for repaint.
-
void
hide
()¶ Set the view to be invisible.
Change the view’s 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.
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.
-
virtual void
repaint
() = 0¶ Repaint the view content, using the View::painter.
Re-paint the view content. This method should be called when 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.
Protected Static Functions
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.