メイン・コンテンツまでスキップ

Keyboard

The keyboard provides text input for touch devices. It is configured using a Layout and a KeyMappingList, both of which can be changed at runtime. The class using the keyboard must provide a buffer where the entered text is placed. The Layout contains a bitmap id for the image to display and two mappings: rectangles to key ids and rectangles to callback methods.

The KeyMappingList maps key ids to Unicode characters. When the user presses a key, the keyboard looks in its layout for a rectangle containing the coordinates pressed. If it finds a mapping to a callback method, it will invoke that method. If it finds a mapping to a key it will look up the Unicode character for that key and place it in a text buffer. The sequence is: (x,y) -> KeyId -> UnicodeChar.

A keyboard with multiple key mappings e.g. lower case alpha, upper case alpha and numeric mappings can be created by implementing callback methods for shift and mode areas in the provided bitmap and then changing the KeyMappingList when those areas are pressed.

Inherits from: Container, Drawable

Public Classes

structCallbackArea
Mapping from rectangle to a callback method to execute.
structKey
Mapping from rectangle to key id.
structKeyMapping
Mapping from key id to Unicode character.
structKeyMappingList
List of KeyMappings to use.
structLayout
Definition of the keyboard layout.

Public Functions

virtual voiddraw(const Rect & invalidatedArea) const
Overrides the draw implementation on the Container.
Unicode::UnicodeChar *getBuffer() const
Gets the buffer.
uint16_tgetBufferPosition()
Gets buffer position.
const KeyMappingList *getKeyMappingList() const
Gets key mapping list.
const Layout *getLayout() const
Gets the layout.
virtual voidhandleClickEvent(const ClickEvent & event)
Overrides the handleClickEvent on the container.
virtual voidhandleDragEvent(const DragEvent & event)
Overrides the handleDragEvent on the container.
Keyboard()
voidsetBuffer(Unicode::UnicodeChar * newBuffer, uint16_t newBufferSize)
Sets the buffer to be used by the keyboard.
voidsetBufferPosition(uint16_t newPos)
Change the buffer position i.e.
voidsetKeyListener(GenericCallback< Unicode::UnicodeChar > & callback)
Sets the callback for the keyboard.
voidsetKeymappingList(const KeyMappingList * newKeyMappingList)
Set/change the KeyMappingList to use.
voidsetLayout(const Layout * newLayout)
Set/change the Keyboard::Layout to use.The Keyboard will invalidate the space it occupies to request a redraw.
voidsetTextIndentation()
Sets text indentation by making the area for entered text slightly larger.

Protected Functions

CallbackAreagetCallbackAreaForCoordinates(int16_t x, int16_t y) const
Gets the callback area defined by the layout for the specified coordinates.
Unicode::UnicodeChargetCharForKey(uint8_t keyId) const
Maps a keyId to the UnicodeChar being displayed by that key.
KeygetKeyForCoordinates(int16_t x, int16_t y) const
Gets key for coordinates.

Protected Attributes

Unicode::UnicodeChar *buffer
Pointer to null-terminated buffer where the entered text is being displayed.
uint16_tbufferPosition
Current position in buffer.
uint16_tbufferSize
Size of the buffer.
boolcancelIsEmitted
Tells if a cancel is emitted to check when a key is released.
TextAreaWithOneWildcardenteredText
Widget capable of displaying the entered text buffer.
ImagehighlightImage
Image to display when a key is highlighted.
Imageimage
Layout bitmap.
GenericCallback< Unicode::UnicodeChar > *keyListener
Pointer to callback being executed when a key is pressed.
const KeyMappingList *keyMappingList
Pointer to key mapping.
const Layout *layout
Pointer to layout.

Additional inherited members

Public Functions inherited from Container

virtual voidadd(Drawable & d)
Adds a Drawable instance as child to this Container.
Container()
virtual boolcontains(const Drawable & d)
Query if a given Drawable has been added directly to this Container.
virtual voidforEachChild(GenericCallback< Drawable & > * function)
Executes the specified callback function for each child in the Container.
virtual Drawable *getFirstChild()
Obtain a pointer to the first child of this container.
virtual voidgetLastChild(int16_t x, int16_t y, Drawable ** last)
Gets the last child in the list of children in this Container.
virtual voidgetLastChildNear(int16_t x, int16_t y, Drawable * last, int16_t fingerAdjustmentX, int16_t * fingerAdjustmentY)
Works similar to getLastChild() but also considers the current set finger size in HAL.
virtual RectgetSolidRect() const
Get (the largest possible) rectangle that is guaranteed to be solid (opaque).
virtual voidinsert(Drawable * previous, Drawable & d)
Inserts a Drawable after a specific child node.
virtual voidinvalidateContent() const
Tell the framework that the contents of the Drawable needs to be redrawn.
virtual voidremove(Drawable & d)
Removes a Drawable from the container by removing it from the linked list of children.
virtual voidremoveAll()
Removes all children in the Container by resetting their parent and sibling pointers.
virtual voidunlink()
Removes all children by unlinking the first child.

