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
struct | CallbackArea |
Mapping from rectangle to a callback method to execute. | |
struct | Key |
Mapping from rectangle to key id. | |
struct | KeyMapping |
Mapping from key id to Unicode character. | |
struct | KeyMappingList |
List of KeyMappings to use. | |
struct | Layout |
Definition of the keyboard layout. | |
Public Functions
virtual void | draw(const Rect & invalidatedArea) const |
Overrides the draw implementation on the Container. | |
Unicode::UnicodeChar * | getBuffer() const |
Gets the buffer. | |
uint16_t | getBufferPosition() |
Gets buffer position. | |
const KeyMappingList * | getKeyMappingList() const |
Gets key mapping list. | |
const Layout * | getLayout() const |
Gets the layout. | |
virtual void | handleClickEvent(const ClickEvent & event) |
Overrides the handleClickEvent on the container. | |
virtual void | handleDragEvent(const DragEvent & event) |
Overrides the handleDragEvent on the container. | |
Keyboard() | |
void | setBuffer(Unicode::UnicodeChar * newBuffer, uint16_t newBufferSize) |
Sets the buffer to be used by the keyboard. | |
void | setBufferPosition(uint16_t newPos) |
Change the buffer position i.e. | |
void | setKeyListener(GenericCallback< Unicode::UnicodeChar > & callback) |
Sets the callback for the keyboard. | |
void | setKeymappingList(const KeyMappingList * newKeyMappingList) |
Set/change the KeyMappingList to use. | |
void | setLayout(const Layout * newLayout) |
Set/change the Keyboard::Layout to use.The Keyboard will invalidate the space it occupies to request a redraw. | |
void | setTextIndentation() |
Sets text indentation by making the area for entered text slightly larger. | |
Protected Functions
CallbackArea | getCallbackAreaForCoordinates(int16_t x, int16_t y) const |
Gets the callback area defined by the layout for the specified coordinates. | |
Unicode::UnicodeChar | getCharForKey(uint8_t keyId) const |
Maps a keyId to the UnicodeChar being displayed by that key. | |
Key | getKeyForCoordinates(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_t | bufferPosition |
Current position in buffer. | |
uint16_t | bufferSize |
Size of the buffer. | |
bool | cancelIsEmitted |
Tells if a cancel is emitted to check when a key is released. | |
TextAreaWithOneWildcard | enteredText |
Widget capable of displaying the entered text buffer. | |
Image | highlightImage |
Image to display when a key is highlighted. | |
Image | image |
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 void | add(Drawable & d) |
Adds a Drawable instance as child to this Container. | |
Container() | |
virtual bool | contains(const Drawable & d) |
Query if a given Drawable has been added directly to this Container. | |
virtual void | forEachChild(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 void | getLastChild(int16_t x, int16_t y, Drawable ** last) |
Gets the last child in the list of children in this Container. | |
virtual void | getLastChildNear(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 Rect | getSolidRect() const |
Get (the largest possible) rectangle that is guaranteed to be solid (opaque). | |
virtual void | insert(Drawable * previous, Drawable & d) |
Inserts a Drawable after a specific child node. | |
virtual void | invalidateContent() const |
Tell the framework that the contents of the Drawable needs to be redrawn. | |
virtual void | remove(Drawable & d) |
Removes a Drawable from the container by removing it from the linked list of children. | |
virtual void | removeAll() |
Removes all children in the Container by resetting their parent and sibling pointers. | |
virtual void | unlink() |
Removes all children by unlinking the first child. | |
Protected Functions inherited from Container
virtual Rect | getContainedArea() const |
Gets a rectangle describing the total area covered by the children of this container. | |
virtual void | moveChildrenRelative(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
void | center() |
Centers the Drawable inside its parent. | |
void | centerX() |
Center the Drawable horizontally inside its parent. | |
void | centerY() |
Center the Drawable vertically inside its parent. | |
virtual void | childGeometryChanged() |
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. | |
void | drawToDynamicBitmap(BitmapId id) |
Render the Drawable object into a dynamic bitmap. | |
void | expand(int margin =0) |
Expands the Drawable to have the same size as its parent with a given margin around the edge. | |
Rect | getAbsoluteRect() 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_t | getHeight() const |
Gets the height of this Drawable. | |
virtual void | getLastChild(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 Rect | getSolidRect() const =0 |
Get (the largest possible) rectangle that is guaranteed to be solid (opaque). | |
virtual Rect | getSolidRectAbsolute() |
Helper function for obtaining the largest solid rect (as implemented by getSolidRect()) expressed in absolute coordinates. | |
virtual void | getVisibleRect(Rect & rect) const |
Function for finding the visible part of this drawable. | |
int16_t | getWidth() const |
Gets the width of this Drawable. | |
int16_t | getX() const |
Gets the x coordinate of this Drawable, relative to its parent. | |
int16_t | getY() const |
Gets the y coordinate of this Drawable, relative to its parent. | |
virtual void | handleGestureEvent(const GestureEvent & event) |
Defines the event handler interface for GestureEvents. | |
virtual void | handleTickEvent() |
Called periodically by the framework if the Drawable instance has subscribed to timer ticks. | |
virtual void | invalidate() const |
Tell the framework that this entire Drawable needs to be redrawn. | |
virtual void | invalidateContent() const |
Tell the framework that the contents of the Drawable needs to be redrawn. | |
virtual void | invalidateRect(Rect & invalidatedArea) const |
Request that a region of this drawable is redrawn. | |
bool | isTouchable() const |
Gets whether this Drawable receives touch events or not. | |
bool | isVisible() const |
Gets whether this Drawable is visible. | |
virtual void | moveRelative(int16_t x, int16_t y) |
Moves the drawable. | |
virtual void | moveTo(int16_t x, int16_t y) |
Moves the drawable. | |
virtual void | setHeight(int16_t height) |
Sets the height of this drawable. | |
void | setPosition(const Drawable & drawable) |
Sets the position of the Drawable to the same as the given Drawable. | |
void | setPosition(int16_t x, int16_t y, int16_t width, int16_t height) |
Sets the size and position of this Drawable, relative to its parent. | |
void | setTouchable(bool touch) |
Controls whether this Drawable receives touch events or not. | |
void | setVisible(bool vis) |
Controls whether this Drawable should be visible. | |
virtual void | setWidth(int16_t width) |
Sets the width of this drawable. | |
void | setWidthHeight(const Bitmap & bitmap) |
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates). | |
void | setWidthHeight(const Drawable & drawable) |
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates). | |
void | setWidthHeight(const Rect & other) |
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates). | |
void | setWidthHeight(int16_t width, int16_t height) |
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates). | |
virtual void | setX(int16_t x) |
Sets the x coordinate of this Drawable, relative to its parent. | |
void | setXY(const Drawable & drawable) |
Sets the x and y coordinates of this Drawable. | |
void | setXY(int16_t x, int16_t y) |
Sets the x and y coordinates of this Drawable, relative to its parent. | |
virtual void | setY(int16_t y) |
Sets the y coordinate of this Drawable, relative to its parent. | |
virtual void | translateRectToAbsolute(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. | |
Rect | rect |
The coordinates of this Drawable, relative to its parent. | |
bool | touchable |
True if this drawable should receive touch events. | |
bool | visible |
True if this drawable should be drawn. | |
Public Functions Documentation
draw
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.
invalidatedArea | The area to draw. |
Reimplements: touchgfx::Container::draw
getBuffer
Unicode::UnicodeChar * getBuffer | ( | ) | const |
Gets the buffer.
The buffer containing entered text currently being displayed.
getBufferPosition
uint16_t getBufferPosition | ( | ) |
Gets buffer position.
the buffer position, i.e. the current index where new characters will be placed.
getKeyMappingList
const KeyMappingList * getKeyMappingList | ( | ) | const |
getLayout
const Layout * getLayout | ( | ) | const |
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.
event | The 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.
event | The DragEvent. |
Reimplements: touchgfx::Drawable::handleDragEvent
Keyboard
Keyboard | ( | ) |
setBuffer
void setBuffer | ( | Unicode::UnicodeChar * | newBuffer , | ||
uint16_t | newBufferSize | ||||
) |
Sets the buffer to be used by the keyboard.
Keys entered are added to the buffer.
newBuffer | Pointer 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. |
newBufferSize | Length of the buffer, i.e. number of UnicodeChar's. |
setBufferPosition
void setBufferPosition | ( | uint16_t | newPos | ) | |
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.
newPos | The buffer position. |
setKeyListener
void setKeyListener | ( | GenericCallback< Unicode::UnicodeChar > & | callback | ) | |
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.
callback | The 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.
newKeyMappingList | The new KeyMappingList. |
setLayout
setTextIndentation
void 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.
Protected Functions Documentation
getCallbackAreaForCoordinates
CallbackArea getCallbackAreaForCoordinates | ( | int16_t | x , | const | |
int16_t | y | const | |||
) | const |
Gets the callback area defined by the layout for the specified coordinates.
x | The x coordinate to perform key look up with. |
y | The y coordinate to perform key look up with. |
The CallbackArea, which is empty if not found.
getCharForKey
Unicode::UnicodeChar getCharForKey | ( | uint8_t | keyId | ) | |
Maps a keyId to the UnicodeChar being displayed by that key.
keyId | The id of the key to perform lookup with. |
the UnicodeChar used for the specified key.
getKeyForCoordinates
Key getKeyForCoordinates | ( | int16_t | x , | const | |
int16_t | y | const | |||
) | const |
Gets key for coordinates.
x | The x coordinate to perform key look up with. |
y | The y coordinate to perform key look up with. |
The key for the given coordinates.
Protected Attributes Documentation
buffer
Unicode::UnicodeChar * 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
TextAreaWithOneWildcard enteredText
Widget capable of displaying the entered text buffer.
highlightImage
image
Image image
Layout bitmap.
keyListener
GenericCallback< Unicode::UnicodeChar > * 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.