Protected Functions inherited from Container

virtual RectgetContainedArea() const
Gets a rectangle describing the total area covered by the children of this container.
virtual voidmoveChildrenRelative(int16_t deltaX, int16_t deltaY)
Calls moveRelative on all children.

Protected Attributes inherited from Container

Drawable *firstChild
Pointer to the first child of this container. Subsequent children can be found through firstChild's nextSibling.

Public Functions inherited from Drawable

voidcenter()
Centers the Drawable inside its parent.
voidcenterX()
Center the Drawable horizontally inside its parent.
voidcenterY()
Center the Drawable vertically inside its parent.
virtual voidchildGeometryChanged()
This function can be called on parent nodes to signal that the size or position of one or more of its children has changed.
Drawable()
Initializes a new instance of the Drawable class.
voiddrawToDynamicBitmap(BitmapId id)
Render the Drawable object into a dynamic bitmap.
voidexpand(int margin =0)
Expands the Drawable to have the same size as its parent with a given margin around the edge.
RectgetAbsoluteRect() const
Helper function for obtaining the rectangle this Drawable covers, expressed in absolute coordinates.
virtual Drawable *getFirstChild()
Function for obtaining the first child of this drawable if any.
int16_tgetHeight() const
Gets the height of this Drawable.
virtual voidgetLastChild(int16_t x, int16_t y, Drawable ** last) =0
Function for obtaining the the last child of this drawable that intersects with the specified point.
Drawable *getNextSibling()
Gets the next sibling node.
Drawable *getParent() const
Returns the parent node.
const Rect &getRect() const
Gets the rectangle this Drawable covers, in coordinates relative to its parent.
virtual RectgetSolidRect() const =0
Get (the largest possible) rectangle that is guaranteed to be solid (opaque).
virtual RectgetSolidRectAbsolute()
Helper function for obtaining the largest solid rect (as implemented by getSolidRect()) expressed in absolute coordinates.
virtual voidgetVisibleRect(Rect & rect) const
Function for finding the visible part of this drawable.
int16_tgetWidth() const
Gets the width of this Drawable.
int16_tgetX() const
Gets the x coordinate of this Drawable, relative to its parent.
int16_tgetY() const
Gets the y coordinate of this Drawable, relative to its parent.
virtual voidhandleGestureEvent(const GestureEvent & event)
Defines the event handler interface for GestureEvents.
virtual voidhandleTickEvent()
Called periodically by the framework if the Drawable instance has subscribed to timer ticks.
virtual voidinvalidate() const
Tell the framework that this entire Drawable needs to be redrawn.
virtual voidinvalidateContent() const
Tell the framework that the contents of the Drawable needs to be redrawn.
virtual voidinvalidateRect(Rect & invalidatedArea) const
Request that a region of this drawable is redrawn.
boolisTouchable() const
Gets whether this Drawable receives touch events or not.
boolisVisible() const
Gets whether this Drawable is visible.
virtual voidmoveRelative(int16_t x, int16_t y)
Moves the drawable.
virtual voidmoveTo(int16_t x, int16_t y)
Moves the drawable.
virtual voidsetHeight(int16_t height)
Sets the height of this drawable.
voidsetPosition(const Drawable & drawable)
Sets the position of the Drawable to the same as the given Drawable.
voidsetPosition(int16_t x, int16_t y, int16_t width, int16_t height)
Sets the size and position of this Drawable, relative to its parent.
voidsetTouchable(bool touch)
Controls whether this Drawable receives touch events or not.
voidsetVisible(bool vis)
Controls whether this Drawable should be visible.
virtual voidsetWidth(int16_t width)
Sets the width of this drawable.
voidsetWidthHeight(const Bitmap & bitmap)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
voidsetWidthHeight(const Drawable & drawable)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
voidsetWidthHeight(const Rect & other)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
voidsetWidthHeight(int16_t width, int16_t height)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
virtual voidsetX(int16_t x)
Sets the x coordinate of this Drawable, relative to its parent.
voidsetXY(const Drawable & drawable)
Sets the x and y coordinates of this Drawable.
voidsetXY(int16_t x, int16_t y)
Sets the x and y coordinates of this Drawable, relative to its parent.
virtual voidsetY(int16_t y)
Sets the y coordinate of this Drawable, relative to its parent.
virtual voidtranslateRectToAbsolute(Rect & r) const
Helper function for converting a region of this Drawable to absolute coordinates.
virtual ~Drawable()
Finalizes an instance of the Drawable class.

Protected Attributes inherited from Drawable

Drawable *nextSibling
Pointer to the next Drawable.
Drawable *parent
Pointer to this drawable's parent.
Rectrect
The coordinates of this Drawable, relative to its parent.
booltouchable
True if this drawable should receive touch events.
boolvisible
True if this drawable should be drawn.

Public Functions Documentation

draw

virtual void draw(const Rect &invalidatedArea)

Overrides the draw implementation on the Container.

First invokes the container draw implementation to draw the keyboard bitmap and text area holding the entered text. If additional drawables have been added to the keyboard, they will also be draw. After invoking the container draw, the glyphs mapped to keys are drawn and if a key has been pressed, it will be highlighted.

Parameters:
invalidatedAreaThe area to draw.

Reimplements: touchgfx::Container::draw

getBuffer

Unicode::UnicodeChar * getBuffer()const

Gets the buffer.

Returns:

The buffer containing entered text currently being displayed.

See also:

getBufferPosition

uint16_t getBufferPosition()

Gets buffer position.

Returns:

the buffer position, i.e. the current index where new characters will be placed.

See also:

getKeyMappingList

const KeyMappingList * getKeyMappingList()const

Gets key mapping list.

Returns:

The KeyMappingList used by the Keyboard.

getLayout

const Layout * getLayout()const

Gets the layout.

Returns:

The layout used by the Keyboard.

See also:

handleClickEvent

virtual void handleClickEvent(const ClickEvent &event)

Overrides the handleClickEvent on the container.

The keyboard handles all click events internally and click events are not propagated to drawables added to the keyboard.

Parameters:
eventThe ClickEvent.

Reimplements: touchgfx::Drawable::handleClickEvent

handleDragEvent

virtual void handleDragEvent(const DragEvent &event)

Overrides the handleDragEvent on the container.

The keyboard handles drag events to enable the container to, emit a CANCEL, if the user drags outside the currently pressed key.

Parameters:
eventThe DragEvent.

Reimplements: touchgfx::Drawable::handleDragEvent

Keyboard

setBuffer

void setBuffer(Unicode::UnicodeChar *newBuffer ,
uint16_tnewBufferSize
)

Sets the buffer to be used by the keyboard.

Keys entered are added to the buffer.

Parameters:
newBufferPointer to a buffer holding the text edited by the keyboard. If the buffer is not empty, the edit position for the keyboard will be set to the end of the provided text.
newBufferSizeLength of the buffer, i.e. number of UnicodeChar's.
See also:

setBufferPosition

void setBufferPosition(uint16_tnewPos)

Change the buffer position i.e.

the next index to place a character when a key is pressed. This can be used to implement backspace functionality if the class using the Keyboard implements a callback and maps it to a backspace implementation. Setting the position will cause the TextArea displaying the text to be invalidated to request a redraw.

Parameters:
newPosThe buffer position.
See also:

setKeyListener

Sets the callback for the keyboard.

The callback will be executed every time a key is clicked. The callback argument contains the key that was just pressed.

Parameters:
callbackThe Callback to invoke.
Note

Backspace, shift and mode keys report a 0 as value.

setKeymappingList

void setKeymappingList(const KeyMappingList *newKeyMappingList)

Set/change the KeyMappingList to use.

The Keyboard will invalidate the space it occupies to request a redraw.

Parameters:
newKeyMappingListThe new KeyMappingList.

setLayout

void setLayout(const Layout *newLayout)

Set/change the Keyboard::Layout to use.The Keyboard will invalidate the space it occupies to request a redraw.

Parameters:
newLayoutThe new layout.
See also:

setTextIndentation

Sets text indentation by making the area for entered text slightly larger.

The result is that some characters (often 'j' and '_') will not be cut off. Indentation is added to both sides of the text area in case the text is right-to-left. Indentation is automatically set so all characters will display properly.

See also:

Protected Functions Documentation

getCallbackAreaForCoordinates

CallbackArea getCallbackAreaForCoordinates(int16_tx ,const
int16_tyconst
)const

Gets the callback area defined by the layout for the specified coordinates.

Parameters:
xThe x coordinate to perform key look up with.
yThe y coordinate to perform key look up with.
Returns:

The CallbackArea, which is empty if not found.

getCharForKey

Unicode::UnicodeChar getCharForKey(uint8_tkeyId)

Maps a keyId to the UnicodeChar being displayed by that key.

Parameters:
keyIdThe id of the key to perform lookup with.
Returns:

the UnicodeChar used for the specified key.

getKeyForCoordinates

Key getKeyForCoordinates(int16_tx ,const
int16_tyconst
)const

Gets key for coordinates.

Parameters:
xThe x coordinate to perform key look up with.
yThe y coordinate to perform key look up with.
Returns:

The key for the given coordinates.

Protected Attributes Documentation

buffer

Pointer to null-terminated buffer where the entered text is being displayed.

bufferPosition

uint16_t bufferPosition

Current position in buffer.

bufferSize

uint16_t bufferSize

Size of the buffer.

cancelIsEmitted

bool cancelIsEmitted

Tells if a cancel is emitted to check when a key is released.

enteredText

Widget capable of displaying the entered text buffer.

highlightImage

Image highlightImage

Image to display when a key is highlighted.

image

Image image

Layout bitmap.

keyListener

Pointer to callback being executed when a key is pressed.

keyMappingList

const KeyMappingList * keyMappingList

Pointer to key mapping.

layout

const Layout * layout

Pointer to layout.