Add Inter Fonts
This commit is contained in:
@ -0,0 +1,174 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/CacheableContainer.hpp
|
||||
*
|
||||
* Declares the touchgfx::CacheableContainer class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_CACHEABLECONTAINER_HPP
|
||||
#define TOUCHGFX_CACHEABLECONTAINER_HPP
|
||||
|
||||
#include <touchgfx/Bitmap.hpp>
|
||||
#include <touchgfx/Drawable.hpp>
|
||||
#include <touchgfx/containers/Container.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/Image.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A CacheableContainer can be seen as a regular Container, i.e. a Drawable that can have child
|
||||
* nodes. The z-order of children is determined by the order in which Drawables are
|
||||
* added to the container - the Drawable added last will be front-most on the screen.
|
||||
*
|
||||
* The important difference is that a CacheableContainer can also render its content to
|
||||
* a dynamic bitmap which can then be used as a texture in subsequent drawing operations,
|
||||
* either as a simple Image or in a TextureMapper. If the bitmap format of the dynamic
|
||||
* bitmap differs from the format of the current LCD, the LCD from drawing the bitmap
|
||||
* must be setup using HAL::setAuxiliaryLCD().
|
||||
*
|
||||
* @see Container, Bitmap, Image, TextureMapper
|
||||
*/
|
||||
class CacheableContainer : public Container
|
||||
{
|
||||
public:
|
||||
CacheableContainer();
|
||||
|
||||
/**
|
||||
* Set the dynamic bitmap into which the container content will be rendered. The format
|
||||
* of the bitmap must be the same as the current LCD or the same as the auxiliary LCD
|
||||
* setup using HAL::setAuxiliaryLCD.
|
||||
*
|
||||
* @param bitmapId Id of the dynamic bitmap to serve as a render target.
|
||||
*
|
||||
* @see updateCache, getCacheBitmap, HAL::setAuxiliaryLCD
|
||||
*/
|
||||
void setCacheBitmap(BitmapId bitmapId);
|
||||
|
||||
/**
|
||||
* Get the dynamic bitmap used by the CacheableContainer.
|
||||
*
|
||||
* @return the id of the assigned bitmap or BITMAP_INVALID if no bitmap has been assigned.
|
||||
*
|
||||
* @see setCacheBitmap
|
||||
*/
|
||||
BitmapId getCacheBitmap() const;
|
||||
|
||||
/**
|
||||
* Render the container into the attached dynamic bitmap.
|
||||
*
|
||||
* @see setCacheBitmap
|
||||
*/
|
||||
void updateCache();
|
||||
|
||||
/**
|
||||
* Render the container into the attached dynamic bitmap. Only the specified Rect region
|
||||
* is updated.
|
||||
*
|
||||
* @param rect Region to update.
|
||||
*
|
||||
* @see setCacheBitmap
|
||||
*/
|
||||
void updateCache(const Rect& rect);
|
||||
|
||||
/**
|
||||
* Toggle cached mode on and off. The CacheableContainer behaves just like a regular
|
||||
* Container when cached mode is turned off.
|
||||
*
|
||||
* @param enable Enable or disable cached mode.
|
||||
*/
|
||||
void enableCachedMode(bool enable);
|
||||
|
||||
/**
|
||||
* Request that a subregion of this drawable is redrawn. Will recursively traverse the
|
||||
* children. When this function returns, the specified invalidated area has been redrawn
|
||||
* for all appropriate Drawables covering the region.
|
||||
*
|
||||
* @param [in] invalidatedArea The area of this drawable to redraw expressed in coordinates
|
||||
* relative to its parent (e.g. to request a complete
|
||||
* redraw, invalidatedArea will be (0, 0, width, height).
|
||||
*/
|
||||
virtual void invalidateRect(Rect& invalidatedArea) const;
|
||||
|
||||
/**
|
||||
* Set the solid area on the dynamic bitmap assigned to the CacheableContainer.
|
||||
*
|
||||
* @param [in] solidRect The rectangle of th CacheableContainer that is solid.
|
||||
*
|
||||
* @return true if the operation succeeds, false otherwise.
|
||||
*/
|
||||
bool setSolidRect(const Rect& solidRect) const;
|
||||
|
||||
/**
|
||||
* Queries the CacheableContainer whether any child widget has been invalidated.
|
||||
*
|
||||
* @return True if a child widget has been invalidated and false otherwise.
|
||||
*/
|
||||
bool isChildInvalidated() const;
|
||||
|
||||
/**
|
||||
* @copydoc Image::setAlpha()
|
||||
*
|
||||
* @note The alpha is only applied when cached mode is enabled.
|
||||
*
|
||||
* @see enableCachedMode
|
||||
*/
|
||||
void setAlpha(uint8_t newAlpha)
|
||||
{
|
||||
cachedImage.setAlpha(newAlpha);
|
||||
}
|
||||
|
||||
/** @copydoc Image::getAlpha() */
|
||||
uint8_t getAlpha() const
|
||||
{
|
||||
return cachedImage.getAlpha();
|
||||
}
|
||||
|
||||
virtual void invalidateContent() const
|
||||
{
|
||||
if (getAlpha() > 0)
|
||||
{
|
||||
Container::invalidateContent();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
/// @cond
|
||||
virtual void setupDrawChain(const Rect& invalidatedArea, Drawable** nextPreviousElement);
|
||||
|
||||
/**
|
||||
* A CachedImage is a specialized Image object that exposes the setupDrawChain() method.
|
||||
*
|
||||
* @see CacheableContainer, Image
|
||||
*/
|
||||
class CachedImage : public Image
|
||||
{
|
||||
public:
|
||||
virtual void setupDrawChain(const Rect& invalidatedArea, Drawable** nextPreviousElement)
|
||||
{
|
||||
Drawable::setupDrawChain(invalidatedArea, nextPreviousElement);
|
||||
}
|
||||
};
|
||||
|
||||
/// @endcond
|
||||
|
||||
private:
|
||||
BitmapId cachedBitmapId; ///< The BitmapId of the dynamic bitmap attached to the CacheableContainer
|
||||
CachedImage cachedImage; ///< The CachedImage object used as a wrapper widget around the attached dynamic bitmap
|
||||
bool isCachedMode; ///< Cached mode whether enabled or disabled
|
||||
bool childWasInvalidated; ///< A child widget has been invalidated. The flag is meaningful when isCachedMode is true.
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_CACHEABLECONTAINER_HPP
|
||||
@ -0,0 +1,196 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/Container.hpp
|
||||
*
|
||||
* Declares the touchgfx::Container class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_CONTAINER_HPP
|
||||
#define TOUCHGFX_CONTAINER_HPP
|
||||
|
||||
#include <touchgfx/Callback.hpp>
|
||||
#include <touchgfx/Drawable.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A Container is a Drawable that can have child nodes. The z-order of children is determined by
|
||||
* the order in which Drawables are added to the container - the Drawable added last
|
||||
* will be front-most on the screen.
|
||||
*
|
||||
* This class overrides a few functions in Drawable in order to traverse child nodes.
|
||||
*
|
||||
* Note that containers act as view ports - that is, only the parts of children that
|
||||
* intersect with the geometry of the container will be visible (e.g. setting a
|
||||
* container's width to 0 will render all children invisible).
|
||||
*
|
||||
* @see Drawable
|
||||
*/
|
||||
class Container : public Drawable
|
||||
{
|
||||
public:
|
||||
Container()
|
||||
: Drawable(),
|
||||
firstChild(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Drawable instance as child to this Container. The Drawable added will be
|
||||
* placed as the element to be drawn last, and thus appear on top of all previously
|
||||
* added drawables in the Container.
|
||||
*
|
||||
* @param [in] d The Drawable to add.
|
||||
*
|
||||
* @note Never add a drawable more than once!
|
||||
*/
|
||||
virtual void add(Drawable& d);
|
||||
|
||||
/**
|
||||
* Removes a Drawable from the container by removing it from the linked list of
|
||||
* children. If the Drawable is not in the list of children, nothing happens. It is
|
||||
* possible to remove an element from whichever Container it is a member of using:
|
||||
* @code
|
||||
* if (d.getParent()) d.getParent()->remove(d);
|
||||
* @endcode
|
||||
* The Drawable will have the parent and next sibling cleared, but is otherwise left
|
||||
* unaltered.
|
||||
*
|
||||
* @param [in] d The Drawable to remove.
|
||||
*
|
||||
* @note This is safe to call even if d is not a child of this Container (in which case nothing happens).
|
||||
*/
|
||||
virtual void remove(Drawable& d);
|
||||
|
||||
/**
|
||||
* Removes all children in the Container by resetting their parent and sibling pointers.
|
||||
* Please note that this is not done recursively, so any child which is itself a
|
||||
* Container is not emptied.
|
||||
*/
|
||||
virtual void removeAll();
|
||||
|
||||
/**
|
||||
* Removes all children by unlinking the first child. The parent and sibling pointers of
|
||||
* the children are not reset.
|
||||
*
|
||||
* @see getFirstChild
|
||||
*/
|
||||
virtual void unlink();
|
||||
|
||||
/**
|
||||
* Query if a given Drawable has been added directly to this Container. The search is
|
||||
* not done recursively.
|
||||
*
|
||||
* @param d The Drawable to look for.
|
||||
*
|
||||
* @return True if the specified Drawable instance is direct child of this container,
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual bool contains(const Drawable& d);
|
||||
|
||||
/**
|
||||
* Inserts a Drawable after a specific child node. If previous child node is 0, the
|
||||
* drawable will be inserted as the first element in the list. The first element in the
|
||||
* list of children is the element drawn first, so this makes it possible to insert a
|
||||
* Drawable \a behind all previously added children.
|
||||
*
|
||||
* @param [in] previous The Drawable to insert after. If null, insert as header.
|
||||
* @param [in] d The Drawable to insert.
|
||||
*
|
||||
* @note As with add, do not add the same drawable twice.
|
||||
*/
|
||||
virtual void insert(Drawable* previous, Drawable& d);
|
||||
|
||||
/**
|
||||
* Gets the last child in the list of children in this Container. If this Container is
|
||||
* touchable (isTouchable()), it will be passed back as the result. Otherwise all \a
|
||||
* visible children are traversed recursively to find the Drawable that intersects with
|
||||
* the given coordinate.
|
||||
*
|
||||
* @param x The x coordinate of the intersection.
|
||||
* @param y The y coordinate of the intersection.
|
||||
* @param [out] last out parameter in which the result is placed.
|
||||
*
|
||||
* @see isVisible, isTouchable, getLastChildNear
|
||||
*/
|
||||
virtual void getLastChild(int16_t x, int16_t y, Drawable** last);
|
||||
|
||||
/**
|
||||
* Works similar to getLastChild() but also considers the current set finger size in HAL.
|
||||
*
|
||||
* @param x The x coordinate of the intersection.
|
||||
* @param y The y coordinate of the intersection.
|
||||
* @param [out] last out parameter in which the result is placed.
|
||||
* @param [out] fingerAdjustmentX out parameter in which the finger adjustment x is placed.
|
||||
* @param [out] fingerAdjustmentY out parameter in which the finger adjustment y is placed.
|
||||
*
|
||||
* @see getLastChild, HAL::setFingerSize
|
||||
*/
|
||||
virtual void getLastChildNear(int16_t x, int16_t y, Drawable** last, int16_t* fingerAdjustmentX, int16_t* fingerAdjustmentY);
|
||||
|
||||
virtual void draw(const Rect& invalidatedArea) const;
|
||||
|
||||
virtual Rect getSolidRect() const;
|
||||
|
||||
/**
|
||||
* Executes the specified callback function for each child in the Container. The
|
||||
* callback to execute must have the following prototype: void T::func(Drawable&)
|
||||
*
|
||||
* @param [in] function The function to be executed for each child.
|
||||
*/
|
||||
virtual void forEachChild(GenericCallback<Drawable&>* function);
|
||||
|
||||
/**
|
||||
* Obtain a pointer to the first child of this container. The first child is the
|
||||
* Drawable drawn first, and therefore the Drawable \a behind all other children of this
|
||||
* Container. Useful if you want to manually iterate the children added to this
|
||||
* container.
|
||||
*
|
||||
* @return Pointer to the first drawable added to this container. If nothing has been
|
||||
* added return zero.
|
||||
*
|
||||
* @see getNextSibling
|
||||
*/
|
||||
virtual Drawable* getFirstChild()
|
||||
{
|
||||
return firstChild;
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Gets a rectangle describing the total area covered by the children of this container.
|
||||
*
|
||||
* @return Rectangle covering all children.
|
||||
*/
|
||||
virtual Rect getContainedArea() const;
|
||||
|
||||
/**
|
||||
* Calls moveRelative on all children.
|
||||
*
|
||||
* @param deltaX Horizontal displacement.
|
||||
* @param deltaY Vertical displacement.
|
||||
*/
|
||||
virtual void moveChildrenRelative(int16_t deltaX, int16_t deltaY);
|
||||
|
||||
Drawable* firstChild; ///< Pointer to the first child of this container. Subsequent children can be found through firstChild's nextSibling.
|
||||
|
||||
friend class Screen;
|
||||
/// @cond
|
||||
virtual void setupDrawChain(const Rect& invalidatedArea, Drawable** nextPreviousElement);
|
||||
/// @endcond
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_CONTAINER_HPP
|
||||
@ -0,0 +1,108 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/ListLayout.hpp
|
||||
*
|
||||
* Declares the touchgfx::ListLayout class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_LISTLAYOUT_HPP
|
||||
#define TOUCHGFX_LISTLAYOUT_HPP
|
||||
|
||||
#include <touchgfx/Drawable.hpp>
|
||||
#include <touchgfx/containers/Container.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* This class provides a layout mechanism for arranging Drawable instances adjacent in the
|
||||
* specified Direction. The first element in the ListLayout is positioned in the
|
||||
* ListLayout origin (0,0). The dimensions of this class is automatically expanded to
|
||||
* cover the area of the added Drawable instances, which may grow larger than the
|
||||
* dimensions of the physical screen. Place the ListLayout inside e.g. a
|
||||
* ScrollableContainer to allow all the children to be viewed.
|
||||
*
|
||||
* @see ScrollableContainer
|
||||
*/
|
||||
class ListLayout : public Container
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Initializes a new instance of the ListLayout class.
|
||||
*
|
||||
* @param d (Optional) The direction to place the elements. ::SOUTH (Default)
|
||||
* places the elements vertically, ::EAST places the elements horizontally.
|
||||
*
|
||||
* @see setDirection
|
||||
*/
|
||||
ListLayout(const Direction d = SOUTH)
|
||||
: Container(), direction(d), offset(0)
|
||||
{
|
||||
assert((d == SOUTH || d == EAST) && "Chosen direction not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the direction of the ListLayout. If elements have already been added to the
|
||||
* ListLayout, these elements will be repositioned to adhere to the new direction.
|
||||
*
|
||||
* @param d The new Direction to grow in when added children (either ::SOUTH or ::EAST).
|
||||
*
|
||||
* @see getDirection
|
||||
*/
|
||||
virtual void setDirection(const Direction d);
|
||||
|
||||
/**
|
||||
* Gets the direction of the ListLayout.
|
||||
*
|
||||
* @return The current direction to grow in when added children (either ::SOUTH or ::EAST).
|
||||
*
|
||||
* @see setDirection
|
||||
*/
|
||||
virtual Direction getDirection() const
|
||||
{
|
||||
return direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a Drawable instance to the end of the list. The Drawable dimensions shall be set
|
||||
* prior to addition. The coordinates of the Drawable will be updated to reflect the
|
||||
* position in the ListLayout.
|
||||
*
|
||||
* @param [in] d The Drawable to add.
|
||||
*/
|
||||
virtual void add(Drawable& d);
|
||||
|
||||
/**
|
||||
* Removes a Drawable. Safe to call even if drawable has not been added. Other Drawable
|
||||
* elements in the ListLayout are repositioned and the size of the ListLayout is
|
||||
* adjusted.
|
||||
*
|
||||
* @param [in] d The drawable to remove.
|
||||
*/
|
||||
virtual void remove(Drawable& d);
|
||||
|
||||
virtual void insert(Drawable* previous, Drawable& d);
|
||||
|
||||
virtual void removeAll();
|
||||
|
||||
private:
|
||||
void internalAddElementAt(Drawable& d, int16_t coord);
|
||||
void internalAddElement(Drawable& d);
|
||||
void internalRemoveElement(Drawable& d, int16_t coord);
|
||||
Direction direction;
|
||||
int16_t offset;
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_LISTLAYOUT_HPP
|
||||
@ -0,0 +1,133 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/ModalWindow.hpp
|
||||
*
|
||||
* Declares the touchgfx::ModalWindow class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_MODALWINDOW_HPP
|
||||
#define TOUCHGFX_MODALWINDOW_HPP
|
||||
|
||||
#include <touchgfx/containers/Container.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/Box.hpp>
|
||||
#include <touchgfx/widgets/Image.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* Container for displaying a modal window and hijacking touch event and prevent them from
|
||||
* reaching the underlying view and widgets.
|
||||
*
|
||||
* The container has a background image and a surrounding box that acts as a shade on
|
||||
* top of the rest of the screen. The background image must be set (using
|
||||
* setBackground()) and the shade can be adjusted (using setShadeAlpha() and
|
||||
* setShadeColor()).
|
||||
*
|
||||
* The ModalWindow can either be used directly by adding widgets/containers to the
|
||||
* ModalWindow from your view or by sub-classing it if you need a specific ModalWindow
|
||||
* with predefined behavior across your application.
|
||||
*
|
||||
* The ModalWindow should be instantiated in the view class and added as the last
|
||||
* element (to always be on top, i.e. be modal). The ModalWindow will fill up the entire
|
||||
* screen so it should always be placed at x=0, y=0 on the display.
|
||||
*
|
||||
* To control the visibility of the ModalWindow use the show and hide methods.
|
||||
*/
|
||||
class ModalWindow : public Container
|
||||
{
|
||||
public:
|
||||
ModalWindow();
|
||||
|
||||
/**
|
||||
* Sets the background of the actual window. The remaining area of the screen will be
|
||||
* covered by the shade. The background image is centered on the screen.
|
||||
*
|
||||
* @param bmpId Identifier for the background bitmap.
|
||||
*/
|
||||
virtual void setBackground(const BitmapId& bmpId);
|
||||
|
||||
/**
|
||||
* Sets the background of the actual window. The remaining area of the screen will be
|
||||
* covered by the shade. The background image will be placed at the backgroundX and
|
||||
* backgroundY coordinate.
|
||||
*
|
||||
* @param bmpId Identifier for the bitmap.
|
||||
* @param backgroundX The background x coordinate.
|
||||
* @param backgroundY The background y coordinate.
|
||||
*/
|
||||
virtual void setBackground(const BitmapId& bmpId, int16_t backgroundX, int16_t backgroundY);
|
||||
|
||||
/**
|
||||
* Gets the width of the actual window (the background images). Whereas the getWidth()
|
||||
* method will return the width including the shade.
|
||||
*
|
||||
* @return The width of the actual window.
|
||||
*/
|
||||
virtual uint16_t getBackgroundWidth() const;
|
||||
|
||||
/**
|
||||
* Gets the height of the actual window (the background images). Whereas the getHeight()
|
||||
* method will return the height including the shade.
|
||||
*
|
||||
* @return The height of the actual window.
|
||||
*/
|
||||
virtual uint16_t getBackgroundHeight() const;
|
||||
|
||||
virtual void add(Drawable& d);
|
||||
|
||||
virtual void remove(Drawable& d);
|
||||
|
||||
/**
|
||||
* Sets the alpha value of the background shade. Default, if not set, is 96.
|
||||
*
|
||||
* @param alpha The new alpha.
|
||||
*/
|
||||
virtual void setShadeAlpha(uint8_t alpha);
|
||||
|
||||
/**
|
||||
* Gets the alpha value of the background shade.
|
||||
*
|
||||
* @return The background shades alpha.
|
||||
*/
|
||||
virtual uint8_t getShadeAlpha() const;
|
||||
|
||||
/**
|
||||
* Sets the color of the background shade. Default is black.
|
||||
*
|
||||
* @param color The new color.
|
||||
*/
|
||||
virtual void setShadeColor(colortype color);
|
||||
|
||||
/**
|
||||
* Gets the color of the background shade.
|
||||
*
|
||||
* @return The color of the background shade.
|
||||
*/
|
||||
virtual colortype getShadeColor() const;
|
||||
|
||||
/** Make the ModalWindow visible. */
|
||||
virtual void show();
|
||||
|
||||
/** Make the ModalWindow invisible. */
|
||||
virtual void hide();
|
||||
|
||||
protected:
|
||||
Box backgroundShade; ///< The background shade
|
||||
Container windowContainer; ///< The window container that defines the active container area where both the windowBackground and added drawables are placed.
|
||||
Image windowBackground; ///< The window background
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_MODALWINDOW_HPP
|
||||
@ -0,0 +1,405 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/ScrollableContainer.hpp
|
||||
*
|
||||
* Declares the touchgfx::ScrollableContainer class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_SCROLLABLECONTAINER_HPP
|
||||
#define TOUCHGFX_SCROLLABLECONTAINER_HPP
|
||||
|
||||
#include <touchgfx/containers/Container.hpp>
|
||||
#include <touchgfx/events/ClickEvent.hpp>
|
||||
#include <touchgfx/events/DragEvent.hpp>
|
||||
#include <touchgfx/events/GestureEvent.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/Box.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A ScrollableContainer is a container that allows its contents to be scrolled. It will
|
||||
* intercept drag operations and move child nodes accordingly.
|
||||
*
|
||||
* A standard Container will simply clip children that are either larger than the
|
||||
* container itself, or children that extend beyond the borders of the container or
|
||||
* children that are placed outside the borders of the container. A ScrollableContainer
|
||||
* behaves much like a Container, except it enables the user to scroll the children and
|
||||
* thereby act like a viewport. When the contents of the ScrollableContainer is
|
||||
* scrollable, scrollbars can be seen near the edge of the ScrollableContainer.
|
||||
*
|
||||
* @see Container
|
||||
*
|
||||
* @note The ScrollableContainer will consume all DragEvents in the area covered by the
|
||||
* container.
|
||||
*/
|
||||
class ScrollableContainer : public Container
|
||||
{
|
||||
public:
|
||||
ScrollableContainer();
|
||||
|
||||
/**
|
||||
* Enables horizontal scrolling. By default, scrolling in either direction is enabled,
|
||||
* provided that the content is larger than the size of the ScrollableContainer. This
|
||||
* function can be used to explicitly (dis)allow horizontal scrolling, even if the
|
||||
* content is larger than the container.
|
||||
*
|
||||
* @param enable If true (default), horizontal scrolling is enabled. If false, horizontal
|
||||
* scrolling is disabled.
|
||||
*
|
||||
* @see enableVerticalScroll
|
||||
*/
|
||||
void enableHorizontalScroll(bool enable)
|
||||
{
|
||||
scrollableX = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables vertical scrolling. By default, scrolling in either direction is enabled,
|
||||
* provided that the content is larger than the size of the ScrollableContainer. This
|
||||
* function can be used to explicitly (dis)allow vertical scrolling, even if the content
|
||||
* is larger than the container.
|
||||
*
|
||||
* @param enable If true (default), vertical scrolling is enabled. If false, vertical
|
||||
* scrolling is disabled.
|
||||
*
|
||||
* @see enableHorizontalScroll
|
||||
*/
|
||||
void enableVerticalScroll(bool enable)
|
||||
{
|
||||
scrollableY = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the ClickableContainer scrollable in either direction? Takes the width of the
|
||||
* contained elements into account and also checks to see if horizontal or vertical
|
||||
* scrolling is allowed.
|
||||
*
|
||||
* @param [out] scrollX True if the container is able to scroll horizontally.
|
||||
* @param [out] scrollY True if the container is able to scroll vertically.
|
||||
*
|
||||
* @see enableHorizontalScroll, enableVerticalScroll
|
||||
*/
|
||||
virtual void isScrollableXY(bool& scrollX, bool& scrollY)
|
||||
{
|
||||
Rect contained = getContainedArea();
|
||||
scrollX = (scrollableX && (rect.width < contained.width));
|
||||
scrollY = (scrollableY && (rect.height < contained.height));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the visibility of the scrollbars, when the scrollable area is pressed. By
|
||||
* default the scrollbars are hidden, but shown when the contents of the
|
||||
* ScrollableContainer is being dragged around. Using setScrollbarsVisible, it is
|
||||
* possible to hide the scrollbars when dragging the contents.
|
||||
*
|
||||
* @param newVisible If true (default), the scrollbars are visible when scrollable area is
|
||||
* pressed. If false, scrollbars are always hidden.
|
||||
*
|
||||
* @see setScrollbarsPermanentlyVisible
|
||||
*/
|
||||
void setScrollbarsVisible(bool newVisible);
|
||||
|
||||
/**
|
||||
* Make scrollbars permanently visible regardless of the size and position of the
|
||||
* children of the ScrollableContainer. Normally the scrollbars are hidden and only
|
||||
* shown when dragging the contents of the ScrollableContainer (unless prohibited using
|
||||
* setScrollbarsVisible()).
|
||||
*
|
||||
* @param permanentlyVisible (Optional) True to show the scrollbars permanently, false for default behavior.
|
||||
*
|
||||
* @see setScrollbarsVisible
|
||||
*/
|
||||
void setScrollbarsPermanentlyVisible(bool permanentlyVisible = true);
|
||||
|
||||
virtual void add(Drawable& d);
|
||||
|
||||
virtual void getLastChild(int16_t x, int16_t y, Drawable** last)
|
||||
{
|
||||
if (isVisible())
|
||||
{
|
||||
if (isTouchable())
|
||||
{
|
||||
*last = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
Container::getLastChild(x, y, last);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void handleClickEvent(const ClickEvent& event);
|
||||
|
||||
virtual void handleDragEvent(const DragEvent& event);
|
||||
|
||||
virtual void handleGestureEvent(const GestureEvent& event);
|
||||
|
||||
virtual void handleTickEvent();
|
||||
|
||||
/**
|
||||
* Gets the area that contains all children added to the ScrollableContainer. The
|
||||
* scrollbars are not considered in this operation. The area also includes the
|
||||
* scrollableContainer itself.
|
||||
*
|
||||
* @return The contained area.
|
||||
*
|
||||
* @see getChildrenContainedArea
|
||||
*/
|
||||
virtual Rect getContainedArea() const;
|
||||
|
||||
/**
|
||||
* Gets the area that contains all children added to the ScrollableContainer. The
|
||||
* container itself and scrollbars are not considered in this operation.
|
||||
*
|
||||
* @return The area containing only the children.
|
||||
*
|
||||
* @see getContainedArea
|
||||
*/
|
||||
virtual Rect getChildrenContainedArea() const;
|
||||
|
||||
/**
|
||||
* Used to signal that the size or position of one or more children have changed. This
|
||||
* function can be called on parent nodes to signal that the size of one or more of its
|
||||
* children have changed.
|
||||
*/
|
||||
virtual void childGeometryChanged();
|
||||
|
||||
/**
|
||||
* Resets the ScrollableContainer to its original state, before the user started
|
||||
* dragging the contents. This reset the x/y coordinates of children to the position
|
||||
* they were in before the first drag event was received.
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* @copydoc Container::moveChildrenRelative
|
||||
*
|
||||
* @note Takes care not to move the scrollbars, which are also children.
|
||||
* @note This function is scheduled to be deprecated. Use doScroll() instead.
|
||||
*/
|
||||
virtual void moveChildrenRelative(int16_t deltaX, int16_t deltaY);
|
||||
|
||||
/**
|
||||
* Sets the maximum velocity of a scroll due to a swipe. This can be used to force
|
||||
* smooth scrolling by limiting the speed of any swipe gesture.
|
||||
*
|
||||
* @param max The maximum velocity of the scroll.
|
||||
*
|
||||
* @see GestureEvent::getVelocity
|
||||
*/
|
||||
void setMaxVelocity(uint16_t max)
|
||||
{
|
||||
maxVelocity = max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the threshold which the first drag event received must exceed before
|
||||
* initiating a scroll. This can be used to avoid touching the screen and moving the
|
||||
* finger only a few pixels resulting in the contents being scrolled.
|
||||
*
|
||||
* @param t The new threshold value.
|
||||
*
|
||||
* @note All subsequent scrolls will be processed regardless of threshold value until a
|
||||
* ClickEvent::RELEASED is received.
|
||||
*/
|
||||
void setScrollThreshold(int16_t t)
|
||||
{
|
||||
scrollThreshold = t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color of the scrollbars.
|
||||
*
|
||||
* @param color The color of the box.
|
||||
*/
|
||||
void setScrollbarsColor(colortype color);
|
||||
|
||||
/**
|
||||
* Sets the alpha value (transparency) of the scrollbars.
|
||||
*
|
||||
* @param alpha The alpha value. 255 being completely solid, 0 being completely invisible.
|
||||
*/
|
||||
void setScrollbarsAlpha(uint8_t alpha);
|
||||
|
||||
/**
|
||||
* Sets the amount of space between the scrollbar and the edge of the ScrollableContainer.
|
||||
*
|
||||
* @param padding The padding.
|
||||
*/
|
||||
void setScrollbarPadding(uint8_t padding);
|
||||
|
||||
/**
|
||||
* Sets the width of the scrollbar measured in pixels.
|
||||
*
|
||||
* @param width The width of the scrollbar.
|
||||
*/
|
||||
void setScrollbarWidth(uint8_t width);
|
||||
|
||||
/**
|
||||
* Gets the distance scrolled for the x-axis.
|
||||
*
|
||||
* @return the distance scrolled for the x-axis.
|
||||
*/
|
||||
int16_t getScrolledX() const;
|
||||
|
||||
/**
|
||||
* Gets the distance scrolled for the y-axis.
|
||||
*
|
||||
* @return the distance scrolled for the y-axis.
|
||||
*/
|
||||
int16_t getScrolledY() const;
|
||||
|
||||
/**
|
||||
* Sets scroll duration speedup multiplier. Default value is 7 which gives a nice speedup on gestures.
|
||||
*
|
||||
* @param speedup The scroll duration speedup multiplier.
|
||||
*
|
||||
* @see getScrollDurationSpeedup, setScrollDurationSlowdown
|
||||
*/
|
||||
void setScrollDurationSpeedup(uint16_t speedup);
|
||||
|
||||
/**
|
||||
* Gets scroll duration speedup multiplier.
|
||||
*
|
||||
* @return The swipe acceleration.
|
||||
*
|
||||
* @see setScrollDurationSpeedup, getScrollDurationSlowdown
|
||||
*/
|
||||
uint16_t getScrollDurationSpeedup() const;
|
||||
|
||||
/**
|
||||
* Sets scroll duration speedup divisor. Default value is 1.
|
||||
*
|
||||
* @param slowdown The scroll duration speedup divisor.
|
||||
*
|
||||
* @see setScrollDurationSpeedup, getScrollDurationSlowdown
|
||||
*/
|
||||
void setScrollDurationSlowdown(uint16_t slowdown);
|
||||
|
||||
/**
|
||||
* Gets scroll duration speedup divisor.
|
||||
*
|
||||
* @return The scroll duration speedup divisor.
|
||||
*
|
||||
* @see setScrollDurationSlowdown
|
||||
*/
|
||||
uint16_t getScrollDurationSlowdown() const;
|
||||
|
||||
/**
|
||||
* Method to actually scroll the container. Passing negative values will scroll the
|
||||
* items in the ScrollableContainer up / left, whereas positive values will scroll items
|
||||
* down / right.
|
||||
*
|
||||
* If the distance is larger than allowed, the deltas are adjusted down to make sure the
|
||||
* contained items stay inside view.
|
||||
*
|
||||
* @param deltaX The horizontal amount to scroll.
|
||||
* @param deltaY The vertical amount to scroll.
|
||||
*
|
||||
* @return did the container actually scroll. The call doScroll(0,0) will always return
|
||||
* false.
|
||||
*/
|
||||
virtual bool doScroll(int16_t deltaX, int16_t deltaY);
|
||||
|
||||
protected:
|
||||
uint8_t scrollbarPadding; ///< The amount of padding. The scrollbar will have a bit of space to the borders of the container.
|
||||
uint8_t scrollbarWidth; ///< The width of the scrollbar.
|
||||
uint8_t scrollbarAlpha; ///< The scrollbar is semitransparent
|
||||
static const uint8_t SCROLLBAR_LINE = 0; ///< The scrollbar line.
|
||||
colortype scrollbarColor; ///< The color of the scrollbar
|
||||
static const uint16_t SCROLLBAR_MIN_VELOCITY = 5; ///< The minimum velocity of a scroll due to a swipe
|
||||
static const uint16_t SCROLLBAR_MAX_VELOCITY = 17; ///< The (default) maximum velocity of a scroll due to a swipe
|
||||
uint16_t maxVelocity; ///< The maximum velocity of a scroll (due to a swipe)
|
||||
|
||||
/**
|
||||
* Gets x coordinate of the scrollbar.
|
||||
*
|
||||
* @return The horizontal scrollbar area.
|
||||
*/
|
||||
Rect getXScrollbar() const;
|
||||
|
||||
/**
|
||||
* Gets y coordinate of the scrollbar.
|
||||
*
|
||||
* @return The vertical scrollbar area.
|
||||
*/
|
||||
Rect getYScrollbar() const;
|
||||
|
||||
/**
|
||||
* Gets the area where the horizontal scrollbar can move.
|
||||
*
|
||||
* @param xBar The current horizontal scrollbar, supplied for caching reasons.
|
||||
* @param yBar The current vertical scrollbar, supplied for caching reasons.
|
||||
*
|
||||
* @return The area.
|
||||
*/
|
||||
Rect getXBorder(const Rect& xBar, const Rect& yBar) const;
|
||||
|
||||
/**
|
||||
* Gets the area where the vertical scrollbar can move.
|
||||
*
|
||||
* @param xBar The current horizontal scrollbar, supplied for caching reasons.
|
||||
* @param yBar The current vertical scrollbar, supplied for caching reasons.
|
||||
*
|
||||
* @return The area.
|
||||
*/
|
||||
Rect getYBorder(const Rect& xBar, const Rect& yBar) const;
|
||||
|
||||
/** Invalidate the scrollbars. */
|
||||
void invalidateScrollbars();
|
||||
|
||||
GestureEvent::GestureEventType accelDirection; ///< The current direction (horizontal or vertical) of scroll
|
||||
|
||||
Box xSlider; ///< The horizontal scrollbar drawable
|
||||
Box ySlider; ///< The vertical scrollbar drawable
|
||||
|
||||
Drawable* pressedDrawable; ///< The drawable child of this container which received the last ClickEvent::PRESSED notification. When scrolling, send this drawable a CANCEL event if the new x/y coords no longer matches this drawable.
|
||||
Drawable* lastDraggableChild; ///< The drawable child of this container which should receive drag events. Note that only drag events in directions which cannot be scrolled by this ScrollableContainer will be forwarded to children.
|
||||
|
||||
int16_t scrolledXDistance; ///< The scrolled horizontal distance
|
||||
int16_t scrolledYDistance; ///< The scrolled vertical distance
|
||||
int16_t scrollThreshold; ///< The threshold which the first drag event received must exceed before scrolling. Default is 5.
|
||||
|
||||
int16_t pressedX; ///< The x coordinate where the last ClickEvent::PRESSED was received.
|
||||
int16_t pressedY; ///< The y coordinate where the last ClickEvent::PRESSED was received.
|
||||
|
||||
bool isPressed; ///< Is the container currently pressed (maybe show scrollbars)
|
||||
bool isScrolling; ///< Is the container scrolling (i.e. has overcome the initial larger drag that is required to initiate a scroll).
|
||||
|
||||
bool scrollableX; ///< Is the container scrollable in the horizontal direction.
|
||||
bool scrollableY; ///< Is the container scrollable in the vertical direction.
|
||||
|
||||
bool scrollbarsVisible; ///< Are scrollbars visible.
|
||||
bool scrollbarsPermanentlyVisible; ///< Are scrollbars always visible.
|
||||
|
||||
uint16_t scrollDuration; ///< Number of ticks the scroll animation should use.
|
||||
|
||||
int16_t beginningValue; ///< Initial X or Y for calculated values in scroll animation.
|
||||
int16_t targetValue; ///< Target X or Y value for scroll animation
|
||||
|
||||
uint16_t animationCounter; ///< Current step/tick in scroll animation.
|
||||
bool animate; ///< Is scroll animation currently active
|
||||
|
||||
int16_t fingerAdjustmentX; ///< How much should the finger be adjusted horizontally
|
||||
int16_t fingerAdjustmentY; ///< and how much vertically
|
||||
|
||||
bool hasIssuedCancelEvent; ///< true if the pressed drawable has received cancel event
|
||||
|
||||
uint16_t scrollDurationSpeedup; ///< The scroll durations is multipled by this number
|
||||
uint16_t scrollDurationSlowdown; ///< The scroll durations is divided by this number
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_SCROLLABLECONTAINER_HPP
|
||||
@ -0,0 +1,380 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/SlideMenu.hpp
|
||||
*
|
||||
* Declares the touchgfx::SlideMenu class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_SLIDEMENU_HPP
|
||||
#define TOUCHGFX_SLIDEMENU_HPP
|
||||
|
||||
#include <touchgfx/Bitmap.hpp>
|
||||
#include <touchgfx/Callback.hpp>
|
||||
#include <touchgfx/EasingEquations.hpp>
|
||||
#include <touchgfx/containers/Container.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/mixins/MoveAnimator.hpp>
|
||||
#include <touchgfx/widgets/AbstractButton.hpp>
|
||||
#include <touchgfx/widgets/Button.hpp>
|
||||
#include <touchgfx/widgets/Image.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* SlideMenu is a menu that can expand and collapse at the touch of a button. The SlideMenu can
|
||||
* expand in any of the four directions. Menu items can be added, just like items are
|
||||
* added to a normal container.
|
||||
*
|
||||
* The relative positions of the background and state change button is configurable as
|
||||
* is the direction in which the SlideMenu expands and collapses. How much of the
|
||||
* SlideMenu that is visible when collapsed can also be set with the. It is, of course,
|
||||
* important that the state change button is accessible when collapsed. The SlideMenu
|
||||
* will collapse after a given timeout is reached. The timer can be reset, for example
|
||||
* when the user interacts with elements in the list.
|
||||
*
|
||||
* Menu elements are added normally using the add() method and are positioned relative
|
||||
* to the SlideMenu.
|
||||
*/
|
||||
class SlideMenu : public Container
|
||||
{
|
||||
public:
|
||||
/** Values that represent the SlideMenu states. */
|
||||
enum State
|
||||
{
|
||||
COLLAPSED, ///< Menu is currently collapsed
|
||||
EXPANDED ///< Menu is currently expanded
|
||||
};
|
||||
|
||||
/** Values that represent the expand directions. */
|
||||
enum ExpandDirection
|
||||
{
|
||||
SOUTH, ///< Menu expands downwards (<b>Towards</b> the south)
|
||||
NORTH, ///< Menu expands upwards (<b>Towards</b> the north)
|
||||
EAST, ///< Menu expands to the right (<b>Towards</b> the east)
|
||||
WEST ///< Menu expands to the left (<b>Towards</b> the west)
|
||||
};
|
||||
|
||||
SlideMenu();
|
||||
|
||||
virtual ~SlideMenu();
|
||||
|
||||
/**
|
||||
* Setup the SlideMenu by positioning the stateChangeButton next to background image
|
||||
* relative to the expand direction, and center it in the other dimension. The width and
|
||||
* height of the SlideMenu will be automatically set to span both elements. Default
|
||||
* values are: expandedStateTimeout = 200, visiblePixelsWhenCollapsed = 0,
|
||||
* hiddenPixelsWhenExpanded = 0, animationDuration = 10, animationEquation =
|
||||
* cubicEaseInOut.
|
||||
*
|
||||
* @param newExpandDirection The new expand direction.
|
||||
* @param backgroundBMP The background bitmap.
|
||||
* @param stateChangeButtonBMP The state change button bitmap.
|
||||
* @param stateChangeButtonPressedBMP The state change button pressed bitmap.
|
||||
*/
|
||||
virtual void setup(ExpandDirection newExpandDirection, const Bitmap& backgroundBMP, const Bitmap& stateChangeButtonBMP, const Bitmap& stateChangeButtonPressedBMP);
|
||||
|
||||
/**
|
||||
* Setup method for the SlideMenu. Positioning of the background is done by stating
|
||||
* the X and Y coordinates for the element (relative to the SlideMenu).
|
||||
* The width and height of the SlideMenu will be automatically set to the size of the background.
|
||||
* Default values are: expandedStateTimeout = 200, visiblePixelsWhenCollapsed = 0,
|
||||
* hiddenPixelsWhenExpanded = 0, animationDuration * = 10, animationEquation = cubicEaseInOut.
|
||||
*
|
||||
* @param newExpandDirection The new expand direction.
|
||||
* @param backgroundBMP The background bitmap.
|
||||
* @param backgroundX The background x coordinate.
|
||||
* @param backgroundY The background y coordinate.
|
||||
*/
|
||||
virtual void setup(ExpandDirection newExpandDirection, const Bitmap& backgroundBMP, int16_t backgroundX, int16_t backgroundY);
|
||||
|
||||
/**
|
||||
* Setup method for the SlideMenu. Positioning of the background image and the
|
||||
* stateChangeButton is done by stating the X and Y coordinates for the elements
|
||||
* (relative to the SlideMenu). The width and height of the SlideMenu will be
|
||||
* automatically set to span both elements. Default values are: expandedStateTimeout =
|
||||
* 200, visiblePixelsWhenCollapsed = 0, hiddenPixelsWhenExpanded = 0, animationDuration
|
||||
* = 10, animationEquation = cubicEaseInOut.
|
||||
*
|
||||
* @param newExpandDirection The new expand direction.
|
||||
* @param backgroundBMP The background bitmap.
|
||||
* @param stateChangeButtonBMP The state change button bitmap.
|
||||
* @param stateChangeButtonPressedBMP The state change button pressed bitmap.
|
||||
* @param backgroundX The background x coordinate.
|
||||
* @param backgroundY The background y coordinate.
|
||||
* @param stateChangeButtonX The state change button x coordinate.
|
||||
* @param stateChangeButtonY The state change button y coordinate.
|
||||
*/
|
||||
virtual void setup(ExpandDirection newExpandDirection, const Bitmap& backgroundBMP, const Bitmap& stateChangeButtonBMP, const Bitmap& stateChangeButtonPressedBMP, int16_t backgroundX, int16_t backgroundY, int16_t stateChangeButtonX, int16_t stateChangeButtonY);
|
||||
|
||||
/**
|
||||
* Sets the expand direction.
|
||||
*
|
||||
* @param newExpandDirection The new expand direction.
|
||||
*/
|
||||
virtual void setExpandDirection(ExpandDirection newExpandDirection);
|
||||
|
||||
/**
|
||||
* Gets the expand direction.
|
||||
*
|
||||
* @return The expand direction.
|
||||
*/
|
||||
virtual ExpandDirection getExpandDirection() const;
|
||||
|
||||
/**
|
||||
* Sets the amount of visible pixels when collapsed.
|
||||
*
|
||||
* @param visiblePixels The visible pixels.
|
||||
*/
|
||||
virtual void setVisiblePixelsWhenCollapsed(int16_t visiblePixels);
|
||||
|
||||
/**
|
||||
* Gets the visible pixels when collapsed.
|
||||
*
|
||||
* @return The visible pixels when collapsed.
|
||||
*/
|
||||
virtual int16_t getVisiblePixelsWhenCollapsed() const;
|
||||
|
||||
/**
|
||||
* Sets the amount of hidden pixels when expanded.
|
||||
*
|
||||
* @param hiddenPixels The hidden pixels.
|
||||
*/
|
||||
virtual void setHiddenPixelsWhenExpanded(int16_t hiddenPixels);
|
||||
|
||||
/**
|
||||
* Gets the hidden pixels when expanded.
|
||||
*
|
||||
* @return The hidden pixels when expanded.
|
||||
*/
|
||||
virtual int16_t getHiddenPixelsWhenExpanded() const;
|
||||
|
||||
/**
|
||||
* Sets the expanded state timeout in ticks. The SlideMenu will animate to the COLLAPSED
|
||||
* state when this number of ticks has been executed while the SlideMenu is in the
|
||||
* EXPANDED state. The timer can be reset with the resetExpandedStateTimer method.
|
||||
*
|
||||
* @param timeout The timeout in ticks.
|
||||
*/
|
||||
virtual void setExpandedStateTimeout(uint16_t timeout);
|
||||
|
||||
/**
|
||||
* Gets expanded state timeout.
|
||||
*
|
||||
* @return The expanded state timeout.
|
||||
*/
|
||||
virtual uint16_t getExpandedStateTimeout() const;
|
||||
|
||||
/**
|
||||
* Sets the animation duration.
|
||||
*
|
||||
* @param duration The animation duration.
|
||||
*/
|
||||
virtual void setAnimationDuration(uint16_t duration);
|
||||
|
||||
/**
|
||||
* Gets the animation duration.
|
||||
*
|
||||
* @return The animation duration.
|
||||
*/
|
||||
virtual uint16_t getAnimationDuration() const;
|
||||
|
||||
/**
|
||||
* Sets the animation easing equation.
|
||||
*
|
||||
* @param animationEasingEquation The animation easing equation.
|
||||
*/
|
||||
virtual void setAnimationEasingEquation(EasingEquation animationEasingEquation);
|
||||
|
||||
/**
|
||||
* Gets the animation easing equation.
|
||||
*
|
||||
* @return The animation easing equation.
|
||||
*/
|
||||
virtual EasingEquation getAnimationEasingEquation() const;
|
||||
|
||||
/**
|
||||
* Sets the state of the SlideMenu. No animation is performed.
|
||||
*
|
||||
* @param newState The new state of the SlideMenu.
|
||||
*
|
||||
* @see animateToState, getState
|
||||
*/
|
||||
virtual void setState(State newState);
|
||||
|
||||
/**
|
||||
* Animate to the given expanded or collapsed state.
|
||||
*
|
||||
* @param newState The new state of the SlideMenu.
|
||||
*
|
||||
* @see setState, getState
|
||||
*/
|
||||
virtual void animateToState(State newState);
|
||||
|
||||
/**
|
||||
* Gets the current expanded or collapsed state.
|
||||
*
|
||||
* @return The current state.
|
||||
*
|
||||
* @see setState, animateToState
|
||||
*/
|
||||
virtual State getState();
|
||||
|
||||
/**
|
||||
* Resets the expanded state timer. The SlideMenu will automatically animate to the
|
||||
* COLLAPSED state after a number of ticks, as set with setExpandedStateTimeout(). This
|
||||
* method resets this timer.
|
||||
*
|
||||
* @see getExpandedStateTimer
|
||||
*/
|
||||
virtual void resetExpandedStateTimer();
|
||||
|
||||
/**
|
||||
* Gets the expanded state timer.
|
||||
*
|
||||
* @return The expanded state timer.
|
||||
*
|
||||
* @see resetExpandedStateTimer
|
||||
*/
|
||||
virtual uint16_t getExpandedStateTimer() const;
|
||||
|
||||
/**
|
||||
* Gets the background Image x coordinate.
|
||||
*
|
||||
* @return The background Image x coordinate.
|
||||
*/
|
||||
virtual int16_t getBackgroundX() const;
|
||||
|
||||
/**
|
||||
* Gets the background Image y coordinate.
|
||||
*
|
||||
* @return The background Image y coordinate.
|
||||
*/
|
||||
virtual int16_t getBackgroundY() const;
|
||||
|
||||
/**
|
||||
* Gets the state change button x coordinate.
|
||||
*
|
||||
* @return The state change button x coordinate.
|
||||
*/
|
||||
virtual int16_t getStateChangeButtonX() const;
|
||||
|
||||
/**
|
||||
* Gets the state change button y coordinate.
|
||||
*
|
||||
* @return The state change button y coordinate.
|
||||
*/
|
||||
virtual int16_t getStateChangeButtonY() const;
|
||||
|
||||
/**
|
||||
* Set the state changed callback. This callback is called when the state change button
|
||||
* is clicked.
|
||||
*
|
||||
* @param callback The callback.
|
||||
*/
|
||||
virtual void setStateChangedCallback(GenericCallback<const SlideMenu&>& callback);
|
||||
|
||||
/**
|
||||
* Set the state change animation ended callback. This callback is called when a state
|
||||
* change animation has ended.
|
||||
*
|
||||
* @param callback The callback.
|
||||
*/
|
||||
virtual void setStateChangedAnimationEndedCallback(GenericCallback<const SlideMenu&>& callback);
|
||||
|
||||
/**
|
||||
* Adds a drawable to the container. Make sure the x and y coordinates of the Drawable
|
||||
* is correct relative to the SlideMenu.
|
||||
*
|
||||
* @param [in] d The drawable to add.
|
||||
*/
|
||||
virtual void add(Drawable& d);
|
||||
|
||||
/**
|
||||
* Removes the drawable from the container.
|
||||
*
|
||||
* @param [in] d The drawable to remove.
|
||||
*/
|
||||
virtual void remove(Drawable& d);
|
||||
|
||||
virtual void handleTickEvent();
|
||||
|
||||
protected:
|
||||
MoveAnimator<Container> menuContainer; ///< The container holding the actual menu items. This is the container that performs the state change animation
|
||||
Button stateChangeButton; ///< The state change button that toggles the SlideMenu state
|
||||
Image background; ///< The background of the SlideMenu
|
||||
|
||||
Callback<SlideMenu, const AbstractButton&> onStateChangeButtonClicked; ///< The local state changed button clicked callback
|
||||
Callback<SlideMenu, const MoveAnimator<Container>&> animationEndedCallback; ///< The local state changed animation ended callback
|
||||
|
||||
GenericCallback<const SlideMenu&>* stateChangedCallback; ///< The public state changed button clicked callback
|
||||
GenericCallback<const SlideMenu&>* stateChangedAnimationEndedCallback; ///< The public state changed animation ended callback
|
||||
|
||||
State currentState; ///< The current state of the SlideMenu
|
||||
ExpandDirection expandDirection; ///< The expand direction of the SlideMenu
|
||||
|
||||
EasingEquation animationEquation; ///< The easing equation used for the state change animation
|
||||
|
||||
int16_t visiblePixelsWhenCollapsed; ///< The number of visible pixels when collapsed
|
||||
int16_t hiddenPixelsWhenExpanded; ///< The number of hidden pixels when expanded
|
||||
|
||||
uint16_t expandedStateTimeout; ///< The expanded state timeout.
|
||||
uint16_t expandedStateTimer; ///< The timer that counts towards the expandedStateTimeout. If reached the SlideMenu will animate to COLLAPSED.
|
||||
|
||||
uint16_t animationDuration; ///< The animation duration of the state change animation
|
||||
|
||||
/**
|
||||
* Handler for the state change button clicked event.
|
||||
*
|
||||
* @param button The state change button.
|
||||
*/
|
||||
void stateChangeButtonClickedHandler(const AbstractButton& button);
|
||||
|
||||
/**
|
||||
* Handler for the state change animation ended event.
|
||||
*
|
||||
* @param container The menuContainer.
|
||||
*/
|
||||
void animationEndedHandler(const MoveAnimator<Container>& container);
|
||||
|
||||
/**
|
||||
* Gets the x coordinate for the collapsed state.
|
||||
*
|
||||
* @return The collapsed x coordinate.
|
||||
*/
|
||||
virtual int16_t getCollapsedXCoordinate();
|
||||
|
||||
/**
|
||||
* Gets the y coordinate for the collapsed state.
|
||||
*
|
||||
* @return The collapsed y coordinate.
|
||||
*/
|
||||
virtual int16_t getCollapsedYCoordinate();
|
||||
|
||||
/**
|
||||
* Gets the x coordinate for the expanded state.
|
||||
*
|
||||
* @return The expanded x coordinate.
|
||||
*/
|
||||
virtual int16_t getExpandedXCoordinate();
|
||||
|
||||
/**
|
||||
* Gets the y coordinate for the expanded state.
|
||||
*
|
||||
* @return The expanded y coordinate.
|
||||
*/
|
||||
virtual int16_t getExpandedYCoordinate();
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_SLIDEMENU_HPP
|
||||
@ -0,0 +1,363 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/Slider.hpp
|
||||
*
|
||||
* Declares the touchgfx::Slider class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_SLIDER_HPP
|
||||
#define TOUCHGFX_SLIDER_HPP
|
||||
|
||||
#include <touchgfx/Bitmap.hpp>
|
||||
#include <touchgfx/Callback.hpp>
|
||||
#include <touchgfx/containers/Container.hpp>
|
||||
#include <touchgfx/events/ClickEvent.hpp>
|
||||
#include <touchgfx/events/DragEvent.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/Image.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A slider is a graphical element with which the user may set a value by moving an indicator on
|
||||
* a slider, or simply by clicking the slider. The slider can operate in horizontal or
|
||||
* vertical mode. The slider has two bitmaps. One bitmap is used on one side of the
|
||||
* indicator. The other is used on the other side. They can be used in indicating the
|
||||
* part of the slider value range that is currently selected.
|
||||
*
|
||||
* The slider operates on an integer value range that can be set by the user.
|
||||
*/
|
||||
class Slider : public Container
|
||||
{
|
||||
public:
|
||||
Slider();
|
||||
|
||||
/**
|
||||
* Sets all the bitmaps for the Slider. The Slider shows the sliderBackgroundSelected
|
||||
* bitmap in the region of the Slider that is selected, that is the area to the left of
|
||||
* the indicator for a horizontal Slider and below the indicator for a vertical Slider.
|
||||
* The sliderBackground is shown on the other side of the Slider. To ignore this effect
|
||||
* simply use the same bitmap for both the sliderBackground and the
|
||||
* sliderBackgroundSelected.
|
||||
*
|
||||
* @param sliderBackground The slider background with the slider range
|
||||
* unselected.
|
||||
* @param sliderBackgroundSelected The slider background with the slider range selected.
|
||||
* @param indicator The indicator.
|
||||
*/
|
||||
void setBitmaps(const Bitmap& sliderBackground, const Bitmap& sliderBackgroundSelected, const Bitmap& indicator);
|
||||
|
||||
/**
|
||||
* Sets all the bitmaps for the Slider. The Slider shows the sliderBackgroundSelected
|
||||
* bitmap in the region of the Slider that is selected, that is the area to the left of
|
||||
* the indicator for a horizontal Slider and below the indicator for a vertical Slider.
|
||||
* The sliderBackground is shown on the other side of the Slider. To ignore this effect
|
||||
* simply use the same bitmap for both the sliderBackground and the
|
||||
* sliderBackgroundSelected.
|
||||
*
|
||||
* @param sliderBackground The slider background with the slider range
|
||||
* unselected.
|
||||
* @param sliderBackgroundSelected The slider background with the slider range selected.
|
||||
* @param indicator The indicator.
|
||||
*/
|
||||
void setBitmaps(const BitmapId sliderBackground, const BitmapId sliderBackgroundSelected, const BitmapId indicator);
|
||||
|
||||
/**
|
||||
* Associates an action to be performed when an interaction with the slider is initiated
|
||||
* (click or drag).
|
||||
*
|
||||
* @param callback The callback to be executed. The callback will be given a reference
|
||||
* to the Slider and the current value of the slider at interaction
|
||||
* start.
|
||||
*
|
||||
* @see GenericCallback
|
||||
*/
|
||||
void setStartValueCallback(GenericCallback<const Slider&, int>& callback)
|
||||
{
|
||||
startValueCallback = &callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Associates an action to be performed when an interaction with the slider ends (click
|
||||
* or drag).
|
||||
*
|
||||
* @param callback The callback to be executed. The callback will be given a reference
|
||||
* to the Slider and the current value of the slider at interaction end.
|
||||
*
|
||||
* @see GenericCallback
|
||||
*/
|
||||
void setStopValueCallback(GenericCallback<const Slider&, int>& callback)
|
||||
{
|
||||
stopValueCallback = &callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Associates an action to be performed when the slider changes its value.
|
||||
*
|
||||
* @param callback The callback to be executed. The callback will be given a reference
|
||||
* to the Slider and the current value of the slider.
|
||||
*
|
||||
* @see GenericCallback
|
||||
*/
|
||||
void setNewValueCallback(GenericCallback<const Slider&, int>& callback)
|
||||
{
|
||||
newValueCallback = &callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the slider in horizontal mode with the range going from the left to right.
|
||||
*
|
||||
* Places the backgrounds and the indicator inside the Slider container. It is possible
|
||||
* to place the end points of the indicator outside the background image if it needs to
|
||||
* go beyond the boundaries of the background. The width and height of the Slider will
|
||||
* be adjusted appropriately so that both the background and the indicator will be fully
|
||||
* visible in both the minimum and maximum indicator positions.
|
||||
*
|
||||
* Calls setValue() with the current value (default 0) and triggers the newSliderValue
|
||||
* callback.
|
||||
*
|
||||
* @param backgroundX The background x coordinate inside the slider.
|
||||
* @param backgroundY The background y coordinate inside the slider.
|
||||
* @param indicatorY The indicator y coordinate inside the slider.
|
||||
* @param indicatorMinX The indicator minimum x coordinate inside the slider. This is the
|
||||
* position used when the slider is at its minimum value. Must
|
||||
* be less than indicatorMaxX.
|
||||
* @param indicatorMaxX The indicator maximum x coordinate inside the slider. This is the
|
||||
* position used when the slider is at its maximum value. Must
|
||||
* be greater than indicatorMinX.
|
||||
*
|
||||
* @note The x and y position of the Slider will either be the left/top of the background or
|
||||
* the left/top of the indicator in its minimum x coordinate.
|
||||
*/
|
||||
virtual void setupHorizontalSlider(int16_t backgroundX, int16_t backgroundY, int16_t indicatorY, int16_t indicatorMinX, int16_t indicatorMaxX);
|
||||
|
||||
/**
|
||||
* Sets up the slider in vertical mode with the range going from the bottom to top.
|
||||
*
|
||||
* Places the backgrounds and the indicator inside the Slider container. It is possible
|
||||
* to place the end points of the indicator outside the background image if it needs to
|
||||
* go beyond the boundaries of the background. The width and height of the Slider will
|
||||
* be adjusted appropriately so that both the background and the indicator will be fully
|
||||
* visible in both the minimum and maximum indicator positions.
|
||||
*
|
||||
*
|
||||
* Calls setValue with the current value (default 0) and triggers the newSliderValue
|
||||
* callback.
|
||||
*
|
||||
* @param backgroundX The background x coordinate inside the slider.
|
||||
* @param backgroundY The background y coordinate inside the slider.
|
||||
* @param indicatorX The indicator x coordinate inside the slider.
|
||||
* @param indicatorMinY The indicator minimum y coordinate inside the slider. This is the
|
||||
* position used when the slider is at its maximum value. Must
|
||||
* be less than indicatorMaxX.
|
||||
* @param indicatorMaxY The indicator maximum y coordinate inside the slider. This is the
|
||||
* position used when the slider is at its minimum value. Must
|
||||
* be greater than indicatorMinX.
|
||||
*
|
||||
* @note The x and y position of the Slider will either be the left/top of the background or
|
||||
* the left/top of the indicator in its minimum y coordinate.
|
||||
*/
|
||||
virtual void setupVerticalSlider(int16_t backgroundX, int16_t backgroundY, int16_t indicatorX, int16_t indicatorMinY, int16_t indicatorMaxY);
|
||||
|
||||
/**
|
||||
* Gets indicator minimum previously set using setupHorizontalSlider() or
|
||||
* setupVerticalSlider().
|
||||
*
|
||||
* @return The indicator minimum.
|
||||
*
|
||||
* @see setupHorizontalSlider, setupVerticalSlider, getIndicatorMax
|
||||
*/
|
||||
virtual int16_t getIndicatorMin() const
|
||||
{
|
||||
return indicatorMinPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets indicator maximum previous set using setupHorizontalSlider() or
|
||||
* setupVerticalSlider().
|
||||
*
|
||||
* @return The calculated indicator maximum.
|
||||
*
|
||||
* @see setupHorizontalSlider, setupVerticalSlider, getIndicatorMin
|
||||
*/
|
||||
virtual int16_t getIndicatorMax() const
|
||||
{
|
||||
return indicatorMaxPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value range of the slider. Values accepted and returned by the slider will
|
||||
* be in this range.
|
||||
*
|
||||
* The slider will set its value to the specified new value.
|
||||
*
|
||||
* @param minValue The minimum value. Must be less than maxValue.
|
||||
* @param maxValue The maximum value. Must be greater than minValue.
|
||||
* @param newValue The new value.
|
||||
*
|
||||
* @note If the range is larger than the number of pixels specified for the indicator min and
|
||||
* max some values will not be represented by the slider.
|
||||
*/
|
||||
virtual void setValueRange(int16_t minValue, int16_t maxValue, int16_t newValue);
|
||||
|
||||
/**
|
||||
* Gets the minimum value previously set using setValueRange().
|
||||
*
|
||||
* @return The minimum value.
|
||||
*
|
||||
* @see setValueRange, getMaxValue
|
||||
*/
|
||||
virtual int16_t getMinValue() const
|
||||
{
|
||||
return valueRangeMin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum value previously set using setValueRange().
|
||||
*
|
||||
* @return The maximum value.
|
||||
*
|
||||
* @see setValueRange, getMinValue
|
||||
*/
|
||||
virtual int16_t getMaxValue() const
|
||||
{
|
||||
return valueRangeMax;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value range of the slider. Values accepted and returned by the slider will
|
||||
* be in this range.
|
||||
*
|
||||
* The slider will set its value to the current value or round to minValue or maxValue
|
||||
* if the current value is outside the new range.
|
||||
*
|
||||
* @param minValue The minimum value. Must be less than maxValue.
|
||||
* @param maxValue The maximum value. Must be greater than minValue.
|
||||
*
|
||||
* @note If the range is larger than the number of pixels specified for the indicator min and
|
||||
* indicator max, some values will not be represented by the slider.
|
||||
*/
|
||||
virtual void setValueRange(int16_t minValue, int16_t maxValue);
|
||||
|
||||
/**
|
||||
* Places the indicator at the specified value relative to the specified value range.
|
||||
* Values beyond the value range will be rounded to the min/max value in the value range.
|
||||
*
|
||||
* @param value The value.
|
||||
*
|
||||
* @see setValueRange
|
||||
*
|
||||
* @note The value update triggers a newSliderValue callback just as a drag or click does.
|
||||
* @note If the value range is larger than the number of pixels specified for the indicator
|
||||
* min and indicator max, some values will not be represented by the slider and
|
||||
* thus is not possible to set with this method. In this case the value will be
|
||||
* rounded to the nearest value that is represented in the current setting.
|
||||
*/
|
||||
virtual void setValue(int16_t value);
|
||||
|
||||
/**
|
||||
* Gets the current value represented by the indicator.
|
||||
*
|
||||
* @return The current value.
|
||||
*/
|
||||
int getValue()
|
||||
{
|
||||
return currentValue;
|
||||
}
|
||||
|
||||
virtual void handleClickEvent(const ClickEvent& event);
|
||||
|
||||
virtual void handleDragEvent(const DragEvent& event);
|
||||
|
||||
protected:
|
||||
/** Values that represent slider orientations. */
|
||||
enum SliderOrientation
|
||||
{
|
||||
HORIZONTAL, ///< The Slider can be moved horizontally between left and right
|
||||
VERTICAL ///< The Slider can be moved vertically between top and bottom
|
||||
};
|
||||
|
||||
SliderOrientation sliderOrientation; ///< The selected slider orientation
|
||||
|
||||
int16_t currentValue; ///< The current value represented by the slider
|
||||
|
||||
int16_t valueRangeMin; ///< The value range min
|
||||
int16_t valueRangeMax; ///< The value range max
|
||||
|
||||
Image background; ///< The background image
|
||||
Image backgroundSelected; ///< The backgroundSelected image
|
||||
Image indicator; ///< The indicator image
|
||||
Container backgroundSelectedViewPort; ///< The backgroundSelected view port. Controls the visible part of the backgroundSelected image.
|
||||
|
||||
int16_t indicatorMinPosition; ///< The minimum position of the indicator (either x coordinate in horizontal mode or y coordinate in vertical mode)
|
||||
int16_t indicatorMaxPosition; ///< The maximum position of the indicator (either x coordinate in horizontal mode or y coordinate in vertical mode)
|
||||
|
||||
GenericCallback<const Slider&, int>* startValueCallback; ///< The start value callback (called when an interaction with the indicator is initiated)
|
||||
GenericCallback<const Slider&, int>* stopValueCallback; ///< The stop value callback (called when an interaction with the indicator ends)
|
||||
GenericCallback<const Slider&, int>* newValueCallback; ///< The new value callback (called when the indicator is moved)
|
||||
|
||||
/**
|
||||
* Updates the indicator position described by position. Calls the
|
||||
* newSliderValueCallback with the new value.
|
||||
*
|
||||
* @param position The position (x coordinate in horizontal mode and y coordinate in
|
||||
* vertical mode).
|
||||
*/
|
||||
virtual void updateIndicatorPosition(int16_t position);
|
||||
|
||||
/**
|
||||
* Translate a value in the value range to the corresponding position in the indicator
|
||||
* position range (x coordinate in horizontal mode and y in vertical mode).
|
||||
*
|
||||
* @param value The value.
|
||||
*
|
||||
* @return The coordinate that corresponds to the value.
|
||||
*/
|
||||
virtual int16_t valueToPosition(int value) const;
|
||||
|
||||
/**
|
||||
* Translate a position (x coordinate in horizontal mode and y in vertical mode) in the
|
||||
* indicator position range to the corresponding value in the value range.
|
||||
*
|
||||
* @param position The position.
|
||||
*
|
||||
* @return The value that corresponds to the coordinate.
|
||||
*/
|
||||
virtual int positionToValue(int16_t position) const;
|
||||
|
||||
/**
|
||||
* Gets the indicator radius, which is half the size of the indicator.
|
||||
*
|
||||
* @return The the indicator radius.
|
||||
*/
|
||||
virtual int16_t getIndicatorRadius() const;
|
||||
|
||||
/**
|
||||
* Gets the indicator position range, i.e. the difference between max and min for the
|
||||
* position of the indicator.
|
||||
*
|
||||
* @return The indicator position range.
|
||||
*/
|
||||
virtual int getIndicatorPositionRangeSize() const;
|
||||
|
||||
/**
|
||||
* Gets the value range, i.e. the difference between max and min for the value range.
|
||||
*
|
||||
* @return The value range.
|
||||
*/
|
||||
virtual int getValueRangeSize() const;
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_SLIDER_HPP
|
||||
@ -0,0 +1,222 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/SwipeContainer.hpp
|
||||
*
|
||||
* Declares the touchgfx::SwipeContainer class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_SWIPECONTAINER_HPP
|
||||
#define TOUCHGFX_SWIPECONTAINER_HPP
|
||||
|
||||
#include <touchgfx/containers/ListLayout.hpp>
|
||||
#include <touchgfx/events/ClickEvent.hpp>
|
||||
#include <touchgfx/events/DragEvent.hpp>
|
||||
#include <touchgfx/events/GestureEvent.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/Image.hpp>
|
||||
#include <touchgfx/widgets/TiledImage.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A SwipeContainer is a Container with a horizontally laid out list of identically sized Drawables.
|
||||
* The bottom of the SwipeContainer shows a page indicator to indicate the position in the horizontal
|
||||
* list of items in the SwipeContainer.
|
||||
*
|
||||
* @see ListLayout
|
||||
*/
|
||||
class SwipeContainer : public Container
|
||||
{
|
||||
public:
|
||||
SwipeContainer();
|
||||
virtual ~SwipeContainer();
|
||||
|
||||
virtual void handleTickEvent();
|
||||
virtual void handleClickEvent(const ClickEvent& event);
|
||||
virtual void handleDragEvent(const DragEvent& event);
|
||||
virtual void handleGestureEvent(const GestureEvent& event);
|
||||
|
||||
/**
|
||||
* Adds a page to the container.
|
||||
*
|
||||
* @param [in] page The page to add.
|
||||
*
|
||||
* @note All pages must have the same width and height.
|
||||
*/
|
||||
virtual void add(Drawable& page);
|
||||
|
||||
/**
|
||||
* Removes the page from the container.
|
||||
*
|
||||
* @param [in] page The page to remove.
|
||||
*
|
||||
* @note This is safe to call even if page is not a page (in which case nothing happens).
|
||||
*/
|
||||
virtual void remove(Drawable& page);
|
||||
|
||||
/**
|
||||
* Set the swipe cutoff which indicates how far you should drag a page before it results in
|
||||
* a page change.
|
||||
*
|
||||
* @param cutoff The cutoff in pixels.
|
||||
*/
|
||||
virtual void setSwipeCutoff(uint16_t cutoff);
|
||||
|
||||
/**
|
||||
* Sets the x and y position of the page indicator.
|
||||
*
|
||||
* @param x The x coordinate.
|
||||
* @param y The y coordinate.
|
||||
*
|
||||
* @see setPageIndicatorXYWithCenteredX, setPageIndicatorCenteredX
|
||||
*/
|
||||
void setPageIndicatorXY(int16_t x, int16_t y);
|
||||
|
||||
/**
|
||||
* Sets the x and y position of the page indicator. The value specified as x will be the
|
||||
* center coordinate of the page indicators.
|
||||
*
|
||||
* @param x The center x coordinate.
|
||||
* @param y The y coordinate.
|
||||
*
|
||||
* @see setPageIndicatorCenteredX, setPageIndicatorXY
|
||||
*
|
||||
* @note This method should not be used until all pages have been added, the
|
||||
* setPageIndicatorBitmaps() has been called and the page indicator therefore has the
|
||||
* correct width.
|
||||
*/
|
||||
void setPageIndicatorXYWithCenteredX(int16_t x, int16_t y);
|
||||
|
||||
/**
|
||||
* Sets the page indicator centered inside the SwipeContainer without changing the y
|
||||
* position.
|
||||
*
|
||||
* @see setPageIndicatorXYWithCenteredX, setPageIndicatorXY
|
||||
*
|
||||
* @note This method should not be used until all pages have been added, the
|
||||
* setPageIndicatorBitmaps() has been called and the page indicator therefore has the
|
||||
* correct width.
|
||||
*/
|
||||
void setPageIndicatorCenteredX();
|
||||
|
||||
/**
|
||||
* Sets the x position of the page indicator without changing the y position. The value
|
||||
* specified as x will be the center coordinate of the page indicators.
|
||||
*
|
||||
* @param x The center x coordinate.
|
||||
*
|
||||
* @see setPageIndicatorXYWithCenteredX, setPageIndicatorXY
|
||||
*
|
||||
* @note This method should not be used until all pages have been added, the
|
||||
* setPageIndicatorBitmaps() has been called and the page indicator therefore has the
|
||||
* correct width.
|
||||
*/
|
||||
void setPageIndicatorCenteredX(int16_t x);
|
||||
|
||||
/**
|
||||
* Sets the bitmaps that are used by the page indicator. The bitmap for the normal page is
|
||||
* repeated side-by-side and the bitmap for a highlighted page is put in the proper position.
|
||||
*
|
||||
* @param normalPage The normal page.
|
||||
* @param highlightedPage The highlighted page.
|
||||
*/
|
||||
void setPageIndicatorBitmaps(const Bitmap& normalPage, const Bitmap& highlightedPage);
|
||||
|
||||
/**
|
||||
* When dragging either one of the end pages a part of the background will become visible
|
||||
* until the user stop dragging and the end page swipes back to its position. The width of
|
||||
* this area is set by this method.
|
||||
*
|
||||
* @param width The width in pixels.
|
||||
*/
|
||||
void setEndSwipeElasticWidth(uint16_t width);
|
||||
|
||||
/**
|
||||
* Gets number of pages.
|
||||
*
|
||||
* @return The number of pages.
|
||||
*/
|
||||
uint8_t getNumberOfPages()
|
||||
{
|
||||
return pageIndicator.getNumberOfPages();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the selected page.
|
||||
*
|
||||
* @param pageIndex Zero-based index of the page. Range from 0 to numberOfPages-1.
|
||||
*
|
||||
* @see getSelectedPage
|
||||
*/
|
||||
void setSelectedPage(uint8_t pageIndex);
|
||||
|
||||
/**
|
||||
* Gets the currently selected page.
|
||||
*
|
||||
* @return Zero-based index of the current page. Rage from 0 to numberOfPages-1.
|
||||
*
|
||||
* @see setSelectedPage
|
||||
*/
|
||||
uint8_t getSelectedPage() const;
|
||||
|
||||
private:
|
||||
static const int16_t DRAG_CANCEL_THRESHOLD = 3;
|
||||
|
||||
enum States
|
||||
{
|
||||
ANIMATE_SWIPE_CANCELLED_LEFT,
|
||||
ANIMATE_SWIPE_CANCELLED_RIGHT,
|
||||
ANIMATE_LEFT,
|
||||
ANIMATE_RIGHT,
|
||||
NO_ANIMATION
|
||||
} currentState;
|
||||
|
||||
uint8_t animationCounter;
|
||||
uint16_t swipeCutoff;
|
||||
int16_t dragX;
|
||||
int16_t animateDistance;
|
||||
int16_t startX;
|
||||
uint16_t endElasticWidth;
|
||||
|
||||
ListLayout pages;
|
||||
|
||||
void adjustPages();
|
||||
|
||||
void animateSwipeCancelledLeft();
|
||||
void animateSwipeCancelledRight();
|
||||
void animateLeft();
|
||||
void animateRight();
|
||||
|
||||
class PageIndicator : public Container
|
||||
{
|
||||
public:
|
||||
PageIndicator();
|
||||
void setNumberOfPages(uint8_t size);
|
||||
void setBitmaps(const Bitmap& normalPage, const Bitmap& highlightedPage);
|
||||
void goRight();
|
||||
void goLeft();
|
||||
void setCurrentPage(uint8_t page);
|
||||
uint8_t getNumberOfPages() const;
|
||||
uint8_t getCurrentPage() const;
|
||||
|
||||
private:
|
||||
TiledImage unselectedPages;
|
||||
Image selectedPage;
|
||||
uint8_t numberOfPages;
|
||||
uint8_t currentPage;
|
||||
} pageIndicator;
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_SWIPECONTAINER_HPP
|
||||
@ -0,0 +1,345 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/ZoomAnimationImage.hpp
|
||||
*
|
||||
* Declares the touchgfx::ZoomAnimationImage class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_ZOOMANIMATIONIMAGE_HPP
|
||||
#define TOUCHGFX_ZOOMANIMATIONIMAGE_HPP
|
||||
|
||||
#include <touchgfx/Bitmap.hpp>
|
||||
#include <touchgfx/Callback.hpp>
|
||||
#include <touchgfx/EasingEquations.hpp>
|
||||
#include <touchgfx/containers/Container.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/Image.hpp>
|
||||
#include <touchgfx/widgets/ScalableImage.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* Class for optimizing and wrapping move and zoom operations on a ScalableImage. The
|
||||
* ZoomAnimationImage takes two bitmaps representing the same image but at a small and a
|
||||
* large resolution. These bitmaps should be the sizes that are used when not animating
|
||||
* the image. The ZoomAnimationImage will use an Image for displaying the Bitmap when
|
||||
* its width and height matches either of them. When it does not match the size of one
|
||||
* of the bitmaps, it will use a ScalableImage instead. The main idea is that the
|
||||
* supplied bitmaps should be the end points of the zoom animation so that it ends up
|
||||
* using an Image when not animating. This is, however, not a requirement. You can
|
||||
* animate from and to sizes that are not equal the sizes of the bitmaps. The result is
|
||||
* a container that has the high performance of an ordinary image when the size matches
|
||||
* the pre-rendered bitmaps. Moreover it supplies easy to use animation functions that
|
||||
* lets you zoom and move the image.
|
||||
*
|
||||
* @note Since this container uses the ScalableImage it has the same restrictions as a
|
||||
* ScaleableImage, i.e. 1bpp is not supported.
|
||||
*/
|
||||
class ZoomAnimationImage : public Container
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* A ZoomMode describes in which direction the image will grow/shrink when do a zoom
|
||||
* animation. A FIXED direction means that the image will not grow/shrink in that
|
||||
* direction.
|
||||
*/
|
||||
enum ZoomMode
|
||||
{
|
||||
FIXED_CENTER, ///< The small image will grow from the center of the large image
|
||||
FIXED_LEFT, ///< The small image will grow from the middle of the left side of the large image
|
||||
FIXED_RIGHT, ///< The small image will grow from the middle of the right side of the large image
|
||||
FIXED_TOP, ///< The small image will grow from the middle of the top of the large image
|
||||
FIXED_BOTTOM, ///< The small image will grow from the middle of the bottom of the large image
|
||||
FIXED_LEFT_AND_TOP, ///< The small image will grow from the top left corner of the large image
|
||||
FIXED_RIGHT_AND_TOP, ///< The small image will grow from the top right corner of the large image
|
||||
FIXED_LEFT_AND_BOTTOM, ///< The small image will grow from the bottom left corner of the large image
|
||||
FIXED_RIGHT_AND_BOTTOM ///< The small image will grow from the bottom right corner of the large image
|
||||
};
|
||||
|
||||
ZoomAnimationImage();
|
||||
|
||||
/**
|
||||
* Setup and starts the zoom animation. At end of the animation the image will have been
|
||||
* resized to the endWidth and endHeight. The development of the width and height during
|
||||
* the animation is described by the supplied EasingEquations. The container is
|
||||
* registered as a TimerWidget and automatically unregistered when the animation has
|
||||
* finished.
|
||||
*
|
||||
* @param endWidth The width of the image at animation end.
|
||||
* @param endHeight The height of the image at animation end.
|
||||
* @param duration The duration of the animation measured in ticks.
|
||||
* @param zoomMode (Optional) The zoom mode that will be used during the
|
||||
* animation. Default is #FIXED_LEFT_AND_TOP.
|
||||
* @param widthProgressionEquation (Optional) The equation that describes the
|
||||
* development of the width during the animation.
|
||||
* Default is EasingEquations::linearEaseNone.
|
||||
* @param heightProgressionEquation (Optional) The equation that describes the
|
||||
* development of the height during the animation.
|
||||
* Default is EasingEquations::linearEaseNone.
|
||||
*
|
||||
* @note The animation follows the specified ZoomMode so the X and Y coordinates of the image
|
||||
* might change during animation.
|
||||
*/
|
||||
void startZoomAnimation(int16_t endWidth, int16_t endHeight, uint16_t duration, ZoomMode zoomMode = FIXED_LEFT_AND_TOP, EasingEquation widthProgressionEquation = &EasingEquations::linearEaseNone, EasingEquation heightProgressionEquation = &EasingEquations::linearEaseNone);
|
||||
|
||||
/**
|
||||
* Setup and starts the zoom and move animation. At end of the animation the image will
|
||||
* have been resized to the endWidth and endHeight and have moved from its original
|
||||
* position to the endX and endY. Please note that the ZoomMode might influence the
|
||||
* actual end position since the zoom transformation might change the X and Y of the
|
||||
* image. The ZoomMode #FIXED_LEFT_AND_TOP ensures that the endX and endY will be the
|
||||
* actual end position.
|
||||
*
|
||||
* The development of the width, height, X and Y during the animation is described by
|
||||
* the supplied EasingEquations. The container is registered as a TimerWidget and
|
||||
* automatically unregistered when the animation has finished.
|
||||
*
|
||||
* @param endX The X position of the image at animation end.
|
||||
* Relative to the container or view that holds the
|
||||
* ZoomAnimationImage.
|
||||
* @param endY The Y position of the image at animation end.
|
||||
* Relative to the container or view that holds the
|
||||
* ZoomAnimationImage.
|
||||
* @param endWidth The width of the image at animation end.
|
||||
* @param endHeight The height of the image at animation end.
|
||||
* @param duration The duration of the animation measured in ticks.
|
||||
* @param zoomMode (Optional) The zoom mode that will be used during the
|
||||
* animation. Default is #FIXED_LEFT_AND_TOP.
|
||||
* @param xProgressionEquation (Optional) The equation that describes the
|
||||
* development of the X position during the animation.
|
||||
* Default is EasingEquations::linearEaseNone.
|
||||
* @param yProgressionEquation (Optional) The equation that describes the
|
||||
* development of the Y position during the animation.
|
||||
* Default is EasingEquations::linearEaseNone.
|
||||
* @param widthProgressionEquation (Optional) The equation that describes the
|
||||
* development of the width during the animation.
|
||||
* Default is EasingEquations::linearEaseNone.
|
||||
* @param heightProgressionEquation (Optional) The equation that describes the
|
||||
* development of the height during the animation.
|
||||
* Default is EasingEquations::linearEaseNone.
|
||||
*/
|
||||
void startZoomAndMoveAnimation(int16_t endX, int16_t endY, int16_t endWidth, int16_t endHeight, uint16_t duration, ZoomMode zoomMode = FIXED_LEFT_AND_TOP, EasingEquation xProgressionEquation = &EasingEquations::linearEaseNone, EasingEquation yProgressionEquation = &EasingEquations::linearEaseNone, EasingEquation widthProgressionEquation = &EasingEquations::linearEaseNone, EasingEquation heightProgressionEquation = &EasingEquations::linearEaseNone);
|
||||
|
||||
/** Cancel zoom animation. The image is left in the position and size it is currently at. */
|
||||
void cancelZoomAnimation();
|
||||
|
||||
virtual void handleTickEvent();
|
||||
|
||||
/**
|
||||
* Initializes the bitmap of the image to be used. The bitmaps should represent the same
|
||||
* image in the two needed static resolutions.
|
||||
*
|
||||
* @param smallBitmap The image in the smallest resolution.
|
||||
* @param largeBitmap The image in the largest resolution.
|
||||
*
|
||||
* @see getSmallBitmap, getLargeBitmap
|
||||
*
|
||||
* @note The size of the bitmaps do not in any way limit the size of the ZoomAnimationImage
|
||||
* and it is possible to scale the image beyond the sizes of these bitmaps.
|
||||
*/
|
||||
void setBitmaps(const Bitmap& smallBitmap, const Bitmap& largeBitmap);
|
||||
|
||||
/**
|
||||
* Gets the small bitmap.
|
||||
*
|
||||
* @return the small bitmap.
|
||||
*
|
||||
* @see setBitmaps
|
||||
*/
|
||||
Bitmap getSmallBitmap() const
|
||||
{
|
||||
return smallBmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the large bitmap.
|
||||
*
|
||||
* @return the large bitmap.
|
||||
*
|
||||
* @see setBitmaps
|
||||
*/
|
||||
Bitmap getLargeBitmap() const
|
||||
{
|
||||
return largeBmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @copydoc Drawable::setWidth
|
||||
*
|
||||
* @note ZoomAnimationImage diverts from the normal behavior by automatically invalidating
|
||||
* which causes a redraw.
|
||||
*/
|
||||
virtual void setWidth(int16_t width);
|
||||
|
||||
/**
|
||||
* @copydoc Drawable::setHeight
|
||||
*
|
||||
* @note ZoomAnimationImage diverts from the normal behavior by automatically invalidating
|
||||
* which causes a redraw.
|
||||
*/
|
||||
virtual void setHeight(int16_t height);
|
||||
|
||||
/**
|
||||
* Sets the algorithm to be used. In short, there is currently a value for fast (nearest
|
||||
* neighbor) and a value for slow (bilinear interpolation). Default is
|
||||
* ScalableImage::NEAREST_NEIGHBOR since moving images do not need to be of the best
|
||||
* quality, until they stop moving. If the image moves only a little bit, or
|
||||
* moves/resizes slowly, consider using ScaleableImage::BILINEAR_INTERPOLATION.
|
||||
*
|
||||
* @param mode The algorithm to use when rendering.
|
||||
*
|
||||
* @see ScalableImage::ScalingAlgorithm, getScalingMode
|
||||
*/
|
||||
virtual void setScalingMode(ScalableImage::ScalingAlgorithm mode);
|
||||
|
||||
/**
|
||||
* Gets the scaling algorithm of the ScalableImage.
|
||||
*
|
||||
* @return the scaling algorithm used.
|
||||
*
|
||||
* @see setScalingMode
|
||||
*/
|
||||
virtual ScalableImage::ScalingAlgorithm getScalingMode();
|
||||
|
||||
/**
|
||||
* @copydoc Image::setAlpha
|
||||
*/
|
||||
virtual void setAlpha(uint8_t newAlpha);
|
||||
|
||||
/**
|
||||
* @copydoc Image::getAlpha
|
||||
*/
|
||||
virtual uint8_t getAlpha() const;
|
||||
|
||||
/**
|
||||
* Sets a delay on animations done by the ZoomAnimationImage. Defaults to 0 which means
|
||||
* that the animation starts immediately.
|
||||
*
|
||||
* @param delay The delay in ticks.
|
||||
*
|
||||
* @see getAnimationDelay
|
||||
*/
|
||||
virtual void setAnimationDelay(uint16_t delay);
|
||||
|
||||
/**
|
||||
* Gets the current animation delay.
|
||||
*
|
||||
* @return The current animation delay. Expressed in ticks.
|
||||
*
|
||||
* @see setAnimationDelay
|
||||
*/
|
||||
virtual uint16_t getAnimationDelay() const;
|
||||
|
||||
/**
|
||||
* Associates an action to be performed when the animation ends.
|
||||
*
|
||||
* @param callback The callback to be executed. The callback will be given a reference
|
||||
* to the ZoomAnimationImage.
|
||||
*
|
||||
* @see GenericCallback
|
||||
*/
|
||||
void setAnimationEndedCallback(GenericCallback<const ZoomAnimationImage&>& callback)
|
||||
{
|
||||
animationEndedAction = &callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is there currently an animation running.
|
||||
*
|
||||
* @return true if there is an animation running.
|
||||
*/
|
||||
bool isZoomAnimationRunning() const;
|
||||
|
||||
virtual void invalidateContent() const
|
||||
{
|
||||
if (getAlpha() > 0)
|
||||
{
|
||||
Container::invalidateContent();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
/** Animation states. */
|
||||
enum States
|
||||
{
|
||||
ANIMATE_ZOOM, ///< Zoom animation state
|
||||
ANIMATE_ZOOM_AND_MOVE, ///< Zoom and move animation state
|
||||
NO_ANIMATION ///< No animation state
|
||||
};
|
||||
|
||||
States currentState; ///< The current animation state
|
||||
uint16_t animationCounter; ///< The progress counter for the animation
|
||||
uint16_t zoomAnimationDelay; ///< A delay that is applied before animation start. Expressed in ticks.
|
||||
Bitmap smallBmp; ///< The bitmap representing the small image
|
||||
Bitmap largeBmp; ///< The bitmap representing the large image
|
||||
Image image; ///< The image for displaying the bitmap when the width/height is equal one of the bitmaps
|
||||
ScalableImage scalableImage; ///< The scalable image for displaying the bitmap when the width/height is not equal one of the bitmaps
|
||||
ZoomMode currentZoomMode; ///< The ZoomMode to use by the animation
|
||||
int16_t zoomAnimationStartWidth; ///< Width of the zoom animation start
|
||||
int16_t zoomAnimationStartHeight; ///< Height of the zoom animation start
|
||||
int16_t zoomAnimationEndWidth; ///< Width of the zoom animation end
|
||||
int16_t zoomAnimationEndHeight; ///< Height of the zoom animation end
|
||||
int16_t zoomAnimationStartX; ///< The zoom animation start x coordinate
|
||||
int16_t zoomAnimationStartY; ///< The zoom animation start y coordinate
|
||||
int16_t zoomAnimationDeltaX; ///< The zoom animation delta x
|
||||
int16_t zoomAnimationDeltaY; ///< The zoom animation delta y
|
||||
int16_t moveAnimationEndX; ///< The move animation end x coordinate
|
||||
int16_t moveAnimationEndY; ///< The move animation end y coordinate
|
||||
uint16_t animationDuration; ///< Duration of the animation
|
||||
EasingEquation zoomAnimationWidthEquation; ///< The zoom animation width equation
|
||||
EasingEquation zoomAnimationHeightEquation; ///< The zoom animation height equation
|
||||
EasingEquation moveAnimationXEquation; ///< The move animation x coordinate equation
|
||||
EasingEquation moveAnimationYEquation; ///< The move animation y coordinate equation
|
||||
|
||||
GenericCallback<const ZoomAnimationImage&>* animationEndedAction; ///< The animation ended action
|
||||
|
||||
/**
|
||||
* Chooses the optimal rendering of the image given the current width and height. If the
|
||||
* dimensions match either the small or large bitmap, that will be used, otherwise the
|
||||
* large image will be scaled using the defined scaling mode.
|
||||
*
|
||||
* @see setScalingMode, setBitmaps
|
||||
*/
|
||||
virtual void updateRenderingMethod();
|
||||
|
||||
/**
|
||||
* Sets the current animation state and reset the animation counter.
|
||||
*
|
||||
* @param state The new state.
|
||||
*/
|
||||
virtual void setCurrentState(States state);
|
||||
|
||||
/**
|
||||
* Starts timer and set parameters. Contains code shared between startZoomAnimation()
|
||||
* and startZoomAndMoveAnimation(). If both delay and duration is zero, the end position
|
||||
* and size is applied and the animation is ended immediately.
|
||||
*
|
||||
* @param endWidth The end width.
|
||||
* @param endHeight The end height.
|
||||
* @param duration The duration.
|
||||
* @param zoomMode The zoom mode.
|
||||
* @param widthProgressionEquation The width progression equation.
|
||||
* @param heightProgressionEquation The height progression equation.
|
||||
*/
|
||||
void startTimerAndSetParameters(int16_t endWidth, int16_t endHeight, uint16_t duration, ZoomMode zoomMode, EasingEquation widthProgressionEquation, EasingEquation heightProgressionEquation);
|
||||
|
||||
/**
|
||||
* Calculates the change in X and Y caused by the zoom animation given the current
|
||||
* #ZoomMode.
|
||||
*/
|
||||
virtual void updateZoomAnimationDeltaXY();
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_ZOOMANIMATIONIMAGE_HPP
|
||||
@ -0,0 +1,126 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/buttons/AbstractButtonContainer.hpp
|
||||
*
|
||||
* Declares the touchgfx::AbstractButtonContainer class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_ABSTRACTBUTTONCONTAINER_HPP
|
||||
#define TOUCHGFX_ABSTRACTBUTTONCONTAINER_HPP
|
||||
|
||||
#include <touchgfx/Callback.hpp>
|
||||
#include <touchgfx/containers/Container.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* An abstract button container. The AbstractButtonContainer defines pressed/not pressed state,
|
||||
* the alpha value, and the action Callback of a button. AbstractButtonContainer is used
|
||||
* as superclass for classes defining a specific button behavior.
|
||||
*
|
||||
* @see ClickButtonTrigger, RepeatButtonTrigger, ToggleButtonTrigger, TouchButtonTrigger
|
||||
*/
|
||||
class AbstractButtonContainer : public Container
|
||||
{
|
||||
public:
|
||||
AbstractButtonContainer()
|
||||
: pressed(false), alpha(255), action(0)
|
||||
{
|
||||
setTouchable(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the pressed state to the given state. A subclass of AbstractButtonContainer
|
||||
* should implement handlePressedUpdate() to handle the new pressed state.
|
||||
*
|
||||
* @param isPressed True if is pressed, false if not.
|
||||
*
|
||||
* @see getPressed, handlePressedUpdated
|
||||
*/
|
||||
void setPressed(bool isPressed)
|
||||
{
|
||||
pressed = isPressed;
|
||||
handlePressedUpdated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the pressed state.
|
||||
*
|
||||
* @return True if it succeeds, false if it fails.
|
||||
*
|
||||
* @see setPressed
|
||||
*/
|
||||
bool getPressed()
|
||||
{
|
||||
return pressed;
|
||||
}
|
||||
|
||||
/** @copydoc Image::setAlpha() */
|
||||
void setAlpha(uint8_t newAlpha)
|
||||
{
|
||||
alpha = newAlpha;
|
||||
handleAlphaUpdated();
|
||||
}
|
||||
|
||||
/** @copydoc Image::getAlpha() */
|
||||
uint8_t getAlpha() const
|
||||
{
|
||||
return alpha;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an action callback to be executed by the subclass of AbstractContainerButton.
|
||||
*
|
||||
* @param callback The callback.
|
||||
*
|
||||
* @see executeAction
|
||||
*/
|
||||
void setAction(GenericCallback<const AbstractButtonContainer&>& callback)
|
||||
{
|
||||
action = &callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the previously set action.
|
||||
*
|
||||
* @see setAction
|
||||
*/
|
||||
virtual void executeAction()
|
||||
{
|
||||
if (action && action->isValid())
|
||||
{
|
||||
action->execute(*this);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
bool pressed; ///< True if pressed
|
||||
uint8_t alpha; ///< The current alpha value. 255 denotes solid, 0 denotes completely invisible.
|
||||
|
||||
GenericCallback<const AbstractButtonContainer&>* action; ///< The action to be executed
|
||||
|
||||
/** Handles what should happen when the pressed state is updated. */
|
||||
virtual void handlePressedUpdated()
|
||||
{
|
||||
}
|
||||
|
||||
/** Handles what should happen when the alpha is updated. */
|
||||
virtual void handleAlphaUpdated()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_ABSTRACTBUTTONCONTAINER_HPP
|
||||
@ -0,0 +1,112 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/buttons/AnimatedImageButtonStyle.hpp
|
||||
*
|
||||
* Declares the touchgfx::AnimatedImageButtonStyle class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_ANIMATEDIMAGEBUTTONSTYLE_HPP
|
||||
#define TOUCHGFX_ANIMATEDIMAGEBUTTONSTYLE_HPP
|
||||
|
||||
#include <touchgfx/Bitmap.hpp>
|
||||
#include <touchgfx/containers/buttons/AbstractButtonContainer.hpp>
|
||||
#include <touchgfx/widgets/AnimatedImage.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* An animated image button style. An animated image button style. This class is supposed to be
|
||||
* used with one of the ButtonTrigger classes to create a functional button. This class
|
||||
* will show the first or last image of an animated image depending on the state of the
|
||||
* button (pressed or released). When the state changes the button will show the
|
||||
* sequence of images in forward or reversed order.
|
||||
*
|
||||
* The AnimatedImageButtonStyle will set the size of the enclosing container (normally
|
||||
* AbstractButtonContainer) to the size of the first Bitmap. This can be overridden by
|
||||
* calling setWidth/setHeight after setting the bitmaps.
|
||||
*
|
||||
* The position of the bitmap can be adjusted with setBitmapXY (default is upper left
|
||||
* corner).
|
||||
*
|
||||
* @tparam T Generic type parameter. Typically a AbstractButtonContainer subclass.
|
||||
*
|
||||
* @see AbstractButtonContainer
|
||||
*/
|
||||
template <class T>
|
||||
class AnimatedImageButtonStyle : public T
|
||||
{
|
||||
public:
|
||||
AnimatedImageButtonStyle()
|
||||
: T(), buttonAnimatedImage()
|
||||
{
|
||||
buttonAnimatedImage.setXY(0, 0);
|
||||
T::add(buttonAnimatedImage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bitmaps.
|
||||
*
|
||||
* @param bitmapStart The bitmap start.
|
||||
* @param bitmapEnd The bitmap end.
|
||||
*/
|
||||
void setBitmaps(const Bitmap& bitmapStart, const Bitmap& bitmapEnd)
|
||||
{
|
||||
buttonAnimatedImage.setBitmaps(bitmapStart.getId(), bitmapEnd.getId());
|
||||
|
||||
AbstractButtonContainer::setWidthHeight(bitmapStart);
|
||||
|
||||
handlePressedUpdated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets bitmap x and y.
|
||||
*
|
||||
* @param x An uint16_t to process.
|
||||
* @param y An uint16_t to process.
|
||||
*/
|
||||
void setBitmapXY(uint16_t x, uint16_t y)
|
||||
{
|
||||
buttonAnimatedImage.setXY(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets update ticks interval.
|
||||
*
|
||||
* @param updateInterval The update interval.
|
||||
*/
|
||||
void setUpdateTicksInterval(uint8_t updateInterval)
|
||||
{
|
||||
buttonAnimatedImage.setUpdateTicksInterval(updateInterval);
|
||||
}
|
||||
|
||||
protected:
|
||||
AnimatedImage buttonAnimatedImage; ///< The button animated image
|
||||
|
||||
/** @copydoc AbstractButtonContainer::handlePressedUpdated() */
|
||||
virtual void handlePressedUpdated()
|
||||
{
|
||||
buttonAnimatedImage.startAnimation(AbstractButtonContainer::pressed, true, false);
|
||||
T::handlePressedUpdated();
|
||||
}
|
||||
|
||||
/** @copydoc AbstractButtonContainer::handleAlphaUpdated() */
|
||||
virtual void handleAlphaUpdated()
|
||||
{
|
||||
buttonAnimatedImage.setAlpha(T::getAlpha());
|
||||
T::handleAlphaUpdated();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_ANIMATEDIMAGEBUTTONSTYLE_HPP
|
||||
@ -0,0 +1,140 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/buttons/BoxWithBorderButtonStyle.hpp
|
||||
*
|
||||
* Declares the touchgfx::BoxWithBorderButtonStyle class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_BOXWITHBORDERBUTTONSTYLE_HPP
|
||||
#define TOUCHGFX_BOXWITHBORDERBUTTONSTYLE_HPP
|
||||
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/BoxWithBorder.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A box with border button style. This class is supposed to be used with one of the
|
||||
* ButtonTrigger classes to create a functional button. This class will show a box with
|
||||
* a border in different colors depending on the state of the button (pressed or
|
||||
* released).
|
||||
*
|
||||
* An image button style. This class is supposed to be used with one of the
|
||||
* ButtonTrigger classes to create a functional button. This class will show one of two
|
||||
* images depending on the state of the button (pressed or released).
|
||||
*
|
||||
* @tparam T Generic type parameter. Typically a AbstractButtonContainer subclass.
|
||||
*
|
||||
* @see AbstractButtonContainer, BoxWithBorder
|
||||
*/
|
||||
template <class T>
|
||||
class BoxWithBorderButtonStyle : public T
|
||||
{
|
||||
public:
|
||||
BoxWithBorderButtonStyle()
|
||||
: T(), up(), down()
|
||||
{
|
||||
borderBox.setXY(0, 0);
|
||||
T::add(borderBox);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size and position of this BoxWithBorderButtonStyle, relative to its parent.
|
||||
*
|
||||
* @param x The x coordinate of this BoxWithBorderButtonStyle.
|
||||
* @param y The y coordinate of this BoxWithBorderButtonStyle.
|
||||
* @param width The width of this BoxWithBorderButtonStyle.
|
||||
* @param height The height of this BoxWithBorderButtonStyle.
|
||||
*
|
||||
* @note Changing this does not automatically yield a redraw.
|
||||
*/
|
||||
void setBoxWithBorderPosition(int16_t x, int16_t y, int16_t width, int16_t height)
|
||||
{
|
||||
borderBox.setPosition(x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the width.
|
||||
*
|
||||
* @param width The width.
|
||||
*/
|
||||
void setBoxWithBorderWidth(int16_t width)
|
||||
{
|
||||
borderBox.setWidth(width);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the height.
|
||||
*
|
||||
* @param height The height.
|
||||
*/
|
||||
void setBoxWithBorderHeight(int16_t height)
|
||||
{
|
||||
borderBox.setHeight(height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the colors.
|
||||
*
|
||||
* @param colorReleased The color released.
|
||||
* @param colorPressed The color pressed.
|
||||
* @param borderColorReleased The border color released.
|
||||
* @param borderColorPressed The border color pressed.
|
||||
*/
|
||||
void setBoxWithBorderColors(const colortype colorReleased, const colortype colorPressed, const colortype borderColorReleased, const colortype borderColorPressed)
|
||||
{
|
||||
up = colorReleased;
|
||||
down = colorPressed;
|
||||
|
||||
borderUp = borderColorReleased;
|
||||
borderDown = borderColorPressed;
|
||||
|
||||
handlePressedUpdated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets border size.
|
||||
*
|
||||
* @param size The size.
|
||||
*/
|
||||
void setBorderSize(uint8_t size)
|
||||
{
|
||||
borderBox.setBorderSize(size);
|
||||
}
|
||||
|
||||
protected:
|
||||
BoxWithBorder borderBox; ///< The border box
|
||||
colortype up; ///< The up
|
||||
colortype down; ///< The down
|
||||
colortype borderUp; ///< The border up
|
||||
colortype borderDown; ///< The border down
|
||||
|
||||
/** @copydoc AbstractButtonContainer::handlePressedUpdated() */
|
||||
virtual void handlePressedUpdated()
|
||||
{
|
||||
borderBox.setColor(T::getPressed() ? down : up);
|
||||
borderBox.setBorderColor(T::getPressed() ? borderDown : borderUp);
|
||||
T::handlePressedUpdated();
|
||||
}
|
||||
|
||||
/** @copydoc AbstractButtonContainer::handleAlphaUpdated() */
|
||||
virtual void handleAlphaUpdated()
|
||||
{
|
||||
borderBox.setAlpha(T::getAlpha());
|
||||
T::handleAlphaUpdated();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_BOXWITHBORDERBUTTONSTYLE_HPP
|
||||
@ -0,0 +1,147 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/buttons/Buttons.hpp
|
||||
*
|
||||
* Declares the various FlexButton styles by combining often used template classes.
|
||||
*/
|
||||
#ifndef TOUCHGFX_BUTTONS_HPP
|
||||
#define TOUCHGFX_BUTTONS_HPP
|
||||
|
||||
#include <touchgfx/containers/buttons/AnimatedImageButtonStyle.hpp>
|
||||
#include <touchgfx/containers/buttons/BoxWithBorderButtonStyle.hpp>
|
||||
#include <touchgfx/containers/buttons/ClickButtonTrigger.hpp>
|
||||
#include <touchgfx/containers/buttons/IconButtonStyle.hpp>
|
||||
#include <touchgfx/containers/buttons/ImageButtonStyle.hpp>
|
||||
#include <touchgfx/containers/buttons/RepeatButtonTrigger.hpp>
|
||||
#include <touchgfx/containers/buttons/TextButtonStyle.hpp>
|
||||
#include <touchgfx/containers/buttons/TiledImageButtonStyle.hpp>
|
||||
#include <touchgfx/containers/buttons/ToggleButtonTrigger.hpp>
|
||||
#include <touchgfx/containers/buttons/TouchButtonTrigger.hpp>
|
||||
#include <touchgfx/containers/buttons/TwoWildcardTextButtonStyle.hpp>
|
||||
#include <touchgfx/containers/buttons/WildcardTextButtonStyle.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/** Defines an alias representing the box click button. */
|
||||
typedef BoxWithBorderButtonStyle<ClickButtonTrigger> BoxClickButton;
|
||||
|
||||
/** Defines an alias representing the box repeat button. */
|
||||
typedef BoxWithBorderButtonStyle<RepeatButtonTrigger> BoxRepeatButton;
|
||||
|
||||
/** Defines an alias representing the box toggle button. */
|
||||
typedef BoxWithBorderButtonStyle<ToggleButtonTrigger> BoxToggleButton;
|
||||
|
||||
/** Defines an alias representing the box touch button. */
|
||||
typedef BoxWithBorderButtonStyle<TouchButtonTrigger> BoxTouchButton;
|
||||
|
||||
/** Defines an alias representing the image click button. */
|
||||
typedef ImageButtonStyle<ClickButtonTrigger> ImageClickButton;
|
||||
|
||||
/** Defines an alias representing the image repeat button. */
|
||||
typedef ImageButtonStyle<RepeatButtonTrigger> ImageRepeatButton;
|
||||
|
||||
/** Defines an alias representing the image touch button. */
|
||||
typedef ImageButtonStyle<TouchButtonTrigger> ImageTouchButton;
|
||||
|
||||
/** Defines an alias representing the image toggle button. */
|
||||
typedef ImageButtonStyle<ToggleButtonTrigger> ImageToggleButton;
|
||||
|
||||
/** Defines an alias representing the icon click button. */
|
||||
typedef IconButtonStyle<ClickButtonTrigger> IconClickButton;
|
||||
|
||||
/** Defines an alias representing the icon repeat button. */
|
||||
typedef IconButtonStyle<RepeatButtonTrigger> IconRepeatButton;
|
||||
|
||||
/** Defines an alias representing the icon touch button. */
|
||||
typedef IconButtonStyle<TouchButtonTrigger> IconTouchButton;
|
||||
|
||||
/** Defines an alias representing the icon toggle button. */
|
||||
typedef IconButtonStyle<ToggleButtonTrigger> IconToggleButton;
|
||||
|
||||
/** Defines an alias representing the icon image click button. */
|
||||
typedef ImageButtonStyle<IconButtonStyle<ClickButtonTrigger> > IconImageClickButton;
|
||||
|
||||
/** Defines an alias representing the icon image repeat button. */
|
||||
typedef ImageButtonStyle<IconButtonStyle<RepeatButtonTrigger> > IconImageRepeatButton;
|
||||
|
||||
/** Defines an alias representing the icon image touch button. */
|
||||
typedef ImageButtonStyle<IconButtonStyle<TouchButtonTrigger> > IconImageTouchButton;
|
||||
|
||||
/** Defines an alias representing the icon image toggle button. */
|
||||
typedef ImageButtonStyle<IconButtonStyle<ToggleButtonTrigger> > IconImageToggleButton;
|
||||
|
||||
/** Defines an alias representing the text click button. */
|
||||
typedef TextButtonStyle<ClickButtonTrigger> TextClickButton;
|
||||
|
||||
/** Defines an alias representing the text repeat button. */
|
||||
typedef TextButtonStyle<RepeatButtonTrigger> TextRepeatButton;
|
||||
|
||||
/** Defines an alias representing the text touch button. */
|
||||
typedef TextButtonStyle<TouchButtonTrigger> TextTouchButton;
|
||||
|
||||
/** Defines an alias representing the text toggle button. */
|
||||
typedef TextButtonStyle<ToggleButtonTrigger> TextToggleButton;
|
||||
|
||||
/** Defines an alias representing the tiled image click button. */
|
||||
typedef TiledImageButtonStyle<ClickButtonTrigger> TiledImageClickButton;
|
||||
|
||||
/** Defines an alias representing the tiled image repeat button. */
|
||||
typedef TiledImageButtonStyle<RepeatButtonTrigger> TiledImageRepeatButton;
|
||||
|
||||
/** Defines an alias representing the tiled image touch button. */
|
||||
typedef TiledImageButtonStyle<TouchButtonTrigger> TiledImageTouchButton;
|
||||
|
||||
/** Defines an alias representing the tiled image toggle button. */
|
||||
typedef TiledImageButtonStyle<ToggleButtonTrigger> TiledImageToggleButton;
|
||||
|
||||
/** Defines an alias representing the wildcard text click button. */
|
||||
typedef WildcardTextButtonStyle<ClickButtonTrigger> WildcardTextClickButton;
|
||||
|
||||
/** Defines an alias representing the wildcard text repeat button. */
|
||||
typedef WildcardTextButtonStyle<RepeatButtonTrigger> WildcardTextRepeatButton;
|
||||
|
||||
/** Defines an alias representing the wildcard text touch button. */
|
||||
typedef WildcardTextButtonStyle<TouchButtonTrigger> WildcardTextTouchButton;
|
||||
|
||||
/** Defines an alias representing the wildcard text toggle button. */
|
||||
typedef WildcardTextButtonStyle<ToggleButtonTrigger> WildcardTextToggleButton;
|
||||
|
||||
/** Defines an alias representing the wildcard text click button. */
|
||||
typedef TwoWildcardTextButtonStyle<ClickButtonTrigger> TwoWildcardTextClickButton;
|
||||
|
||||
/** Defines an alias representing the wildcard text repeat button. */
|
||||
typedef TwoWildcardTextButtonStyle<RepeatButtonTrigger> TwoWildcardTextRepeatButton;
|
||||
|
||||
/** Defines an alias representing the wildcard text touch button. */
|
||||
typedef TwoWildcardTextButtonStyle<TouchButtonTrigger> TwoWildcardTextTouchButton;
|
||||
|
||||
/** Defines an alias representing the wildcard text toggle button. */
|
||||
typedef TwoWildcardTextButtonStyle<ToggleButtonTrigger> TwoWildcardTextToggleButton;
|
||||
|
||||
/** Defines an alias representing the animated image click button. */
|
||||
typedef AnimatedImageButtonStyle<ClickButtonTrigger> AnimatedImageClickButton;
|
||||
|
||||
/** Defines an alias representing the animated image repeat button. */
|
||||
typedef AnimatedImageButtonStyle<RepeatButtonTrigger> AnimatedImageRepeatButton;
|
||||
|
||||
/** Defines an alias representing the animated image touch button. */
|
||||
typedef AnimatedImageButtonStyle<TouchButtonTrigger> AnimatedImageTouchButton;
|
||||
|
||||
/** Defines an alias representing the animated image toggle button. */
|
||||
typedef AnimatedImageButtonStyle<ToggleButtonTrigger> AnimatedImageToggleButton;
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_BUTTONS_HPP
|
||||
@ -0,0 +1,65 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/buttons/ClickButtonTrigger.hpp
|
||||
*
|
||||
* Declares the touchgfx::ClickButtonTrigger class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_CLICKBUTTONTRIGGER_HPP
|
||||
#define TOUCHGFX_CLICKBUTTONTRIGGER_HPP
|
||||
|
||||
#include <touchgfx/containers/buttons/AbstractButtonContainer.hpp>
|
||||
#include <touchgfx/events/ClickEvent.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A click button trigger. This trigger will create a button that reacts on clicks. This means
|
||||
* it will call the set action when it gets a touch released event. The
|
||||
* ClickButtonTrigger can be combined with one or more of the ButtonStyle classes to
|
||||
* create a fully functional button.
|
||||
*
|
||||
* @see TouchButtonTrigger
|
||||
*/
|
||||
class ClickButtonTrigger : public AbstractButtonContainer
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Handles a ClickAvent. The action callback is called when the ClickButtonTrigger
|
||||
* receives a ClickEvent::RELEASED event in PRESSED state. Function setPressed() will
|
||||
* be called with the new button state.
|
||||
*
|
||||
* @param event The click event.
|
||||
*
|
||||
* @see setAction, setPressed, getPressed
|
||||
*/
|
||||
virtual void handleClickEvent(const ClickEvent& event)
|
||||
{
|
||||
bool wasPressed = getPressed();
|
||||
bool newPressedValue = (event.getType() == ClickEvent::PRESSED);
|
||||
if ((newPressedValue && !wasPressed) || (!newPressedValue && wasPressed))
|
||||
{
|
||||
setPressed(newPressedValue);
|
||||
invalidate();
|
||||
}
|
||||
if (wasPressed && (event.getType() == ClickEvent::RELEASED))
|
||||
{
|
||||
executeAction();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_CLICKBUTTONTRIGGER_HPP
|
||||
@ -0,0 +1,153 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/buttons/IconButtonStyle.hpp
|
||||
*
|
||||
* Declares the touchgfx::IconButtonStyle class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_ICONBUTTONSTYLE_HPP
|
||||
#define TOUCHGFX_ICONBUTTONSTYLE_HPP
|
||||
|
||||
#include <touchgfx/Bitmap.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/Image.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* An icon button style. This class is supposed to be used with one of the ButtonTrigger classes
|
||||
* to create a functional button. This class will show one of two icons depending on the
|
||||
* state of the button (pressed or released).
|
||||
*
|
||||
* To get a background behind the icon, use IconButtonStyle together with e.g.
|
||||
* ImageButtonStyle: IconButtonStyle<ImageButtonStyle<ClickButtonTrigger> >
|
||||
* myButton;
|
||||
*
|
||||
* The IconButtonStyle will center the icon on the enclosing container (normally
|
||||
* AbstractButtonContainer). Set the size of the button before setting the icons.
|
||||
*
|
||||
* The position of the icon can be adjusted with setIconXY.
|
||||
*
|
||||
* @see AbstractButtonContainer
|
||||
*/
|
||||
template <class T>
|
||||
class IconButtonStyle : public T
|
||||
{
|
||||
public:
|
||||
IconButtonStyle()
|
||||
: T()
|
||||
{
|
||||
T::add(iconImage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets icon bitmaps.
|
||||
*
|
||||
* @param newIconReleased The new icon released.
|
||||
* @param newIconPressed The new icon pressed.
|
||||
*/
|
||||
virtual void setIconBitmaps(const Bitmap& newIconReleased, const Bitmap& newIconPressed)
|
||||
{
|
||||
iconReleased = newIconReleased;
|
||||
iconPressed = newIconPressed;
|
||||
|
||||
iconImage.setXY((T::getWidth() / 2) - (newIconPressed.getWidth() / 2), (T::getHeight() / 2) - (newIconPressed.getHeight() / 2));
|
||||
|
||||
handlePressedUpdated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets icon x coordinate.
|
||||
*
|
||||
* @param x The x coordinate.
|
||||
*/
|
||||
void setIconX(int16_t x)
|
||||
{
|
||||
iconImage.setX(x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets icon y coordinate.
|
||||
*
|
||||
* @param y The y coordinate.
|
||||
*/
|
||||
void setIconY(int16_t y)
|
||||
{
|
||||
iconImage.setY(y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the position of the icon.
|
||||
*
|
||||
* @param x The x coordinate.
|
||||
* @param y The y coordinate.
|
||||
*/
|
||||
void setIconXY(int16_t x, int16_t y)
|
||||
{
|
||||
setIconX(x);
|
||||
setIconY(y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets currently displayed icon.
|
||||
*
|
||||
* @return The currently displayed icon.
|
||||
*/
|
||||
Bitmap getCurrentlyDisplayedIcon() const
|
||||
{
|
||||
return (T::getPressed() ? iconPressed : iconReleased);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets icon x coordinate.
|
||||
*
|
||||
* @return The icon x coordinate.
|
||||
*/
|
||||
int16_t getIconX() const
|
||||
{
|
||||
return iconImage.getX();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets icon y coordinate.
|
||||
*
|
||||
* @return The icon y coordinate.
|
||||
*/
|
||||
int16_t getIconY() const
|
||||
{
|
||||
return iconImage.getY();
|
||||
}
|
||||
|
||||
protected:
|
||||
Bitmap iconReleased; ///< Icon to display when button is not pressed.
|
||||
Bitmap iconPressed; ///< Icon to display when button is pressed.
|
||||
Image iconImage; ///< The icon image
|
||||
|
||||
/** @copydoc AbstractButtonContainer::handlePressedUpdated() */
|
||||
virtual void handlePressedUpdated()
|
||||
{
|
||||
iconImage.setBitmap(T::getPressed() ? iconPressed : iconReleased);
|
||||
T::handlePressedUpdated();
|
||||
}
|
||||
|
||||
/** @copydoc AbstractButtonContainer::handleAlphaUpdated() */
|
||||
virtual void handleAlphaUpdated()
|
||||
{
|
||||
iconImage.setAlpha(T::getAlpha());
|
||||
T::handleAlphaUpdated();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_ICONBUTTONSTYLE_HPP
|
||||
@ -0,0 +1,113 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/buttons/ImageButtonStyle.hpp
|
||||
*
|
||||
* Declares the touchgfx::ImageButtonStyle class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_IMAGEBUTTONSTYLE_HPP
|
||||
#define TOUCHGFX_IMAGEBUTTONSTYLE_HPP
|
||||
|
||||
#include <touchgfx/Bitmap.hpp>
|
||||
#include <touchgfx/containers/buttons/AbstractButtonContainer.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/Image.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* An image button style. This class is supposed to be used with one of the ButtonTrigger
|
||||
* classes to create a functional button. This class will show one of two images
|
||||
* depending on the state of the button (pressed or released).
|
||||
*
|
||||
* The ImageButtonStyle will set the size of the enclosing container (normally
|
||||
* AbstractButtonContainer) to the size of the pressed Bitmap. This can be overridden by
|
||||
* calling setWidth/setHeight after setting the bitmaps.
|
||||
*
|
||||
* The position of the bitmap can be adjusted with setBitmapXY (default is upper left
|
||||
* corner).
|
||||
*
|
||||
* @tparam T Generic type parameter. Typically a AbstractButtonContainer subclass.
|
||||
*
|
||||
* @see AbstractButtonContainer
|
||||
*/
|
||||
template <class T>
|
||||
class ImageButtonStyle : public T
|
||||
{
|
||||
public:
|
||||
ImageButtonStyle()
|
||||
: T(), up(), down()
|
||||
{
|
||||
buttonImage.setXY(0, 0);
|
||||
T::add(buttonImage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bitmaps.
|
||||
*
|
||||
* @param bmpReleased The bitmap released.
|
||||
* @param bmpPressed The bitmap pressed.
|
||||
*/
|
||||
virtual void setBitmaps(const Bitmap& bmpReleased, const Bitmap& bmpPressed)
|
||||
{
|
||||
up = bmpReleased;
|
||||
down = bmpPressed;
|
||||
ImageButtonStyle::setWidthHeight(down);
|
||||
|
||||
handlePressedUpdated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets bitmap x and y.
|
||||
*
|
||||
* @param x An uint16_t to process.
|
||||
* @param y An uint16_t to process.
|
||||
*/
|
||||
void setBitmapXY(uint16_t x, uint16_t y)
|
||||
{
|
||||
buttonImage.setXY(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets currently displayed bitmap.
|
||||
*
|
||||
* @return The currently displayed bitmap.
|
||||
*/
|
||||
Bitmap getCurrentlyDisplayedBitmap() const
|
||||
{
|
||||
return (AbstractButtonContainer::pressed ? down : up);
|
||||
}
|
||||
|
||||
protected:
|
||||
Image buttonImage; ///< The button image
|
||||
Bitmap up; ///< The image to display when button is released.
|
||||
Bitmap down; ///< The image to display when button is pressed.
|
||||
|
||||
/** @copydoc AbstractButtonContainer::handlePressedUpdated() */
|
||||
virtual void handlePressedUpdated()
|
||||
{
|
||||
buttonImage.setBitmap(T::getPressed() ? down : up);
|
||||
T::handlePressedUpdated();
|
||||
}
|
||||
|
||||
/** @copydoc AbstractButtonContainer::handleAlphaUpdated() */
|
||||
virtual void handleAlphaUpdated()
|
||||
{
|
||||
buttonImage.setAlpha(T::getAlpha());
|
||||
T::handleAlphaUpdated();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_IMAGEBUTTONSTYLE_HPP
|
||||
@ -0,0 +1,148 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/buttons/RepeatButtonTrigger.hpp
|
||||
*
|
||||
* Declares the touchgfx::RepeatButtonTrigger class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_REPEATBUTTONTRIGGER_HPP
|
||||
#define TOUCHGFX_REPEATBUTTONTRIGGER_HPP
|
||||
|
||||
#include <touchgfx/Application.hpp>
|
||||
#include <touchgfx/containers/buttons/AbstractButtonContainer.hpp>
|
||||
#include <touchgfx/events/ClickEvent.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A repeat button trigger. This trigger will create a button that reacts to a consistent touch.
|
||||
* This means it will call the set action repeatedly as long as it is touched. The
|
||||
* RepeatButtonTrigger can be combined with one or more of the ButtonStyle classes to
|
||||
* create a fully functional button.
|
||||
*/
|
||||
class RepeatButtonTrigger : public AbstractButtonContainer
|
||||
{
|
||||
public:
|
||||
RepeatButtonTrigger()
|
||||
: AbstractButtonContainer(), ticksDelay(30), ticksInterval(15), ticks(0), ticksBeforeContinuous(0)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the delay (in number of ticks) from the first button activation until the next
|
||||
* time it will be automatically activated.
|
||||
*
|
||||
* @param delay The delay, measured in ticks, between first activation and second activation.
|
||||
*
|
||||
* @see setInterval, getDelay
|
||||
*/
|
||||
void setDelay(int delay)
|
||||
{
|
||||
ticksDelay = delay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the delay in ticks from first button activation until next activation.
|
||||
*
|
||||
* @return The delay, measured in ticks, between first activation and second activation.
|
||||
*
|
||||
* @see setDelay
|
||||
*/
|
||||
int getDelay()
|
||||
{
|
||||
return ticksDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the interval in number of ticks between each each activation of the pressed
|
||||
* button after the second activation.
|
||||
*
|
||||
* @param interval The interval between repeated activations, measured in ticks.
|
||||
*
|
||||
* @see setDelay, getInterval
|
||||
*/
|
||||
void setInterval(int interval)
|
||||
{
|
||||
ticksInterval = interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* The interval between repeated activations, measured in ticks. This is the number of
|
||||
* ticks between the an activation beyond the first and the following activation.
|
||||
*
|
||||
* @return The interval between repeated activations, measured in ticks.
|
||||
*
|
||||
* @see setInterval
|
||||
*/
|
||||
int getInterval()
|
||||
{
|
||||
return ticksInterval;
|
||||
}
|
||||
|
||||
virtual void handleClickEvent(const ClickEvent& event)
|
||||
{
|
||||
bool wasPressed = getPressed();
|
||||
bool newPressedValue = (event.getType() == ClickEvent::PRESSED);
|
||||
if ((newPressedValue && !wasPressed) || (!newPressedValue && wasPressed))
|
||||
{
|
||||
setPressed(newPressedValue);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
if (event.getType() == ClickEvent::PRESSED)
|
||||
{
|
||||
executeAction();
|
||||
|
||||
ticks = 0;
|
||||
ticksBeforeContinuous = ticksDelay;
|
||||
Application::getInstance()->registerTimerWidget(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
Application::getInstance()->unregisterTimerWidget(this);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void handleTickEvent()
|
||||
{
|
||||
AbstractButtonContainer::handleTickEvent();
|
||||
|
||||
if (!pressed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (ticks == ticksBeforeContinuous)
|
||||
{
|
||||
executeAction();
|
||||
|
||||
ticks = 0;
|
||||
ticksBeforeContinuous = ticksInterval;
|
||||
}
|
||||
else
|
||||
{
|
||||
ticks++;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int16_t ticksDelay;
|
||||
int16_t ticksInterval;
|
||||
|
||||
int16_t ticks;
|
||||
int16_t ticksBeforeContinuous;
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_REPEATBUTTONTRIGGER_HPP
|
||||
@ -0,0 +1,154 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/buttons/TextButtonStyle.hpp
|
||||
*
|
||||
* Declares the touchgfx::TextButtonStyle class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_TEXTBUTTONSTYLE_HPP
|
||||
#define TOUCHGFX_TEXTBUTTONSTYLE_HPP
|
||||
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/TextArea.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A text button style. This class is supposed to be used with one of the ButtonTrigger classes
|
||||
* to create a functional button. This class will show a text in one of two colors
|
||||
* depending on the state of the button (pressed or released).
|
||||
*
|
||||
* The TextButtonStyle does not set the size of the enclosing container (normally
|
||||
* AbstractButtonContainer). The size must be set manually.
|
||||
*
|
||||
* To get a background behind the text, use TextButtonStyle together with e.g.
|
||||
* ImageButtonStyle: TextButtonStyle<ImageButtonStyle<ClickButtonTrigger> >
|
||||
* myButton;
|
||||
*
|
||||
* The position of the text can be adjusted with setTextXY (default is centered).
|
||||
*
|
||||
* @see AbstractButtonContainer
|
||||
*/
|
||||
template <class T>
|
||||
class TextButtonStyle : public T
|
||||
{
|
||||
public:
|
||||
TextButtonStyle()
|
||||
: T()
|
||||
{
|
||||
T::add(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a text.
|
||||
*
|
||||
* @param t A TypedText to process.
|
||||
*/
|
||||
void setText(TypedText t)
|
||||
{
|
||||
text.setTypedText(t);
|
||||
text.setWidthHeight(*this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets text x coordinate.
|
||||
*
|
||||
* @param x The x coordinate.
|
||||
*/
|
||||
void setTextX(int16_t x)
|
||||
{
|
||||
text.setX(x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets text y coordinate.
|
||||
*
|
||||
* @param y The y coordinate.
|
||||
*/
|
||||
void setTextY(int16_t y)
|
||||
{
|
||||
text.setY(y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets text x and y.
|
||||
*
|
||||
* @param x The x coordinate.
|
||||
* @param y The y coordinate.
|
||||
*/
|
||||
void setTextXY(int16_t x, int16_t y)
|
||||
{
|
||||
setTextX(x);
|
||||
setTextY(y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets text position.
|
||||
*
|
||||
* @param x The x coordinate.
|
||||
* @param y The y coordinate.
|
||||
* @param width The width of the text.
|
||||
* @param height The height of the text.
|
||||
*/
|
||||
void setTextPosition(int16_t x, int16_t y, int16_t width, int16_t height)
|
||||
{
|
||||
text.setPosition(x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets text rotation.
|
||||
*
|
||||
* @param rotation The rotation.
|
||||
*/
|
||||
void setTextRotation(TextRotation rotation)
|
||||
{
|
||||
text.setRotation(rotation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets text colors.
|
||||
*
|
||||
* @param newColorReleased The new color released.
|
||||
* @param newColorPressed The new color pressed.
|
||||
*/
|
||||
void setTextColors(colortype newColorReleased, colortype newColorPressed)
|
||||
{
|
||||
colorReleased = newColorReleased;
|
||||
colorPressed = newColorPressed;
|
||||
|
||||
handlePressedUpdated();
|
||||
}
|
||||
|
||||
protected:
|
||||
TextArea text; ///< The text
|
||||
colortype colorReleased; ///< The color released
|
||||
colortype colorPressed; ///< The color pressed
|
||||
|
||||
/** @copydoc AbstractButtonContainer::handlePressedUpdated() */
|
||||
virtual void handlePressedUpdated()
|
||||
{
|
||||
text.setColor(T::getPressed() ? colorPressed : colorReleased);
|
||||
T::handlePressedUpdated();
|
||||
}
|
||||
|
||||
/** @copydoc AbstractButtonContainer::handleAlphaUpdated() */
|
||||
virtual void handleAlphaUpdated()
|
||||
{
|
||||
text.setAlpha(T::getAlpha());
|
||||
T::handleAlphaUpdated();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_TEXTBUTTONSTYLE_HPP
|
||||
@ -0,0 +1,129 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/buttons/TiledImageButtonStyle.hpp
|
||||
*
|
||||
* Declares the touchgfx::TiledImageButtonStyle class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_TILEDIMAGEBUTTONSTYLE_HPP
|
||||
#define TOUCHGFX_TILEDIMAGEBUTTONSTYLE_HPP
|
||||
|
||||
#include <touchgfx/Bitmap.hpp>
|
||||
#include <touchgfx/containers/buttons/AbstractButtonContainer.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/TiledImage.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A tiled image button style.
|
||||
*
|
||||
* An tiled image button style. This class is supposed to be used with one of the
|
||||
* ButtonTrigger classes to create a functional button. This class will show one of two
|
||||
* tiled images depending on the state of the button (pressed or released).
|
||||
*
|
||||
* The TiledImageButtonStyle does not set the size of the enclosing container (normally
|
||||
* AbstractButtonContainer) to the size of the pressed Bitmap. This can be overridden by
|
||||
* calling setWidth/setHeight after setting the bitmaps.
|
||||
*
|
||||
* @tparam T Generic type parameter. Typically a AbstractButtonContainer subclass.
|
||||
*
|
||||
* @see AbstractButtonContainer
|
||||
*/
|
||||
template <class T>
|
||||
class TiledImageButtonStyle : public T
|
||||
{
|
||||
public:
|
||||
TiledImageButtonStyle()
|
||||
: T()
|
||||
{
|
||||
tiledImage.setXY(0, 0);
|
||||
T::add(tiledImage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets width.
|
||||
*
|
||||
* @param width The width.
|
||||
*/
|
||||
virtual void setWidth(int16_t width)
|
||||
{
|
||||
tiledImage.setWidth(width);
|
||||
T::setWidth(width);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets height.
|
||||
*
|
||||
* @param height The height.
|
||||
*/
|
||||
virtual void setHeight(int16_t height)
|
||||
{
|
||||
tiledImage.setHeight(height);
|
||||
T::setHeight(height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets tile bitmaps.
|
||||
*
|
||||
* @param bmpReleased The bitmap released.
|
||||
* @param bmpPressed The bitmap pressed.
|
||||
*/
|
||||
virtual void setTileBitmaps(const Bitmap& bmpReleased, const Bitmap& bmpPressed)
|
||||
{
|
||||
upTile = bmpReleased;
|
||||
downTile = bmpPressed;
|
||||
AbstractButtonContainer::setWidthHeight(downTile);
|
||||
|
||||
handlePressedUpdated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an offset into the bitmap where the tile drawing should start.
|
||||
*
|
||||
* @param x The x coordinate offset.
|
||||
* @param y The y coordinate offset.
|
||||
* @see TiledImage::setOffset
|
||||
*/
|
||||
virtual void setTileOffset(int16_t x, int16_t y)
|
||||
{
|
||||
tiledImage.setOffset(x, y);
|
||||
}
|
||||
|
||||
protected:
|
||||
TiledImage tiledImage; ///< The tiled image
|
||||
Bitmap upTile; ///< The image to display when button is released.
|
||||
Bitmap downTile; ///< The image to display when button is pressed.
|
||||
|
||||
/** @copydoc AbstractButtonContainer::handlePressedUpdated() */
|
||||
virtual void handlePressedUpdated()
|
||||
{
|
||||
int16_t buttonWidth = AbstractButtonContainer::getWidth();
|
||||
int16_t buttonHeight = AbstractButtonContainer::getHeight();
|
||||
|
||||
tiledImage.setBitmap(T::getPressed() ? downTile : upTile);
|
||||
tiledImage.setWidthHeight(buttonWidth, buttonHeight);
|
||||
T::handlePressedUpdated();
|
||||
}
|
||||
|
||||
/** @copydoc AbstractButtonContainer::handleAlphaUpdated() */
|
||||
virtual void handleAlphaUpdated()
|
||||
{
|
||||
tiledImage.setAlpha(T::getAlpha());
|
||||
T::handleAlphaUpdated();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_TILEDIMAGEBUTTONSTYLE_HPP
|
||||
@ -0,0 +1,103 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/buttons/ToggleButtonTrigger.hpp
|
||||
*
|
||||
* Declares the touchgfx::ToggleButtonTrigger class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_TOGGLEBUTTONTRIGGER_HPP
|
||||
#define TOUCHGFX_TOGGLEBUTTONTRIGGER_HPP
|
||||
|
||||
#include <touchgfx/containers/buttons/AbstractButtonContainer.hpp>
|
||||
#include <touchgfx/events/ClickEvent.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A toggle button trigger. This trigger will create a button that reacts on clicks. This means
|
||||
* it will call the set action when it gets a touch released event, just like a
|
||||
* ClickButtonTrigger. The difference being that a ToggleButtonTrigger will stay in
|
||||
* pressed state until it is clicked again.
|
||||
*
|
||||
* The ToggleButtonTrigger can be combined with one or more of the ButtonStyle classes
|
||||
* to create a fully functional button.
|
||||
*/
|
||||
class ToggleButtonTrigger : public AbstractButtonContainer
|
||||
{
|
||||
public:
|
||||
ToggleButtonTrigger()
|
||||
: AbstractButtonContainer(), toggleCanceled(false)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the button to be forced into either the pressed state, or the normal state. In
|
||||
* the pressed state, the button will always be shown as pressed down (and shown as
|
||||
* released when the user presses it). In the normal state, the button will be show as
|
||||
* released or pressed depending on its actual state.
|
||||
*
|
||||
* @param activeState If true, swap the images for released and pressed. If false display
|
||||
* the button normally.
|
||||
*/
|
||||
void forceState(bool activeState)
|
||||
{
|
||||
AbstractButtonContainer::setPressed(activeState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets toggle canceled.
|
||||
*
|
||||
* @param isToggleCanceled True if is toggle canceled, false if not.
|
||||
*/
|
||||
void setToggleCanceled(bool isToggleCanceled)
|
||||
{
|
||||
toggleCanceled = isToggleCanceled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets toggle canceled.
|
||||
*
|
||||
* @return True if it succeeds, false if it fails.
|
||||
*/
|
||||
bool getToggleCanceled()
|
||||
{
|
||||
return toggleCanceled;
|
||||
}
|
||||
|
||||
virtual void handleClickEvent(const ClickEvent& event)
|
||||
{
|
||||
bool wasPressed = getPressed();
|
||||
bool newPressedValue = !getPressed();
|
||||
bool toggleCanceled = getToggleCanceled();
|
||||
setToggleCanceled(event.getType() == ClickEvent::CANCEL);
|
||||
|
||||
if (((newPressedValue && !wasPressed) || (!newPressedValue && wasPressed)) && (event.getType() != ClickEvent::RELEASED) && !toggleCanceled)
|
||||
{
|
||||
setPressed(newPressedValue);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
if (!toggleCanceled && (event.getType() == ClickEvent::RELEASED))
|
||||
{
|
||||
executeAction();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
bool toggleCanceled; ///< True if toggle canceled
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_TOGGLEBUTTONTRIGGER_HPP
|
||||
@ -0,0 +1,65 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/buttons/TouchButtonTrigger.hpp
|
||||
*
|
||||
* Declares the touchgfx::TouchButtonTrigger class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_TOUCHBUTTONTRIGGER_HPP
|
||||
#define TOUCHGFX_TOUCHBUTTONTRIGGER_HPP
|
||||
|
||||
#include <touchgfx/containers/buttons/AbstractButtonContainer.hpp>
|
||||
#include <touchgfx/events/ClickEvent.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A touch button trigger. This trigger will create a button that reacts on touches. This means
|
||||
* it will call the set action when it gets a touch pressed event. The
|
||||
* TouchButtonTrigger can be combined with one or more of the ButtonStyle classes to
|
||||
* create a fully functional button.
|
||||
*
|
||||
* @see ClickButtonTrigger
|
||||
*/
|
||||
class TouchButtonTrigger : public AbstractButtonContainer
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Handles a ClickAvent. The action callback is called when the ClickButtonTrigger
|
||||
* receives a ClickEvent::PRESSED event. Function setPressed() will be called with the
|
||||
* new button state.
|
||||
*
|
||||
* @param event The click event.
|
||||
*
|
||||
* @see setAction, setPressed, getPressed
|
||||
*/
|
||||
virtual void handleClickEvent(const ClickEvent& event)
|
||||
{
|
||||
bool wasPressed = getPressed();
|
||||
bool newPressedValue = (event.getType() == ClickEvent::PRESSED);
|
||||
if ((newPressedValue && !wasPressed) || (!newPressedValue && wasPressed))
|
||||
{
|
||||
setPressed(newPressedValue);
|
||||
invalidate();
|
||||
}
|
||||
if (newPressedValue)
|
||||
{
|
||||
executeAction();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_TOUCHBUTTONTRIGGER_HPP
|
||||
@ -0,0 +1,183 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/buttons/TwoWildcardTextButtonStyle.hpp
|
||||
*
|
||||
* Declares the touchgfx::TwoWildcardTextButtonStyle class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_TWOWILDCARDTEXTBUTTONSTYLE_HPP
|
||||
#define TOUCHGFX_TWOWILDCARDTEXTBUTTONSTYLE_HPP
|
||||
|
||||
#include <touchgfx/Unicode.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/TextAreaWithWildcard.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A wildcard text button style.
|
||||
*
|
||||
* An wildcard text button style. This class is supposed to be used with one of the
|
||||
* ButtonTrigger classes to create a functional button. This class will show a text with
|
||||
* a wildcard in one of two colors depending on the state of the button (pressed or
|
||||
* released).
|
||||
*
|
||||
* The TwoWildcardTextButtonStyle does not set the size of the enclosing container
|
||||
* (normally AbstractButtonContainer). The size must be set manually.
|
||||
*
|
||||
* To get a background behind the text, use TwoWildcardTextButtonStyle together with
|
||||
* e.g. ImageButtonStyle:
|
||||
* @code
|
||||
* TwoWildcardTextButtonStyle<ImageButtonStyle<ClickButtonTrigger> > myButton;
|
||||
* @endcode
|
||||
*
|
||||
* The position of the text can be adjusted with setTwoWildcardTextXY (default is
|
||||
* centered).
|
||||
*
|
||||
* @tparam T Generic type parameter. Typically a AbstractButtonContainer subclass.
|
||||
*
|
||||
* @see AbstractButtonContainer
|
||||
*/
|
||||
template <class T>
|
||||
class TwoWildcardTextButtonStyle : public T
|
||||
{
|
||||
public:
|
||||
TwoWildcardTextButtonStyle()
|
||||
: T()
|
||||
{
|
||||
T::add(twoWildcardText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets wildcard text.
|
||||
*
|
||||
* @param t A TypedText to process.
|
||||
*/
|
||||
void setTwoWildcardText(TypedText t)
|
||||
{
|
||||
twoWildcardText.setTypedText(t);
|
||||
twoWildcardText.setWidthHeight(T::getWidth(), T::getHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets wildcard text x coordinate.
|
||||
*
|
||||
* @param x The x coordinate.
|
||||
*/
|
||||
void setTwoWildcardTextX(int16_t x)
|
||||
{
|
||||
twoWildcardText.setX(x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets wildcard text y coordinate.
|
||||
*
|
||||
* @param y The y coordinate.
|
||||
*/
|
||||
void setTwoWildcardTextY(int16_t y)
|
||||
{
|
||||
twoWildcardText.setY(y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets wildcard text position.
|
||||
*
|
||||
* @param x The x coordinate.
|
||||
* @param y The y coordinate.
|
||||
*/
|
||||
void setTwoWildcardTextXY(int16_t x, int16_t y)
|
||||
{
|
||||
setTwoWildcardTextX(x);
|
||||
setTwoWildcardTextY(y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets text position and dimensions.
|
||||
*
|
||||
* @param x The x coordinate.
|
||||
* @param y The y coordinate.
|
||||
* @param width The width of the text.
|
||||
* @param height The height of the text.
|
||||
*/
|
||||
void setTwoWildcardTextPosition(int16_t x, int16_t y, int16_t width, int16_t height)
|
||||
{
|
||||
twoWildcardText.setPosition(x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets wildcard text rotation.
|
||||
*
|
||||
* @param rotation The rotation.
|
||||
*/
|
||||
void setTwoWildcardTextRotation(TextRotation rotation)
|
||||
{
|
||||
twoWildcardText.setRotation(rotation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the first wildcard in the text. Must be a null-terminated UnicodeChar array.
|
||||
*
|
||||
* @param value A pointer to the UnicodeChar to set the wildcard to.
|
||||
*/
|
||||
void setWildcardTextBuffer1(const Unicode::UnicodeChar* value)
|
||||
{
|
||||
twoWildcardText.setWildcard1(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the second wildcard in the text. Must be a null-terminated UnicodeChar array.
|
||||
*
|
||||
* @param value A pointer to the UnicodeChar to set the wildcard to.
|
||||
*/
|
||||
void setWildcardTextBuffer2(const Unicode::UnicodeChar* value)
|
||||
{
|
||||
twoWildcardText.setWildcard2(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets wild card text colors.
|
||||
*
|
||||
* @param newColorReleased The new color released.
|
||||
* @param newColorPressed The new color pressed.
|
||||
*/
|
||||
void setTwoWildcardTextColors(colortype newColorReleased, colortype newColorPressed)
|
||||
{
|
||||
colorReleased = newColorReleased;
|
||||
colorPressed = newColorPressed;
|
||||
|
||||
handlePressedUpdated();
|
||||
}
|
||||
|
||||
protected:
|
||||
TextAreaWithTwoWildcards twoWildcardText; ///< The wildcard text
|
||||
colortype colorReleased; ///< The color released
|
||||
colortype colorPressed; ///< The color pressed
|
||||
|
||||
/** @copydoc AbstractButtonContainer::handlePressedUpdated() */
|
||||
virtual void handlePressedUpdated()
|
||||
{
|
||||
twoWildcardText.setColor(T::getPressed() ? colorPressed : colorReleased);
|
||||
T::handlePressedUpdated();
|
||||
}
|
||||
|
||||
/** @copydoc AbstractButtonContainer::handleAlphaUpdated() */
|
||||
virtual void handleAlphaUpdated()
|
||||
{
|
||||
twoWildcardText.setAlpha(T::getAlpha());
|
||||
T::handleAlphaUpdated();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_TWOWILDCARDTEXTBUTTONSTYLE_HPP
|
||||
@ -0,0 +1,172 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/buttons/WildcardTextButtonStyle.hpp
|
||||
*
|
||||
* Declares the touchgfx::WildcardTextButtonStyle class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_WILDCARDTEXTBUTTONSTYLE_HPP
|
||||
#define TOUCHGFX_WILDCARDTEXTBUTTONSTYLE_HPP
|
||||
|
||||
#include <touchgfx/Unicode.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/TextAreaWithWildcard.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A wildcard text button style.
|
||||
*
|
||||
* An wildcard text button style. This class is supposed to be used with one of the
|
||||
* ButtonTrigger classes to create a functional button. This class will show a text with
|
||||
* a wildcard in one of two colors depending on the state of the button (pressed or
|
||||
* released).
|
||||
*
|
||||
* The WildcardTextButtonStyle does not set the size of the enclosing container
|
||||
* (normally AbstractButtonContainer). The size must be set manually.
|
||||
*
|
||||
* To get a background behind the text, use WildcardTextButtonStyle together with e.g.
|
||||
* ImageButtonStyle:
|
||||
* @code
|
||||
* WildcardTextButtonStyle<ImageButtonStyle<ClickButtonTrigger> > myButton;
|
||||
* @endcode
|
||||
*
|
||||
* The position of the text can be adjusted with setTextXY (default is centered).
|
||||
*
|
||||
* @tparam T Generic type parameter. Typically a AbstractButtonContainer subclass.
|
||||
*
|
||||
* @see AbstractButtonContainer
|
||||
*/
|
||||
template <class T>
|
||||
class WildcardTextButtonStyle : public T
|
||||
{
|
||||
public:
|
||||
WildcardTextButtonStyle()
|
||||
: T()
|
||||
{
|
||||
T::add(wildcardText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets wildcard text.
|
||||
*
|
||||
* @param t A TypedText to process.
|
||||
*/
|
||||
void setWildcardText(TypedText t)
|
||||
{
|
||||
wildcardText.setTypedText(t);
|
||||
wildcardText.setWidthHeight(T::getWidth(), T::getHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets wildcard text x coordinate.
|
||||
*
|
||||
* @param x The x coordinate.
|
||||
*/
|
||||
void setWildcardTextX(int16_t x)
|
||||
{
|
||||
wildcardText.setX(x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets wildcard text y coordinate.
|
||||
*
|
||||
* @param y The y coordinate.
|
||||
*/
|
||||
void setWildcardTextY(int16_t y)
|
||||
{
|
||||
wildcardText.setY(y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets wildcard text position.
|
||||
*
|
||||
* @param x The x coordinate.
|
||||
* @param y The y coordinate.
|
||||
*/
|
||||
void setWildcardTextXY(int16_t x, int16_t y)
|
||||
{
|
||||
setWildcardTextX(x);
|
||||
setWildcardTextY(y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets text position and dimensions.
|
||||
*
|
||||
* @param x The x coordinate.
|
||||
* @param y The y coordinate.
|
||||
* @param width The width of the text.
|
||||
* @param height The height of the text.
|
||||
*/
|
||||
void setWildcardTextPosition(int16_t x, int16_t y, int16_t width, int16_t height)
|
||||
{
|
||||
wildcardText.setPosition(x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets wildcard text rotation.
|
||||
*
|
||||
* @param rotation The rotation.
|
||||
*/
|
||||
void setWildcardTextRotation(TextRotation rotation)
|
||||
{
|
||||
wildcardText.setRotation(rotation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets wildcard text buffer.
|
||||
*
|
||||
* @param buffer If non-null, the buffer.
|
||||
*/
|
||||
void setWildcardTextBuffer(const Unicode::UnicodeChar* buffer)
|
||||
{
|
||||
wildcardText.setWildcard(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets wild card text colors.
|
||||
*
|
||||
* @param newColorReleased The new color released.
|
||||
* @param newColorPressed The new color pressed.
|
||||
*/
|
||||
void setWildcardTextColors(colortype newColorReleased, colortype newColorPressed)
|
||||
{
|
||||
colorReleased = newColorReleased;
|
||||
colorPressed = newColorPressed;
|
||||
|
||||
handlePressedUpdated();
|
||||
}
|
||||
|
||||
protected:
|
||||
TextAreaWithOneWildcard wildcardText; ///< The wildcard text
|
||||
colortype colorReleased; ///< The color released
|
||||
colortype colorPressed; ///< The color pressed
|
||||
|
||||
/** @copydoc AbstractButtonContainer::handlePressedUpdated() */
|
||||
virtual void handlePressedUpdated()
|
||||
{
|
||||
wildcardText.setColor(T::getPressed() ? colorPressed : colorReleased);
|
||||
T::handlePressedUpdated();
|
||||
}
|
||||
|
||||
/** @copydoc AbstractButtonContainer::handleAlphaUpdated() */
|
||||
virtual void handleAlphaUpdated()
|
||||
{
|
||||
wildcardText.setAlpha(T::getAlpha());
|
||||
T::handleAlphaUpdated();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_WILDCARDTEXTBUTTONSTYLE_HPP
|
||||
@ -0,0 +1,121 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/clock/AbstractClock.hpp
|
||||
*
|
||||
* Declares the touchgfx::AbstractClock class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_ABSTRACTCLOCK_HPP
|
||||
#define TOUCHGFX_ABSTRACTCLOCK_HPP
|
||||
|
||||
#include <touchgfx/containers/Container.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* Superclass of clock widgets. Allows the hour, minute and second of the clock to be set and
|
||||
* read.
|
||||
*
|
||||
* @see AnalogClock, DigitalClock
|
||||
*/
|
||||
class AbstractClock : public Container
|
||||
{
|
||||
public:
|
||||
AbstractClock();
|
||||
|
||||
/**
|
||||
* Sets the time with input format as 24H. Note that this does not affect any selected
|
||||
* presentation formats.
|
||||
*
|
||||
* @param hour The hours, value should be between 0 and 23.
|
||||
* @param minute The minutes, value should be between 0 and 59.
|
||||
* @param second The seconds, value should be between 0 and 59.
|
||||
*
|
||||
* @note all values passed are saved modulo the values limit. For example minutes=62 is
|
||||
* treated as minutes=2.
|
||||
*/
|
||||
virtual void setTime24Hour(uint8_t hour, uint8_t minute, uint8_t second);
|
||||
|
||||
/**
|
||||
* Sets the time with input format as 12H. Note that this does not affect any selected
|
||||
* presentation formats.
|
||||
*
|
||||
* @param hour The hours, value should be between 1 and 12.
|
||||
* @param minute The minutes, value should be between 0 and 59.
|
||||
* @param second The seconds, value should be between 0 and 59.
|
||||
* @param am AM/PM setting. True = AM, false = PM.
|
||||
*
|
||||
* @note all values passed are saved modulo the values limit. For example minutes=62 is
|
||||
* treated as minutes=2.
|
||||
*/
|
||||
virtual void setTime12Hour(uint8_t hour, uint8_t minute, uint8_t second, bool am);
|
||||
|
||||
/**
|
||||
* Gets the current hour.
|
||||
*
|
||||
* @return The current hour in range 0-23.
|
||||
*
|
||||
* @see getCurrentHour24, getCurrentHour12
|
||||
*/
|
||||
uint8_t getCurrentHour() const;
|
||||
|
||||
/**
|
||||
* Gets current hour 24, i.e. between 0 and 23.
|
||||
*
|
||||
* @return The current hour in range 0-23.
|
||||
*/
|
||||
uint8_t getCurrentHour24() const;
|
||||
|
||||
/**
|
||||
* Gets current hour 12, i.e. between 1 and 12.
|
||||
*
|
||||
* @return The current hour in range 1-12.
|
||||
*
|
||||
* @see getCurrentHour24, getCurrentAM
|
||||
*/
|
||||
uint8_t getCurrentHour12() const;
|
||||
|
||||
/**
|
||||
* Is the current time a.m. or p.m.? True for a.m. and false for p.m.
|
||||
*
|
||||
* @return True if a.m., false if p.m.
|
||||
*/
|
||||
bool getCurrentAM() const;
|
||||
|
||||
/**
|
||||
* Gets the current minute.
|
||||
*
|
||||
* @return The current minute in range 0-59.
|
||||
*/
|
||||
uint8_t getCurrentMinute() const;
|
||||
|
||||
/**
|
||||
* Gets the current second.
|
||||
*
|
||||
* @return The current second in range 0-59.
|
||||
*/
|
||||
uint8_t getCurrentSecond() const;
|
||||
|
||||
protected:
|
||||
uint8_t currentHour; ///< Local copy of the current hour
|
||||
uint8_t currentMinute; ///< Local copy of the current minute
|
||||
uint8_t currentSecond; ///< Local copy of the current second
|
||||
|
||||
/** Update the visual representation of the clock on the display. */
|
||||
virtual void updateClock() = 0;
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_ABSTRACTCLOCK_HPP
|
||||
@ -0,0 +1,285 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/clock/AnalogClock.hpp
|
||||
*
|
||||
* Declares the touchgfx::AnalogClock class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_ANALOGCLOCK_HPP
|
||||
#define TOUCHGFX_ANALOGCLOCK_HPP
|
||||
|
||||
#include <touchgfx/Bitmap.hpp>
|
||||
#include <touchgfx/EasingEquations.hpp>
|
||||
#include <touchgfx/containers/clock/AbstractClock.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/AnimationTextureMapper.hpp>
|
||||
#include <touchgfx/widgets/Image.hpp>
|
||||
#include <touchgfx/widgets/TextureMapper.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* An analog clock. Should be supplied with images for the background, hour hand, minute hand
|
||||
* and the optional second hand. You setup the AnalogClock by specifying the rotation
|
||||
* point of each hand as well as the global rotation point of the clock. You can
|
||||
* customize the behavior of the AnalogClock in respect to animations and relations
|
||||
* between the hands e.g. if the hour hand should move gradually towards the next hour
|
||||
* as the minute hand progresses (setHourHandMinuteCorrection())
|
||||
*/
|
||||
class AnalogClock : public AbstractClock
|
||||
{
|
||||
public:
|
||||
AnalogClock();
|
||||
|
||||
/**
|
||||
* Sets the background image of the clock. The clock rotation center is automatically
|
||||
* set to the background image center. The clock rotation center is the point that the
|
||||
* clock hands rotates around. The size of the AnalocClock widget is set to the size of
|
||||
* the bitmap.
|
||||
*
|
||||
* @param backgroundBitmapId Identifier for the background bitmap.
|
||||
*/
|
||||
virtual void setBackground(const BitmapId backgroundBitmapId);
|
||||
|
||||
/**
|
||||
* Sets the background image of the clock and the rotation center of the clock. The
|
||||
* clock rotation center is the point that the clock hands rotates around. The size of
|
||||
* the AnalocClock widget is set to the size of the bitmap.
|
||||
*
|
||||
* @param backgroundBitmapId Identifier for the background bitmap.
|
||||
* @param rotationCenterX The rotation center x coordinate.
|
||||
* @param rotationCenterY The rotation center y coordinate.
|
||||
*
|
||||
* @see setBackground(BitmapId), setRotationCenter
|
||||
*/
|
||||
virtual void setBackground(const BitmapId backgroundBitmapId, int16_t rotationCenterX, int16_t rotationCenterY);
|
||||
|
||||
/**
|
||||
* Sets the rotation center of the clock. The clock rotation center is the point that
|
||||
* the clock hands rotates around.
|
||||
*
|
||||
* @param rotationCenterX The rotation center x coordinate.
|
||||
* @param rotationCenterY The rotation center y coordinate.
|
||||
*/
|
||||
virtual void setRotationCenter(int16_t rotationCenterX, int16_t rotationCenterY);
|
||||
|
||||
/**
|
||||
* Sets up the hour hand. The specified rotation center is the point of the hand that is
|
||||
* to be placed on top of the clock rotation center. That is the point that the hand
|
||||
* rotates around. The rotation point is relative to the supplied bitmap and can be
|
||||
* placed outside of it.
|
||||
*
|
||||
* @param hourHandBitmapId Identifier for the hour hand bitmap.
|
||||
* @param rotationCenterX The hand rotation center x coordinate.
|
||||
* @param rotationCenterY The hand rotation center y coordinate.
|
||||
*
|
||||
* @note If no hour hand is setup it will just be omitted.
|
||||
*/
|
||||
virtual void setupHourHand(const BitmapId hourHandBitmapId, int16_t rotationCenterX, int16_t rotationCenterY);
|
||||
|
||||
/**
|
||||
* Sets up the minute hand. The specified rotation center is the point of the hand that
|
||||
* is to be placed on top of the clock rotation center. That is the point that the hand
|
||||
* rotates around. The rotation point is relative to the supplied bitmap but can be
|
||||
* placed outside of it.
|
||||
*
|
||||
* @param minuteHandBitmapId Identifier for the minute hand bitmap.
|
||||
* @param rotationCenterX The hand rotation center x coordinate.
|
||||
* @param rotationCenterY The hand rotation center y coordinate.
|
||||
*
|
||||
* @note If no minute hand is setup it will just be omitted.
|
||||
*/
|
||||
virtual void setupMinuteHand(const BitmapId minuteHandBitmapId, int16_t rotationCenterX, int16_t rotationCenterY);
|
||||
|
||||
/**
|
||||
* Sets up the second hand. The specified rotation center is the point of the hand that
|
||||
* is to be placed on top of the clock rotation center. That is the point that the hand
|
||||
* rotates around. The rotation point is relative to the supplied bitmap but can be
|
||||
* placed outside of it.
|
||||
*
|
||||
* @param secondHandBitmapId Identifier for the second hand bitmap.
|
||||
* @param rotationCenterX The hand rotation center x coordinate.
|
||||
* @param rotationCenterY The hand rotation center y coordinate.
|
||||
*
|
||||
* @note If no second hand is setup it will just be omitted.
|
||||
*/
|
||||
virtual void setupSecondHand(const BitmapId secondHandBitmapId, int16_t rotationCenterX, int16_t rotationCenterY);
|
||||
|
||||
/**
|
||||
* Sets whether hour hand minute correction should be active. If set to true the hour
|
||||
* hand will be positioned between the current hour and the next depending on the minute
|
||||
* hands position.
|
||||
*
|
||||
* @param active true to use hour hand correction.
|
||||
*
|
||||
* @see getHourHandMinuteCorrection
|
||||
*/
|
||||
virtual void setHourHandMinuteCorrection(bool active);
|
||||
|
||||
/**
|
||||
* Gets hour hand minute correction.
|
||||
*
|
||||
* @return true if hour hand minute correction is active.
|
||||
*
|
||||
* @see setHourHandMinuteCorrection
|
||||
*/
|
||||
virtual bool getHourHandMinuteCorrection() const;
|
||||
|
||||
/**
|
||||
* Sets whether minute hand second correction should be active. If set to true the
|
||||
* minute hand will be positioned between the current minute and the next depending on
|
||||
* the second hands position.
|
||||
*
|
||||
* @param active true to use.
|
||||
*
|
||||
* @see setMinuteHandSecondCorrection
|
||||
*/
|
||||
virtual void setMinuteHandSecondCorrection(bool active);
|
||||
|
||||
/**
|
||||
* Gets minute hand second correction.
|
||||
*
|
||||
* @return true if minute hand second correction is active.
|
||||
*
|
||||
* @see setHourHandMinuteCorrection
|
||||
*/
|
||||
virtual bool getMinuteHandSecondCorrection() const;
|
||||
|
||||
/**
|
||||
* Setup the clock to use animation for hand movements.
|
||||
*
|
||||
* @param duration (Optional) The animation duration, default is 10.
|
||||
* @param animationProgressionEquation (Optional) The animation progression equation,
|
||||
* default is EasingEquations::backEaseInOut.
|
||||
*/
|
||||
virtual void setAnimation(uint16_t duration = 10, EasingEquation animationProgressionEquation = EasingEquations::backEaseInOut);
|
||||
|
||||
/**
|
||||
* Gets the animation duration.
|
||||
*
|
||||
* @return The animation duration.
|
||||
*
|
||||
* @see setAnimation
|
||||
*/
|
||||
virtual uint16_t getAnimationDuration()
|
||||
{
|
||||
return animationDuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the time with input format as 24H. No animations are performed regardless of the
|
||||
* animation settings. This is often useful when setting up the AnalogClock where you do
|
||||
* not want an initial animation.
|
||||
*
|
||||
* @param hour The hours, value should be between 0 and 23.
|
||||
* @param minute The minutes, value should be between 0 and 59.
|
||||
* @param second The seconds, value should be between 0 and 59.
|
||||
*
|
||||
* @see setTime24Hour
|
||||
*
|
||||
* @note that this does not affect any selected presentation formats.
|
||||
*/
|
||||
virtual void initializeTime24Hour(uint8_t hour, uint8_t minute, uint8_t second);
|
||||
|
||||
/**
|
||||
* Sets the time with input format as 12H. No animations are performed regardless of the
|
||||
* animation settings. This is often useful when setting up the AnalogClock where you do
|
||||
* not want an initial animation.
|
||||
*
|
||||
* @param hour The hours, value should be between 1 and 12.
|
||||
* @param minute The minutes, value should be between 0 and 59.
|
||||
* @param second The seconds, value should be between 0 and 59.
|
||||
* @param am AM/PM setting. True = AM, false = PM.
|
||||
*
|
||||
* @see setTime12Hour
|
||||
*
|
||||
* @note that this does not affect any selected presentation formats.
|
||||
*/
|
||||
virtual void initializeTime12Hour(uint8_t hour, uint8_t minute, uint8_t second, bool am);
|
||||
|
||||
/**
|
||||
* @copydoc Image::setAlpha
|
||||
* @note The alpha value is reflected in the background image
|
||||
*/
|
||||
virtual void setAlpha(uint8_t newAlpha);
|
||||
|
||||
/** @copydoc Image::getAlpha() */
|
||||
virtual uint8_t getAlpha() const;
|
||||
|
||||
virtual void invalidateContent() const
|
||||
{
|
||||
if (getAlpha() > 0)
|
||||
{
|
||||
AbstractClock::invalidateContent();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
Image background; ///< The background image of the AnalogClock
|
||||
|
||||
AnimationTextureMapper hourHand; ///< TextureMapper used for drawing the hourHand
|
||||
AnimationTextureMapper minuteHand; ///< TextureMapper used for drawing the minuteHand
|
||||
AnimationTextureMapper secondHand; ///< TextureMapper used for drawing the secondHand
|
||||
|
||||
EasingEquation animationEquation; ///< The easing equation used by hand animations
|
||||
uint16_t animationDuration; ///< The duration of hand animations. If 0 animations are disabled
|
||||
|
||||
int16_t clockRotationCenterX; ///< The x coordinate of the rotation point of the hands
|
||||
int16_t clockRotationCenterY; ///< The y coordinate of the rotation point of the hands
|
||||
|
||||
uint8_t lastHour; ///< The last know hour value
|
||||
uint8_t lastMinute; ///< The last know minute value
|
||||
uint8_t lastSecond; ///< The last know second value
|
||||
|
||||
bool hourHandMinuteCorrectionActive; ///< Is hour hand minute correction active
|
||||
bool minuteHandSecondCorrectionActive; ///< Is minute hand second correction active
|
||||
|
||||
virtual void updateClock();
|
||||
|
||||
/**
|
||||
* Sets up a given the hand.
|
||||
*
|
||||
* @param [in] hand Reference to the hand being setup.
|
||||
* @param bitmapId The bitmap identifier for the given hand.
|
||||
* @param rotationCenterX The hand rotation center x coordinate.
|
||||
* @param rotationCenterY The hand rotation center y coordinate.
|
||||
*/
|
||||
virtual void setupHand(TextureMapper& hand, const BitmapId bitmapId, int16_t rotationCenterX, int16_t rotationCenterY);
|
||||
|
||||
/**
|
||||
* Convert hand value to angle.
|
||||
*
|
||||
* @param steps Number of steps the primary hand value is divided into, i.e.
|
||||
* 60 for minutes/seconds and 12 for hour.
|
||||
* @param handValue The actual value for the hand in question (in the range [0;
|
||||
* steps]).
|
||||
* @param secondHandValue (Optional) If the angle should be corrected for a secondary
|
||||
* hand its value should be specified here (in the range [0;
|
||||
* 60]). This is the case when setHourHandMinuteCorrection(true)
|
||||
* or setMinuteHandSecondCorrection(true) is selected.
|
||||
*
|
||||
* @return The converted value to angle.
|
||||
*/
|
||||
virtual float convertHandValueToAngle(uint8_t steps, uint8_t handValue, uint8_t secondHandValue = 0) const;
|
||||
|
||||
/**
|
||||
* Is animation enabled for the hands?
|
||||
*
|
||||
* @return true if animation is enabled.
|
||||
*/
|
||||
virtual bool animationEnabled() const;
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_ANALOGCLOCK_HPP
|
||||
@ -0,0 +1,173 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/clock/DigitalClock.hpp
|
||||
*
|
||||
* Declares the touchgfx::DigitalClock class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_DIGITALCLOCK_HPP
|
||||
#define TOUCHGFX_DIGITALCLOCK_HPP
|
||||
|
||||
#include <touchgfx/TypedText.hpp>
|
||||
#include <touchgfx/containers/clock/AbstractClock.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/TextAreaWithWildcard.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A digital clock. Can be set in either 12 or 24 hour mode. Seconds are optional. Width and
|
||||
* height must be set manually to match the typography and alignment specified in the
|
||||
* text database. The Digital Clock requires a typedText with one wildcard and uses the
|
||||
* following characters (not including quotes)
|
||||
* "AMP :0123456789" These must be present in the text database with the same typography
|
||||
* as the wildcard text. Leading zero for the hour indicator can be enabled/disable by
|
||||
* the displayLeadingZeroForHourIndicator method.
|
||||
*/
|
||||
class DigitalClock : public AbstractClock
|
||||
{
|
||||
public:
|
||||
/** Values that represent different display modes. */
|
||||
enum DisplayMode
|
||||
{
|
||||
DISPLAY_12_HOUR_NO_SECONDS, ///< 12 Hour clock. Seconds are not displayed
|
||||
DISPLAY_24_HOUR_NO_SECONDS, ///< 24 Hour clock. Seconds are not displayed
|
||||
DISPLAY_12_HOUR, ///< 12 Hour clock. Seconds are displayed
|
||||
DISPLAY_24_HOUR ///< 24 Hour clock. Seconds are displayed
|
||||
};
|
||||
|
||||
DigitalClock();
|
||||
|
||||
virtual void setWidth(int16_t width);
|
||||
|
||||
virtual void setHeight(int16_t height);
|
||||
|
||||
/**
|
||||
* Adjusts the DigitalClock y coordinate so the text will have its baseline at the
|
||||
* specified value. The placements is relative to the specified TypedText so if the
|
||||
* TypedText is changed, you have to set the baseline again.
|
||||
*
|
||||
* @param baselineY The y coordinate of the baseline of the text.
|
||||
*
|
||||
* @note that setTypedText must be called prior to setting the baseline.
|
||||
*/
|
||||
virtual void setBaselineY(int16_t baselineY);
|
||||
|
||||
/**
|
||||
* Sets the typed text of the DigitalClock. Expects a TypedText with one wildcard and
|
||||
* that the following characters are defined for the typography of the TypedText:
|
||||
* - 12 hour clock: "AMP :0123456789"
|
||||
* - 24 hour clock: ":0123456789"
|
||||
*
|
||||
* @param typedText Describes the typed text to use.
|
||||
*
|
||||
* @note Automatically invalidates the DigitalClock.
|
||||
*/
|
||||
virtual void setTypedText(TypedText typedText);
|
||||
|
||||
/**
|
||||
* Sets the color of the text.
|
||||
*
|
||||
* @param color The new text color.
|
||||
*
|
||||
* @note Automatically invalidates the DigitalClock.
|
||||
*/
|
||||
virtual void setColor(colortype color);
|
||||
|
||||
/**
|
||||
* Gets the color of the text.
|
||||
*
|
||||
* @return The color.
|
||||
*/
|
||||
virtual colortype getColor() const;
|
||||
|
||||
/**
|
||||
* Sets the display mode to 12/24 hour clock with or without seconds.
|
||||
*
|
||||
* @param dm The new display mode.
|
||||
*
|
||||
* @see DisplayMode, getDisplayMode
|
||||
*/
|
||||
virtual void setDisplayMode(DisplayMode dm)
|
||||
{
|
||||
displayMode = dm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current display mode.
|
||||
*
|
||||
* @return The display mode.
|
||||
*
|
||||
* @see DisplayMode, setDisplayMode
|
||||
*/
|
||||
virtual DisplayMode getDisplayMode() const
|
||||
{
|
||||
return displayMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to display a leading zero for the hour indicator or not, when the hour
|
||||
* value only has one digit. For example 8 can be displayed as "8:"
|
||||
* (displayLeadingZero=false) or "08:" (displayLeadingZero=true).
|
||||
*
|
||||
* Default value for this setting is false.
|
||||
*
|
||||
* @param displayLeadingZero true = show leading zero. false = do not show leading zero.
|
||||
*
|
||||
* @note This does not affect the display of minutes or seconds.
|
||||
*/
|
||||
void displayLeadingZeroForHourIndicator(bool displayLeadingZero);
|
||||
|
||||
/**
|
||||
* @copydoc Image::setAlpha
|
||||
*/
|
||||
virtual void setAlpha(uint8_t newAlpha);
|
||||
|
||||
/**
|
||||
* @copydoc Image::getAlpha
|
||||
*/
|
||||
virtual uint8_t getAlpha() const;
|
||||
|
||||
/**
|
||||
* Gets text width of the currently displayed DigitalClock.
|
||||
*
|
||||
* @return The text width of the currently displayed DigitalClock.
|
||||
*/
|
||||
virtual uint16_t getTextWidth() const
|
||||
{
|
||||
return text.getTextWidth();
|
||||
}
|
||||
|
||||
virtual void invalidateContent() const
|
||||
{
|
||||
if (getAlpha() > 0)
|
||||
{
|
||||
AbstractClock::invalidateContent();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
static const int BUFFER_SIZE = 12; ///< Buffer size of the wild card, worst case is "12:59:59 AM" (12 chars)
|
||||
|
||||
DisplayMode displayMode; ///< The current display mode
|
||||
bool useLeadingZeroForHourIndicator; ///< Print a leading zero if the hour is less than 10
|
||||
|
||||
TextAreaWithOneWildcard text; ///< The clock text
|
||||
Unicode::UnicodeChar buffer[BUFFER_SIZE]; ///< Wild card buffer for the clock text
|
||||
|
||||
virtual void updateClock();
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_DIGITALCLOCK_HPP
|
||||
@ -0,0 +1,68 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/progress_indicators/AbstractDirectionProgress.hpp
|
||||
*
|
||||
* Declares the touchgfx::AbstractDirectionProgress class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_ABSTRACTDIRECTIONPROGRESS_HPP
|
||||
#define TOUCHGFX_ABSTRACTDIRECTIONPROGRESS_HPP
|
||||
|
||||
#include <touchgfx/containers/progress_indicators/AbstractProgressIndicator.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* An abstract class for progress indicators that need a horizontal or vertical direction to be
|
||||
* specified.
|
||||
*/
|
||||
class AbstractDirectionProgress : public AbstractProgressIndicator
|
||||
{
|
||||
public:
|
||||
/** Values that represent directions. */
|
||||
enum DirectionType
|
||||
{
|
||||
RIGHT, ///< Progress should be from left to right
|
||||
LEFT, ///< Progress should be from right to left
|
||||
DOWN, ///< Progress should be down (top to bottom)
|
||||
UP ///< Progress should be up (bottom to top)
|
||||
};
|
||||
|
||||
AbstractDirectionProgress();
|
||||
|
||||
/**
|
||||
* Sets a direction for the progress indicator. This will re-calculate the current value
|
||||
* according to the new direction.
|
||||
*
|
||||
* @param direction The direction.
|
||||
*
|
||||
* @see getDirection
|
||||
*/
|
||||
virtual void setDirection(DirectionType direction);
|
||||
|
||||
/**
|
||||
* Gets the current direction for the progress indicator.
|
||||
*
|
||||
* @return The direction.
|
||||
*
|
||||
* @see setDirection
|
||||
*/
|
||||
virtual DirectionType getDirection() const;
|
||||
|
||||
protected:
|
||||
DirectionType progressDirection; ///< The progress direction
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_ABSTRACTDIRECTIONPROGRESS_HPP
|
||||
@ -0,0 +1,298 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/progress_indicators/AbstractProgressIndicator.hpp
|
||||
*
|
||||
* Declares the touchgfx::AbstractProgressIndicator class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_ABSTRACTPROGRESSINDICATOR_HPP
|
||||
#define TOUCHGFX_ABSTRACTPROGRESSINDICATOR_HPP
|
||||
|
||||
#include <touchgfx/Bitmap.hpp>
|
||||
#include <touchgfx/Callback.hpp>
|
||||
#include <touchgfx/EasingEquations.hpp>
|
||||
#include <touchgfx/containers/Container.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/Image.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* The AbstractProgressIndicator declares methods that provides the basic mechanisms and tools
|
||||
* to implement a progress indicator. For more specific implementations see classes that
|
||||
* inherit from AbstractProgressIndicator.
|
||||
*
|
||||
* @see BoxProgress, CircleProgress, ImageProgress, LineProgress, TextProgress
|
||||
*/
|
||||
class AbstractProgressIndicator : public Container
|
||||
{
|
||||
public:
|
||||
/** Initializes a new instance of the AbstractProgressIndicator class with a default range 0-100. */
|
||||
AbstractProgressIndicator();
|
||||
|
||||
/**
|
||||
* Sets the background image. The width and height of the progress indicator widget is
|
||||
* updated according to the dimensions of the bitmap.
|
||||
*
|
||||
* @param bitmapBackground The background bitmap.
|
||||
*/
|
||||
virtual void setBackground(const Bitmap& bitmapBackground);
|
||||
|
||||
/**
|
||||
* Sets the position and dimensions of the actual progress indicator relative to the
|
||||
* background image.
|
||||
*
|
||||
* @param x The x coordinate.
|
||||
* @param y The y coordinate.
|
||||
* @param width The width of the box progress indicator.
|
||||
* @param height The height of the box progress indicator.
|
||||
*
|
||||
* @see getProgressIndicatorX, getProgressIndicatorY, getProgressIndicatorWidth,
|
||||
* getProgressIndicatorHeight
|
||||
*/
|
||||
virtual void setProgressIndicatorPosition(int16_t x, int16_t y, int16_t width, int16_t height);
|
||||
|
||||
/**
|
||||
* Gets progress indicator x coordinate.
|
||||
*
|
||||
* @return The progress indicator x coordinate.
|
||||
*
|
||||
* @see setProgressIndicatorPosition
|
||||
*/
|
||||
virtual int16_t getProgressIndicatorX() const;
|
||||
|
||||
/**
|
||||
* Gets progress indicator y coordinate.
|
||||
*
|
||||
* @return The progress indicator y coordinate.
|
||||
*
|
||||
* @see setProgressIndicatorPosition
|
||||
*/
|
||||
virtual int16_t getProgressIndicatorY() const;
|
||||
|
||||
/**
|
||||
* Gets progress indicator width.
|
||||
*
|
||||
* @return The progress indicator width.
|
||||
*
|
||||
* @see setProgressIndicatorPosition
|
||||
*/
|
||||
virtual int16_t getProgressIndicatorWidth() const;
|
||||
|
||||
/**
|
||||
* Gets progress indicator height.
|
||||
*
|
||||
* @return The progress indicator height.
|
||||
*
|
||||
* @see setProgressIndicatorPosition
|
||||
*/
|
||||
virtual int16_t getProgressIndicatorHeight() const;
|
||||
|
||||
/**
|
||||
* Sets the range for the progress indicator. The range is the values that are given to
|
||||
* the progress indicator while progressing through the task at hand. If an app needs to
|
||||
* work through 237 items to finish a task, the range should be set to (0, 237) assuming
|
||||
* that 0 items is the minimum. Though the minimum is often 0, it is possible to
|
||||
* customize this.
|
||||
*
|
||||
* The steps parameter is used to specify at what granularity you want the progress
|
||||
* indicator to report a new progress value. If the 237 items to be reported as 0%,
|
||||
* 10%, 20%, ... 100%, the steps should be set to 10 as there are ten steps from 0%
|
||||
* to 100%. If you want to update a widget which is 150 pixels wide, you might want to
|
||||
* set steps to 150 to get a new progress value for every pixel. If you are updating a
|
||||
* clock and want this to resemble an analog clock, you might want to use
|
||||
* 12 or perhaps 60 as number of steps.
|
||||
*
|
||||
* The minStep parameter is used when the minimum input value (min) should give a
|
||||
* progress different from 0. For example, if progress is a clock face, you want to
|
||||
* count from 0..1000 and you want progress per minute, but want to make sure that 0 is
|
||||
* not a blank clock face, but instead you want 1 minute to show, use
|
||||
* @code
|
||||
* setRange(0, 1000, 60, 1)
|
||||
* @endcode
|
||||
* to make sure that as values progress from 0 to 1000, getProgress() start from 1 and
|
||||
* goes up to 60. Another example could be a BoxProgress with a TextProgress on top and
|
||||
* you want to make sure that "0%" will always show in the box, use something like
|
||||
* @code
|
||||
* setRange(0, 1000, 200, 40)
|
||||
* @endcode
|
||||
* if your box is 200 pixels wide and "0%" is 40 pixels wide.
|
||||
*
|
||||
* @param min The minimum input value.
|
||||
* @param max The maximum input value.
|
||||
* @param steps (Optional) The steps in which to report progress.
|
||||
* @param minStep (Optional) The step which the minimum input value is mapped to.
|
||||
*
|
||||
* @see setValue, getProgress
|
||||
*/
|
||||
virtual void setRange(int min, int max, uint16_t steps = 0, uint16_t minStep = 0);
|
||||
|
||||
/**
|
||||
* Gets the range set by setRange().
|
||||
*
|
||||
* @param [out] min The minimum input value.
|
||||
* @param [out] max The maximum input value.
|
||||
* @param [out] steps The steps in which to report progress.
|
||||
* @param [out] minStep The step which the minimum input value is mapped to.
|
||||
*
|
||||
* @see setRange
|
||||
*/
|
||||
virtual void getRange(int& min, int& max, uint16_t& steps, uint16_t& minStep) const;
|
||||
|
||||
/**
|
||||
* Gets the range set by setRange().
|
||||
*
|
||||
* @param [out] min The minimum input value.
|
||||
* @param [out] max The maximum input value.
|
||||
* @param [out] steps The steps in which to report progress.
|
||||
*
|
||||
* @see setRange
|
||||
*/
|
||||
virtual void getRange(int& min, int& max, uint16_t& steps) const;
|
||||
|
||||
/**
|
||||
* Gets the range set by setRange().
|
||||
*
|
||||
* @param [out] min The minimum input value.
|
||||
* @param [out] max The maximum input value.
|
||||
*
|
||||
* @see setRange
|
||||
*/
|
||||
virtual void getRange(int& min, int& max) const;
|
||||
|
||||
/**
|
||||
* Sets the current value in the range (min..max) set by setRange(). Values lower than min
|
||||
* are mapped to min, values higher than max are mapped to max. If a callback function has
|
||||
* been set using setValueSetAction, that callback will be called (unless the new value
|
||||
* is the same as the current value).
|
||||
*
|
||||
* @param value The value.
|
||||
*
|
||||
* @see getValue, updateValue, setValueSetAction
|
||||
*
|
||||
* @note if value is equal to the current value, nothing happens, and the callback will not be
|
||||
* called.
|
||||
*/
|
||||
virtual void setValue(int value);
|
||||
|
||||
/**
|
||||
* Sets easing equation to be used in updateValue.
|
||||
*
|
||||
* @param easingEquation The easing equation.
|
||||
*
|
||||
* @see updateValue
|
||||
*/
|
||||
virtual void setEasingEquation(EasingEquation easingEquation);
|
||||
|
||||
/**
|
||||
* Update the current value in the range (min..max) set by setRange(). Values lower than min
|
||||
* are mapped to min, values higher than max are mapped to max. The value is changed
|
||||
* gradually in the given number of ticks using the easing equation set in
|
||||
* setEasingEquation. Function setValue() is called for every new value during the change of
|
||||
* value, and if a callback function has been set using setValueSetAction, that callback
|
||||
* will be called for every new value. The callback set using setValueUpdatedCallback is
|
||||
* called when the animation has finished.
|
||||
*
|
||||
* @param value The value.
|
||||
* @param duration The duration.
|
||||
*
|
||||
* @see setValue, setEasingEquation, setValueSetAction, setValueUpdatedAction
|
||||
*
|
||||
* @note If duration is 0, setValue will be called immediately and the valueUpdated action is
|
||||
* called immediately.
|
||||
*/
|
||||
virtual void updateValue(int value, uint16_t duration);
|
||||
|
||||
/**
|
||||
* Gets the current value set by setValue().
|
||||
*
|
||||
* @return The value.
|
||||
*
|
||||
* @see setValue
|
||||
*/
|
||||
virtual int getValue() const;
|
||||
|
||||
/**
|
||||
* Gets the current progress based on the range set by setRange() and the value set by
|
||||
* setValue().
|
||||
*
|
||||
* @param range (Optional) The range, default is 100.
|
||||
*
|
||||
* @return The progress.
|
||||
*
|
||||
* @see setRange, setValue, getValue
|
||||
*/
|
||||
virtual uint16_t getProgress(uint16_t range = 100) const;
|
||||
|
||||
/**
|
||||
* Sets callback that will be triggered every time a new value is assigned to the progress
|
||||
* indicator. This can happen directly from setValue() or during a gradual change initiated
|
||||
* using updateValue().
|
||||
*
|
||||
* @param callback The callback.
|
||||
*
|
||||
* @see setValue, updateValue
|
||||
*/
|
||||
void setValueSetAction(GenericCallback<const AbstractProgressIndicator&>& callback);
|
||||
|
||||
/**
|
||||
* Sets callback that will be triggered when updateValue has finished animating to the final
|
||||
* value.
|
||||
*
|
||||
* @param callback The callback.
|
||||
*
|
||||
* @see updateValue, setValueSetAction
|
||||
*/
|
||||
void setValueUpdatedAction(GenericCallback<const AbstractProgressIndicator&>& callback);
|
||||
|
||||
/**
|
||||
* @copydoc Image::setAlpha
|
||||
*/
|
||||
virtual void setAlpha(uint8_t newAlpha);
|
||||
|
||||
/**
|
||||
* @copydoc Image::getAlpha
|
||||
*/
|
||||
virtual uint8_t getAlpha() const;
|
||||
|
||||
virtual void handleTickEvent();
|
||||
|
||||
virtual void invalidateContent() const
|
||||
{
|
||||
if (getAlpha() > 0)
|
||||
{
|
||||
Container::invalidateContent();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
Image background; ///< The background image
|
||||
Container progressIndicatorContainer; ///< The container that holds the actual progress indicator
|
||||
int rangeMin; ///< The range minimum
|
||||
int rangeMax; ///< The range maximum
|
||||
int currentValue; ///< The current value
|
||||
uint16_t rangeSteps; ///< The range steps
|
||||
uint16_t rangeStepsMin; ///< The range steps minimum
|
||||
EasingEquation equation; ///< The equation used in updateValue()
|
||||
bool animationRunning; ///< Is the animation running
|
||||
int animationStartValue; ///< The animation start value
|
||||
int animationEndValue; ///< The animation end value
|
||||
int animationDuration; ///< Duration of the animation
|
||||
int animationStep; ///< The current animation step
|
||||
GenericCallback<const AbstractProgressIndicator&>* valueSetCallback; ///< New value assigned Callback.
|
||||
GenericCallback<const AbstractProgressIndicator&>* valueUpdatedCallback; ///< Animation ended Callback.
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_ABSTRACTPROGRESSINDICATOR_HPP
|
||||
@ -0,0 +1,69 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/progress_indicators/BoxProgress.hpp
|
||||
*
|
||||
* Declares the touchgfx::BoxProgress class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_BOXPROGRESS_HPP
|
||||
#define TOUCHGFX_BOXPROGRESS_HPP
|
||||
|
||||
#include <touchgfx/containers/progress_indicators/AbstractDirectionProgress.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/Box.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A BoxProgress which shows the current progress using a simple Box. It is possible to set the
|
||||
* color and the alpha of the box. It is also possible to control in what direction the
|
||||
* box will progress (up, down, to the left or to the right).
|
||||
*/
|
||||
class BoxProgress : public AbstractDirectionProgress
|
||||
{
|
||||
public:
|
||||
BoxProgress();
|
||||
|
||||
virtual void setProgressIndicatorPosition(int16_t x, int16_t y, int16_t width, int16_t height);
|
||||
|
||||
/**
|
||||
* Sets the color of the Box.
|
||||
*
|
||||
* @param color The color.
|
||||
* @see getColor
|
||||
*/
|
||||
virtual void setColor(colortype color);
|
||||
|
||||
/**
|
||||
* Gets the color of the Box.
|
||||
*
|
||||
* @return The color.
|
||||
*
|
||||
* @see setColor
|
||||
*/
|
||||
virtual colortype getColor() const;
|
||||
|
||||
/**
|
||||
* @copydoc Image::setAlpha
|
||||
*/
|
||||
virtual void setAlpha(uint8_t newAlpha);
|
||||
|
||||
virtual void setValue(int value);
|
||||
|
||||
protected:
|
||||
Box box; ///< The box
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_BOXPROGRESS_HPP
|
||||
@ -0,0 +1,177 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/progress_indicators/CircleProgress.hpp
|
||||
*
|
||||
* Declares the touchgfx::CircleProgress class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_CIRCLEPROGRESS_HPP
|
||||
#define TOUCHGFX_CIRCLEPROGRESS_HPP
|
||||
|
||||
#include <touchgfx/containers/progress_indicators/AbstractProgressIndicator.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/canvas/AbstractPainter.hpp>
|
||||
#include <touchgfx/widgets/canvas/Circle.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A circle progress indicator uses CanvasWidgetRenderer for drawing the arc of a Circle to show
|
||||
* progress. This means that the user must create a painter for painting the circle. The
|
||||
* circle progress is defined by setting the minimum and maximum angle of the arc.
|
||||
*
|
||||
* @note As CircleProgress uses CanvasWidgetRenderer, it is important that a buffer is set up
|
||||
* by calling CanvasWidgetRendere::setBuffer().
|
||||
*/
|
||||
class CircleProgress : public AbstractProgressIndicator
|
||||
{
|
||||
public:
|
||||
CircleProgress();
|
||||
|
||||
virtual void setProgressIndicatorPosition(int16_t x, int16_t y, int16_t width, int16_t height);
|
||||
|
||||
/**
|
||||
* Sets the painter to use for drawing the circle progress.
|
||||
*
|
||||
* @param [in] painter The painter.
|
||||
*
|
||||
* @see Circle::setPainter, AbstractPainter
|
||||
*/
|
||||
virtual void setPainter(AbstractPainter& painter);
|
||||
|
||||
/**
|
||||
* Sets the center of the circle / arc.
|
||||
*
|
||||
* @param x The x coordinate of the center of the circle.
|
||||
* @param y The y coordinate of the center of the circle.
|
||||
*/
|
||||
virtual void setCenter(int x, int y);
|
||||
|
||||
/**
|
||||
* Gets the circle center coordinates.
|
||||
*
|
||||
* @param [out] x The x coordinate of the center of the circle.
|
||||
* @param [out] y The y coordinate of the center of the circle.
|
||||
*/
|
||||
virtual void getCenter(int& x, int& y) const;
|
||||
|
||||
/**
|
||||
* Sets the radius of the circle.
|
||||
*
|
||||
* @param r The radius.
|
||||
*
|
||||
* @see Circle::setRadius
|
||||
*/
|
||||
virtual void setRadius(int r);
|
||||
|
||||
/**
|
||||
* Gets the radius of the circle.
|
||||
*
|
||||
* @return The radius.
|
||||
*/
|
||||
virtual int getRadius() const;
|
||||
|
||||
/**
|
||||
* Sets line width of the circle. If a line width of zero is specified, it has a special
|
||||
* meaning of drawing a filled circle (with the set radius) instead of just the circle arc.
|
||||
*
|
||||
* @param width The width of the line (0 produces a filled circle with the given radius).
|
||||
*
|
||||
* @see Circle::setLineWidth, setRadius
|
||||
*/
|
||||
virtual void setLineWidth(int width);
|
||||
|
||||
/**
|
||||
* Gets line width.
|
||||
*
|
||||
* @return The line width.
|
||||
*
|
||||
* @see setLineWidth
|
||||
*/
|
||||
virtual int getLineWidth() const;
|
||||
|
||||
/**
|
||||
* Sets the cap precision of end of the circle arc. This is not used if line width is
|
||||
* zero.
|
||||
*
|
||||
* @param precision The cap precision.
|
||||
*
|
||||
* @see Circle::setCapPrecision, getCapPrecision
|
||||
*/
|
||||
virtual void setCapPrecision(int precision);
|
||||
|
||||
/**
|
||||
* Gets the cap precision.
|
||||
*
|
||||
* @return The cap precision.
|
||||
*
|
||||
* @see setCapPrecision
|
||||
*/
|
||||
virtual int getCapPrecision() const
|
||||
{
|
||||
return circle.getCapPrecision();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets start angle and end angle in degrees. By swapping end and start angles, circles can
|
||||
* progress backwards.
|
||||
*
|
||||
* @param startAngle The start angle.
|
||||
* @param endAngle The end angle.
|
||||
*
|
||||
* @note Angles are given in degrees, so a full circle is 360.
|
||||
*/
|
||||
virtual void setStartEndAngle(int startAngle, int endAngle);
|
||||
|
||||
/**
|
||||
* Gets start angle in degrees.
|
||||
*
|
||||
* @return The start angle.
|
||||
*
|
||||
* @see setStartEndAngle, getEndAngle
|
||||
*
|
||||
* @note Angles are given in degrees, so a full circle is 360.
|
||||
*/
|
||||
virtual int getStartAngle() const;
|
||||
|
||||
/**
|
||||
* Gets end angle in degrees. Beware that the value returned is not related to the current
|
||||
* progress of the circle but rather the end point of the circle when it is at 100%.
|
||||
*
|
||||
* @return The end angle.
|
||||
*
|
||||
* @see setStartEndAngle
|
||||
*
|
||||
* @note Angles are given in degrees, so a full circle is 360.
|
||||
*/
|
||||
virtual int getEndAngle() const;
|
||||
|
||||
/**
|
||||
* @copydoc Image::setAlpha
|
||||
*
|
||||
* @note The alpha can also be set on the Painter, but this can be controlled directly from
|
||||
* the user app, setting alpha for the CircleProgress will set the alpha of the
|
||||
* actual circle.
|
||||
*/
|
||||
virtual void setAlpha(uint8_t newAlpha);
|
||||
|
||||
virtual void setValue(int value);
|
||||
|
||||
protected:
|
||||
Circle circle; ///< The circle
|
||||
int circleEndAngle; ///< The end angle
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_CIRCLEPROGRESS_HPP
|
||||
@ -0,0 +1,99 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/progress_indicators/ImageProgress.hpp
|
||||
*
|
||||
* Declares the touchgfx::ImageProgress class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_IMAGEPROGRESS_HPP
|
||||
#define TOUCHGFX_IMAGEPROGRESS_HPP
|
||||
|
||||
#include <touchgfx/Bitmap.hpp>
|
||||
#include <touchgfx/containers/progress_indicators/AbstractDirectionProgress.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/TiledImage.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* An image progress will show parts of an image as a progress indicator. The image can progress
|
||||
* from the left, the right, the bottom or the top of the given area, and can visually
|
||||
* be fixed with a larger and larger portion of the image showing, or it can be moved
|
||||
* into view.
|
||||
*/
|
||||
class ImageProgress : public AbstractDirectionProgress
|
||||
{
|
||||
public:
|
||||
ImageProgress();
|
||||
|
||||
virtual void setProgressIndicatorPosition(int16_t x, int16_t y, int16_t width, int16_t height);
|
||||
|
||||
/**
|
||||
* Sets anchor at zero.
|
||||
*
|
||||
* Setting anchor at zero will force the image will be placed so that it is not moved
|
||||
* during progress, only more and more of the image will become visible. If the image is
|
||||
* not anchored at zero, it will be anchored at the current progress and will appear to
|
||||
* slide into view.
|
||||
*
|
||||
* @param anchorAtZero true to anchor at zero, false to anchor at current progress.
|
||||
*
|
||||
* @see getAnchorAtZero
|
||||
*/
|
||||
virtual void setAnchorAtZero(bool anchorAtZero);
|
||||
|
||||
/**
|
||||
* Gets the current anchor at zero setting.
|
||||
*
|
||||
* @return true if the image is anchored at zero, false if it is anchored at current
|
||||
* progress.
|
||||
*
|
||||
* @see setAnchorAtZero
|
||||
*/
|
||||
virtual bool getAnchorAtZero() const;
|
||||
|
||||
/**
|
||||
* Sets the bitmap id to use for progress. Please note that the bitmap is tiled which
|
||||
* will allow smaller bitmaps to repeat on the display and save memory.
|
||||
*
|
||||
* @param bitmapId The bitmap id.
|
||||
*
|
||||
* @see getBitmap, TiledImage
|
||||
*/
|
||||
virtual void setBitmap(BitmapId bitmapId);
|
||||
|
||||
/**
|
||||
* Gets the bitmap id of the current image.
|
||||
*
|
||||
* @return The image.
|
||||
*
|
||||
* @see setBitmap
|
||||
*/
|
||||
virtual BitmapId getBitmap() const;
|
||||
|
||||
/**
|
||||
* @copydoc Image::setAlpha
|
||||
*/
|
||||
virtual void setAlpha(uint8_t newAlpha);
|
||||
|
||||
virtual void setValue(int value);
|
||||
|
||||
protected:
|
||||
Container container; ///< The container for the image to allow for anchored images
|
||||
TiledImage image; ///< The image
|
||||
bool fixedPosition; ///< true if the image should not move during progress
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_IMAGEPROGRESS_HPP
|
||||
@ -0,0 +1,140 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/progress_indicators/LineProgress.hpp
|
||||
*
|
||||
* Declares the touchgfx::LineProgress class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_LINEPROGRESS_HPP
|
||||
#define TOUCHGFX_LINEPROGRESS_HPP
|
||||
|
||||
#include <touchgfx/containers/progress_indicators/AbstractProgressIndicator.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/canvas/AbstractPainter.hpp>
|
||||
#include <touchgfx/widgets/canvas/CWRUtil.hpp>
|
||||
#include <touchgfx/widgets/canvas/Line.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* Using Line from CanvasWidgetRenderer, progress will be rendered as a line. This means that
|
||||
* the user must create a painter for painting the circle. The line does not need to
|
||||
* horizontal or vertical, but can start at any coordinate and finish at any coordinate.
|
||||
*
|
||||
* @note As LineProgress uses CanvasWidgetRenderer, it is important that a buffer is set up by
|
||||
* calling CanvasWidgetRendere::setBuffer().
|
||||
*/
|
||||
class LineProgress : public AbstractProgressIndicator
|
||||
{
|
||||
public:
|
||||
LineProgress();
|
||||
|
||||
virtual void setProgressIndicatorPosition(int16_t x, int16_t y, int16_t width, int16_t height);
|
||||
|
||||
/**
|
||||
* Sets a painter to be used for drawing the line. This can be any Painter, a simple
|
||||
* single color painter, a bitmap painter or a custom painter.
|
||||
*
|
||||
* @param [in] painter The painter.
|
||||
*/
|
||||
virtual void setPainter(AbstractPainter& painter);
|
||||
|
||||
/**
|
||||
* Sets a starting point for the line.
|
||||
*
|
||||
* @param x The x coordinate of the start point.
|
||||
* @param y The y coordinate of the start point.
|
||||
*
|
||||
* @see setEnd
|
||||
*/
|
||||
virtual void setStart(int x, int y);
|
||||
|
||||
/**
|
||||
* Gets the coordinates of the starting point of the line.
|
||||
*
|
||||
* @param [out] x The x coordinate.
|
||||
* @param [out] y The y coordinate.
|
||||
*/
|
||||
virtual void getStart(int& x, int& y) const;
|
||||
|
||||
/**
|
||||
* Sets the end point for the line. When progress is at 100%, the line will go from the
|
||||
* coordinates set by setStart() to the coordinates set by setEnd()
|
||||
*
|
||||
* @param x The x coordinate of the end point.
|
||||
* @param y The y coordinate of the end point.
|
||||
*
|
||||
* @see setStart
|
||||
*/
|
||||
virtual void setEnd(int x, int y);
|
||||
|
||||
/**
|
||||
* Gets the coordinates of the end point of the line. Beware that this is not the
|
||||
* coordinates of the current progress of the line, but the coordinates when the line is
|
||||
* at 100%.
|
||||
*
|
||||
* @param [out] x The x coordinate.
|
||||
* @param [out] y The y coordinate.
|
||||
*/
|
||||
virtual void getEnd(int& x, int& y) const;
|
||||
|
||||
/**
|
||||
* Sets the line width.
|
||||
*
|
||||
* @param width The width.
|
||||
*
|
||||
* @see Line::setLineWidth
|
||||
*/
|
||||
virtual void setLineWidth(int width);
|
||||
|
||||
/**
|
||||
* Gets the line width.
|
||||
*
|
||||
* @return The line width.
|
||||
*/
|
||||
virtual int getLineWidth() const;
|
||||
|
||||
/**
|
||||
* Sets line ending style.
|
||||
*
|
||||
* @param lineEndingStyle The line ending style.
|
||||
*
|
||||
* @see Line::setLineEndingStyle
|
||||
*/
|
||||
virtual void setLineEndingStyle(Line::LINE_ENDING_STYLE lineEndingStyle);
|
||||
|
||||
/**
|
||||
* Gets line ending style.
|
||||
*
|
||||
* @return The line ending style.
|
||||
*/
|
||||
virtual Line::LINE_ENDING_STYLE getLineEndingStyle() const;
|
||||
|
||||
/**
|
||||
* @copydoc Image::setAlpha
|
||||
*/
|
||||
virtual void setAlpha(uint8_t newAlpha);
|
||||
|
||||
virtual void setValue(int value);
|
||||
|
||||
protected:
|
||||
Line line; ///< The line
|
||||
CWRUtil::Q5 startX; ///< The start x coordinate
|
||||
CWRUtil::Q5 startY; ///< The start y coordinate
|
||||
CWRUtil::Q5 endX; ///< The end x coordinate
|
||||
CWRUtil::Q5 endY; ///< The end y coordinate
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_LINEPROGRESS_HPP
|
||||
@ -0,0 +1,123 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/progress_indicators/TextProgress.hpp
|
||||
*
|
||||
* Declares the touchgfx::TextProgress class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_TEXTPROGRESS_HPP
|
||||
#define TOUCHGFX_TEXTPROGRESS_HPP
|
||||
|
||||
#include <touchgfx/TypedText.hpp>
|
||||
#include <touchgfx/Unicode.hpp>
|
||||
#include <touchgfx/containers/progress_indicators/AbstractProgressIndicator.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
#include <touchgfx/widgets/TextAreaWithWildcard.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A text progress will display progress as a number with a given number of decimals.
|
||||
*
|
||||
* @note The implementation does not use floating point variables to calculate the progress.
|
||||
*/
|
||||
class TextProgress : public AbstractProgressIndicator
|
||||
{
|
||||
public:
|
||||
TextProgress();
|
||||
|
||||
/**
|
||||
* Sets the position and dimensions of the text progress indicator.
|
||||
*
|
||||
* Sets the position and dimensions of the text progress indicator relative to the
|
||||
* background image.
|
||||
*
|
||||
* @param x The x coordinate.
|
||||
* @param y The y coordinate.
|
||||
* @param width The width of the text progress indicator.
|
||||
* @param height The height of the text progress indicator.
|
||||
*/
|
||||
virtual void setProgressIndicatorPosition(int16_t x, int16_t y, int16_t width, int16_t height);
|
||||
|
||||
/**
|
||||
* Sets the typed text. The text should have exactly one wildcard and could for example
|
||||
* look like this: "<progress>\%".
|
||||
*
|
||||
* @param t The TypedText to process.
|
||||
*
|
||||
* @see getTypedText
|
||||
*/
|
||||
virtual void setTypedText(const TypedText& t);
|
||||
|
||||
/**
|
||||
* Gets the typed text.
|
||||
*
|
||||
* @return The typed text.
|
||||
*
|
||||
* @see setTypedText
|
||||
*/
|
||||
virtual const TypedText& getTypedText() const;
|
||||
|
||||
/**
|
||||
* Sets the color of the text in the used text area.
|
||||
*
|
||||
* @param color The color.
|
||||
*
|
||||
* @see getColor, TextArea::setColor
|
||||
*/
|
||||
virtual void setColor(colortype color);
|
||||
|
||||
/**
|
||||
* Gets the color of the text in the used text area.
|
||||
*
|
||||
* @return The color.
|
||||
*/
|
||||
virtual colortype getColor() const;
|
||||
|
||||
/** @copydoc Image::setAlpha */
|
||||
virtual void setAlpha(uint8_t newAlpha);
|
||||
|
||||
/**
|
||||
* Sets the new value for the progress indicator.
|
||||
*
|
||||
* @param value The value.
|
||||
*/
|
||||
virtual void setValue(int value);
|
||||
|
||||
/**
|
||||
* Sets number of decimals when displaying progress.
|
||||
*
|
||||
* @param numberOfDecimals Number of decimals. Only up to two decimals is supported.
|
||||
*
|
||||
* @see getNumberOfDecimals
|
||||
*/
|
||||
virtual void setNumberOfDecimals(uint16_t numberOfDecimals);
|
||||
|
||||
/**
|
||||
* Gets number of decimals.
|
||||
*
|
||||
* @return The number of decimals.
|
||||
*
|
||||
* @see setNumberOfDecimals
|
||||
*/
|
||||
virtual uint16_t getNumberOfDecimals() const;
|
||||
|
||||
protected:
|
||||
TextAreaWithOneWildcard textArea; ///< The text area
|
||||
Unicode::UnicodeChar textBuffer[9]; ///< Room for 100.0000
|
||||
uint16_t decimals; ///< The number of decimals
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_TEXTPROGRESS_HPP
|
||||
@ -0,0 +1,396 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/scrollers/DrawableList.hpp
|
||||
*
|
||||
* Declares the touchgfx::DrawableListItemsInterface (abstract), touchgfx::DrawableListItems
|
||||
* and touchgfx::DrawableList classes.
|
||||
*/
|
||||
#ifndef TOUCHGFX_DRAWABLELIST_HPP
|
||||
#define TOUCHGFX_DRAWABLELIST_HPP
|
||||
|
||||
#include <touchgfx/Callback.hpp>
|
||||
#include <touchgfx/Drawable.hpp>
|
||||
#include <touchgfx/containers/Container.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A drawable list items interface. Used to pass the allocated array of drawable elements to
|
||||
* ScrollList::setDrawables(), ScrollWheel::setDrawables() or
|
||||
* ScrollWheelWithSelectionStyle::setDrawables(). Provides easy access to each element
|
||||
* in the array as well as the size of the array.
|
||||
*
|
||||
* @see ScrollList::setDrawables, ScrollWheel::setDrawables,
|
||||
* ScrollWheelWithSelectionStyle::setDrawables
|
||||
*/
|
||||
class DrawableListItemsInterface
|
||||
{
|
||||
public:
|
||||
/** Finalizes an instance of the DrawableListItemsInterface class. */
|
||||
virtual ~DrawableListItemsInterface()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a drawable at a given index.
|
||||
*
|
||||
* @param index Zero-based index of the drawable.
|
||||
*
|
||||
* @return Null if it fails, else the drawable.
|
||||
*/
|
||||
virtual Drawable* getDrawable(int16_t index) = 0;
|
||||
|
||||
/**
|
||||
* Gets number of drawables.
|
||||
*
|
||||
* @return The number of drawables.
|
||||
*/
|
||||
virtual int16_t getNumberOfDrawables() = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* An array of drawables used by DrawableList. This class is used to ease the setup of
|
||||
* a callback function to get access to a specific drawable in the array.
|
||||
*
|
||||
* Example usage:
|
||||
* @code
|
||||
* static const int NUMBER_OF_DRAWABLES = 5;
|
||||
* DrawableListItems<TextAreaWithOneWildcardContainer, NUMBER_OF_DRAWABLES> menuItems;
|
||||
* @endcode
|
||||
*
|
||||
* @tparam TYPE Type of the drawables. Can be a simple drawable, such as Image or a more
|
||||
* complex container.
|
||||
* @tparam SIZE Size of the array. This is the number of drawables to allocate and should be
|
||||
* all visible drawables on the screen at any given time.
|
||||
*/
|
||||
template <class TYPE, int SIZE>
|
||||
class DrawableListItems : public DrawableListItemsInterface
|
||||
{
|
||||
public:
|
||||
virtual Drawable* getDrawable(int16_t index)
|
||||
{
|
||||
assert(index >= 0 && index < SIZE);
|
||||
return &element[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Array indexer operator.
|
||||
*
|
||||
* @param index Zero-based index of elements to access.
|
||||
*
|
||||
* @return The indexed value.
|
||||
*/
|
||||
TYPE& operator[](int index)
|
||||
{
|
||||
assert(index >= 0 && index < SIZE);
|
||||
return element[index];
|
||||
}
|
||||
|
||||
virtual int16_t getNumberOfDrawables()
|
||||
{
|
||||
return SIZE;
|
||||
}
|
||||
|
||||
TYPE element[SIZE]; ///< The array of drawables
|
||||
};
|
||||
|
||||
/**
|
||||
* A container able to display many items using only a few drawables. This is done by only
|
||||
* having drawables for visible items, and populating these drawables with new content
|
||||
* when each of these become visible.
|
||||
*
|
||||
* This means that all drawables must have an identical structure in some way, for
|
||||
* example an Image or a Container with a button and a text.
|
||||
*/
|
||||
class DrawableList : public Container
|
||||
{
|
||||
public:
|
||||
DrawableList();
|
||||
|
||||
/**
|
||||
* @copydoc Container::setWidth
|
||||
*
|
||||
* @note If the list is vertical, the width is also propagated to all drawables in the list.
|
||||
*/
|
||||
virtual void setWidth(int16_t width);
|
||||
|
||||
/**
|
||||
* @copydoc Container::setHeight
|
||||
*
|
||||
* @note If the list is horizontal, the height is also propagated to all drawables in the list.
|
||||
*/
|
||||
virtual void setHeight(int16_t height);
|
||||
|
||||
/**
|
||||
* Sets a horizontal or vertical layout. If parameter horizontal is set true, all
|
||||
* drawables are arranged side by side. If horizontal is set false, the drawables are
|
||||
* arranged above and below each other (vertically).
|
||||
*
|
||||
* @param horizontal True to align drawables horizontal, false to align drawables
|
||||
* vertically.
|
||||
*
|
||||
* @see ScrollBase::setHorizontal, getHorizontal
|
||||
*
|
||||
* @note Default value is false, i.e. vertical layout.
|
||||
*/
|
||||
virtual void setHorizontal(bool horizontal);
|
||||
|
||||
/**
|
||||
* Gets the orientation of the drawables, previously set using setHorizontal().
|
||||
*
|
||||
* @return True if it horizontal, false if it is vertical.
|
||||
*
|
||||
* @see ScrollBase::getHorizontal, setHorizontal
|
||||
*/
|
||||
virtual bool getHorizontal() const;
|
||||
|
||||
/**
|
||||
* Sets whether the list is circular (infinite) or not. A circular list is a list where
|
||||
* the first drawable re-appears after the last item in the list - and the last item in
|
||||
* the list appears before the first item in the list.
|
||||
*
|
||||
* @param circular True if the list should be circular, false if the list should not be
|
||||
* circular.
|
||||
*
|
||||
* @see ScrollBase::setCircular, getCircular
|
||||
*/
|
||||
virtual void setCircular(bool circular);
|
||||
|
||||
/**
|
||||
* Gets the circular setting, previously set using setCircular().
|
||||
*
|
||||
* @return True if the list is circular (infinite), false if the list is not circular
|
||||
* (finite).
|
||||
*
|
||||
* @see ScrollBase::getCircular, setCircular
|
||||
*/
|
||||
virtual bool getCircular() const;
|
||||
|
||||
/**
|
||||
* Sets drawables size. The drawable is is the size of each drawable in the list in the
|
||||
* set direction of the list (this is enforced by the DrawableList class). The specified
|
||||
* margin is added above and below each item for spacing. The entire size of an item is
|
||||
* thus size + 2 * spacing.
|
||||
*
|
||||
* For a horizontal list each element will be \a drawableSize high and have the same
|
||||
* width as set using setWidth(). For a vertical list each element will be \a
|
||||
* drawableSize wide and have the same height as set using setHeight().
|
||||
*
|
||||
* @param drawableSize The size of the drawable.
|
||||
* @param drawableMargin The margin around drawables (margin before and margin after).
|
||||
*
|
||||
* @see setWidth, setHeight, setHorizontal
|
||||
*/
|
||||
void setDrawableSize(int16_t drawableSize, int16_t drawableMargin);
|
||||
|
||||
/**
|
||||
* Gets size of each item. This equals the drawable size plus the drawable margin as set
|
||||
* in setDrawables(). Equals getDrawableSize() + 2 * getDrawableMargin().
|
||||
*
|
||||
* @return The item size.
|
||||
*
|
||||
* @see setDrawables, setDrawableSize, getDrawableMargin
|
||||
*
|
||||
* @note Not the same as getDrawableSize().
|
||||
*/
|
||||
virtual int16_t getItemSize() const;
|
||||
|
||||
/**
|
||||
* Gets drawable size as set by setDrawables.
|
||||
*
|
||||
* @return The drawable size.
|
||||
*
|
||||
* @see setDrawables
|
||||
*/
|
||||
virtual int16_t getDrawableSize() const;
|
||||
|
||||
/**
|
||||
* Gets drawable margin.
|
||||
*
|
||||
* Gets drawable margin as set by setDrawables.
|
||||
*
|
||||
* @return The drawable margin.
|
||||
*/
|
||||
virtual int16_t getDrawableMargin() const;
|
||||
|
||||
/**
|
||||
* Sets the drawables parameters. These parameters are \li The access class to the array
|
||||
* of drawables \li The offset in the drawableListItems array to start using drawable
|
||||
* and \li Callback to update the contents of a drawable.
|
||||
*
|
||||
* @param [in] drawableListItems Number of drawables allocated.
|
||||
* @param [in] drawableItemIndexOffset The offset of the drawable item.
|
||||
* @param [in] updateDrawableCallback A callback to update the contents of a drawable.
|
||||
*
|
||||
* @see getRequiredNumberOfDrawables
|
||||
*/
|
||||
virtual void setDrawables(DrawableListItemsInterface& drawableListItems,
|
||||
int16_t drawableItemIndexOffset,
|
||||
GenericCallback<DrawableListItemsInterface*, int16_t, int16_t>& updateDrawableCallback);
|
||||
|
||||
/**
|
||||
* Gets number of drawables based on the size of each item and the size of the widget.
|
||||
*
|
||||
* @return The number of drawables.
|
||||
*
|
||||
* @see setDrawables
|
||||
*/
|
||||
int16_t getNumberOfDrawables() const;
|
||||
|
||||
/**
|
||||
* Sets number of items in the list. This forces all drawables to be updated to ensure
|
||||
* that the content is correct.
|
||||
*
|
||||
* @param numberOfItems Number of items.
|
||||
*
|
||||
* @note The DrawableList is refreshed to reflect the change.
|
||||
*/
|
||||
void setNumberOfItems(int16_t numberOfItems);
|
||||
|
||||
/**
|
||||
* Gets number of items in the DrawableList, as previously set using setNumberOfItems().
|
||||
*
|
||||
* @return The number of items.
|
||||
*
|
||||
* @see setNumberOfItems
|
||||
*/
|
||||
int16_t getNumberOfItems() const;
|
||||
|
||||
/**
|
||||
* Gets required number of drawables. After setting up the DrawableList it is possible
|
||||
* to request how many drawables are needed to ensure that the list can always be drawn
|
||||
* properly. If the DrawableList has been setup with fewer Drawables than the required
|
||||
* number of drawables, part of the lower part of the DrawableList will look wrong.
|
||||
*
|
||||
* The number of required drawables depend on the size of the widget and the size of the
|
||||
* drawables and the margin around drawables. If there are fewer drawables than required,
|
||||
* the widget will not display correctly. If there are more drawables than required,
|
||||
* some will be left unused.
|
||||
*
|
||||
* @return The required number of drawables.
|
||||
*
|
||||
* @see setDrawables
|
||||
*/
|
||||
int16_t getRequiredNumberOfDrawables() const;
|
||||
|
||||
/**
|
||||
* Sets virtual coordinate. Does not move to the given coordinate, but places the
|
||||
* drawables and fill correct content into the drawables to give the impression that
|
||||
* everything has been scrolled to the given coordinate.
|
||||
*
|
||||
* Setting a value of 0 means that item 0 is at the start of the DrawableList. Setting a
|
||||
* value of "-getItemSize()" places item 0 outside the start of the DrawableList and
|
||||
* item 1 at the start of it.
|
||||
*
|
||||
* Items that are completely outside of view, will be updated with new content using the
|
||||
* provided callback from setDrawables(). Care is taken to not fill drawables more than
|
||||
* strictly required.
|
||||
*
|
||||
* @param ofs The virtual coordinate.
|
||||
*
|
||||
* @see getOffset, setDrawables
|
||||
*/
|
||||
void setOffset(int32_t ofs);
|
||||
|
||||
/**
|
||||
* Gets offset, as previously set using setOffset().
|
||||
*
|
||||
* @return The virtual offset.
|
||||
*
|
||||
* @see setOffset
|
||||
*/
|
||||
int32_t getOffset() const;
|
||||
|
||||
/**
|
||||
* Gets item stored in a given Drawable.
|
||||
*
|
||||
* @param drawableIndex Zero-based index of the drawable.
|
||||
*
|
||||
* @return The item index.
|
||||
*/
|
||||
int16_t getItemIndex(int16_t drawableIndex) const;
|
||||
|
||||
/**
|
||||
* Gets drawable indices. Useful when the number of items is smaller than the number of
|
||||
* drawables as the same item might be in more than one drawable on the screen (if the
|
||||
* DrawableList is circular). The passed array will be filled with the drawable indices
|
||||
* and the number of indices found is returned.
|
||||
*
|
||||
* @param itemIndex Zero-based index of the item.
|
||||
* @param [out] drawableIndexArray Array where the drawable indices are stored.
|
||||
* @param arraySize Size of drawable array.
|
||||
*
|
||||
* @return The number of drawable indices found.
|
||||
*
|
||||
* @see getItemIndex, setCircular, getDrawableIndex
|
||||
*/
|
||||
int16_t getDrawableIndices(int16_t itemIndex, int16_t* drawableIndexArray, int16_t arraySize) const;
|
||||
|
||||
/**
|
||||
* Gets the drawable index of an item. If the number of items is smaller than the number
|
||||
* of drawables and the DrawableList is circular, the same item can be in more than one
|
||||
* drawable. In that case, calling this function again with the previously returned
|
||||
* index as second parameter, the index of the next drawable containing the item will be
|
||||
* returned.
|
||||
*
|
||||
* @param itemIndex Index of the item.
|
||||
* @param prevDrawableIndex (Optional) Index of the previous drawable. If given, search
|
||||
* starts after this index.
|
||||
*
|
||||
* @return The first drawable index with the given item. Returns -1 if the item is not
|
||||
* in a drawable.
|
||||
*
|
||||
* @see getDrawableIndices
|
||||
*/
|
||||
int16_t getDrawableIndex(int16_t itemIndex, int16_t prevDrawableIndex = -1) const;
|
||||
|
||||
/**
|
||||
* Refresh drawables. Useful to call if the number or items, their size or other
|
||||
* properties have changed.
|
||||
*/
|
||||
void refreshDrawables();
|
||||
|
||||
/**
|
||||
* Item changed.
|
||||
*
|
||||
* Item changed and drawables containing this item must be updated. This function can be
|
||||
* called when an item has changed and needs to be updated on screen. If the given item
|
||||
* is displayed on screen, possible more than once for cyclic lists, each drawable is
|
||||
* request to refresh its content to reflect the new value.
|
||||
*
|
||||
* @param itemIndex Zero-based index of the item.
|
||||
*/
|
||||
void itemChanged(int16_t itemIndex);
|
||||
|
||||
private:
|
||||
bool isHorizontal; ///< True if list is horizontal, false if not
|
||||
bool isCircular; ///< True if list is circular, false if not
|
||||
int32_t offset; ///< The offset of item 0
|
||||
int16_t itemSize; ///< Size of each item (including margin)
|
||||
int16_t itemMargin; ///< The margin around each item (included in itemSize)
|
||||
int16_t numItems; ///< Number of items
|
||||
int16_t numDrawables; ///< Number of drawables
|
||||
int16_t firstItem; ///< The first visible item
|
||||
int16_t firstDrawable; ///< The first visible drawable
|
||||
bool drawablesInitialized; ///< True if all drawables initialized
|
||||
|
||||
int16_t firstDrawableIndex; ///< The offset when accessing DrawableListItems
|
||||
DrawableListItemsInterface* drawableItems; ///< The drawable items
|
||||
GenericCallback<DrawableListItemsInterface*, int16_t, int16_t>* updateDrawable; ///< The update drawable callback
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_DRAWABLELIST_HPP
|
||||
@ -0,0 +1,490 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/scrollers/ScrollBase.hpp
|
||||
*
|
||||
* Declares the touchgfx::ScrollBase class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_SCROLLBASE_HPP
|
||||
#define TOUCHGFX_SCROLLBASE_HPP
|
||||
|
||||
#include <touchgfx/Callback.hpp>
|
||||
#include <touchgfx/EasingEquations.hpp>
|
||||
#include <touchgfx/containers/Container.hpp>
|
||||
#include <touchgfx/containers/scrollers/DrawableList.hpp>
|
||||
#include <touchgfx/events/DragEvent.hpp>
|
||||
#include <touchgfx/events/GestureEvent.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* The ScrollBase class is an abstract class used for Widgets that needs to show (a lot of)
|
||||
* elements in a DrawableList that can be scrolled. Due to memory limitations, this is
|
||||
* implemented by re-using the Drawables in the DrawableList - once an element is moved
|
||||
* off screen, it is filled with new content and moved to the other end and the of the
|
||||
* scrolling list.
|
||||
*
|
||||
* Lists can be horizontal or vertical and the can be circular (infinite scrolling).
|
||||
*
|
||||
* @see ScrollList, ScrollWheel, ScrollWheelWithSelectionStyle
|
||||
* @see ScrollWheelBase, DrawableList
|
||||
*/
|
||||
class ScrollBase : public Container
|
||||
{
|
||||
public:
|
||||
ScrollBase();
|
||||
|
||||
/**
|
||||
* @copydoc Container::setWidth
|
||||
*
|
||||
* @note Also sets the width of the children.
|
||||
*/
|
||||
virtual void setWidth(int16_t width);
|
||||
|
||||
/**
|
||||
* @copydoc Container::setHeight
|
||||
*
|
||||
* @note Also sets the height of the children.
|
||||
*/
|
||||
virtual void setHeight(int16_t height);
|
||||
|
||||
/**
|
||||
* Sets a horizontal or vertical layout. If parameter horizontal is set true, all
|
||||
* drawables are arranged side by side. If horizontal is set false, the drawables are
|
||||
* arranged above and below each other (vertically).
|
||||
*
|
||||
* @param horizontal True to align drawables horizontal, false to align drawables
|
||||
* vertically.
|
||||
*
|
||||
* @see DrawableList::setHorizontal, getHorizontal
|
||||
*
|
||||
* @note Default value is false, i.e. vertical layout.
|
||||
*/
|
||||
virtual void setHorizontal(bool horizontal);
|
||||
|
||||
/**
|
||||
* Gets the orientation of the drawables, previously set using setHorizontal().
|
||||
*
|
||||
* @return True if it horizontal, false if it is vertical.
|
||||
*
|
||||
* @see DrawableList::getHorizontal, setHorizontal
|
||||
*/
|
||||
virtual bool getHorizontal() const;
|
||||
|
||||
/**
|
||||
* Sets whether the list is circular (infinite) or not. A circular list is a list where
|
||||
* the first drawable re-appears after the last item in the list - and the last item in
|
||||
* the list appears before the first item in the list.
|
||||
*
|
||||
* @param circular True if the list should be circular, false if the list should not be
|
||||
* circular.
|
||||
*
|
||||
* @see DrawableList::setCircular, getCircular
|
||||
*/
|
||||
virtual void setCircular(bool circular);
|
||||
|
||||
/**
|
||||
* Gets the circular setting, previously set using setCircular().
|
||||
*
|
||||
* @return True if the list is circular (infinite), false if the list is not circular
|
||||
* (finite).
|
||||
*
|
||||
* @see DrawableList::getCircular, setCircular
|
||||
*/
|
||||
virtual bool getCircular() const;
|
||||
|
||||
/**
|
||||
* Sets drawables size. The drawable is is the size of each drawable in the list in the
|
||||
* set direction of the list (this is enforced by the DrawableList class). The specified
|
||||
* margin is added above and below each item for spacing. The entire size of an item is
|
||||
* thus size + 2 * spacing.
|
||||
*
|
||||
* For a horizontal list each element will be \a drawableSize high and have the same
|
||||
* width as set using setWidth(). For a vertical list each element will be \a
|
||||
* drawableSize wide and have the same height as set using setHeight().
|
||||
*
|
||||
* @param drawableSize The size of the drawable.
|
||||
* @param drawableMargin The margin around drawables (margin before and margin after).
|
||||
*
|
||||
* @see setWidth, setHeight, setHorizontal
|
||||
*/
|
||||
virtual void setDrawableSize(int16_t drawableSize, int16_t drawableMargin);
|
||||
|
||||
/**
|
||||
* Gets drawable size as set through the first parameter in most recent call to
|
||||
* setDrawableSize().
|
||||
*
|
||||
* @return The drawable size.
|
||||
*
|
||||
* @see setDrawableSize
|
||||
*/
|
||||
virtual int16_t getDrawableSize() const;
|
||||
|
||||
/**
|
||||
* Gets drawable margin as set through the second parameter in most recent call to
|
||||
* setDrawableSize().
|
||||
*
|
||||
* @return The drawable margin.
|
||||
*
|
||||
* @see setDrawableSize
|
||||
*/
|
||||
virtual int16_t getDrawableMargin() const;
|
||||
|
||||
/**
|
||||
* Sets number of items in the DrawableList. This forces all drawables to be updated to
|
||||
* ensure that the content is correct. For example a date selector might switch number
|
||||
* of days between 28, 29, 30, and 31 depending on the month. A circular list might show
|
||||
* 27-28-29-30-31 and might need to update this to show 27-28-1-2-3.
|
||||
*
|
||||
* @param numberOfItems Number of items.
|
||||
*
|
||||
* @note The DrawableList is refreshed to reflect the change.
|
||||
*/
|
||||
virtual void setNumberOfItems(int16_t numberOfItems);
|
||||
|
||||
/**
|
||||
* Gets number of items in the DrawableList, as previously set using setNumberOfItems().
|
||||
*
|
||||
* @return The number of items.
|
||||
*
|
||||
* @see setNumberOfItems, DrawableList::getNumberOfItems
|
||||
*/
|
||||
virtual int16_t getNumberOfItems() const;
|
||||
|
||||
/**
|
||||
* Sets easing equation when changing the selected item, for example via swipe or
|
||||
* AnimateTo.
|
||||
*
|
||||
* @param equation The equation.
|
||||
*
|
||||
* @see setAnimationSteps, getAnimationSteps
|
||||
*/
|
||||
void setEasingEquation(EasingEquation equation);
|
||||
|
||||
/**
|
||||
* Sets animation steps (in ticks) when moving to a new selected item. The default value is 30.
|
||||
*
|
||||
* @param steps The animation steps.
|
||||
*
|
||||
* @see setEasingEquation, getAnimationSteps
|
||||
*/
|
||||
void setAnimationSteps(int16_t steps);
|
||||
|
||||
/**
|
||||
* Gets animation steps as set in setAnimationSteps.
|
||||
*
|
||||
* @return The animation steps.
|
||||
*
|
||||
* @see setAnimationSteps, setEasingEquation
|
||||
*/
|
||||
uint16_t getAnimationSteps() const;
|
||||
|
||||
/**
|
||||
* Sets swipe acceleration (times 10). Default value, if not set, is 10, i.e. 1.0.
|
||||
*
|
||||
* @param acceleration The acceleration times 10, so "9" means "0.9" and "75" means "7.5".
|
||||
*
|
||||
* @see getSwipeAcceleration
|
||||
*
|
||||
* @note The reason for multiplying the acceleration by 10 is to avoid introducing floating
|
||||
* point arithmetic.
|
||||
*/
|
||||
void setSwipeAcceleration(uint16_t acceleration);
|
||||
|
||||
/**
|
||||
* Gets swipe acceleration (times 10).
|
||||
*
|
||||
* @return The swipe acceleration.
|
||||
*
|
||||
* @see setSwipeAcceleration
|
||||
*
|
||||
* @note The reason for multiplying the acceleration by 10 is to avoid introducing floating
|
||||
* point arithmetic.
|
||||
*/
|
||||
uint16_t getSwipeAcceleration() const;
|
||||
|
||||
/**
|
||||
* Sets maximum swipe items. Often useful when there are e.g. five visible items on the
|
||||
* screen and a swipe action should at most swipe the next/previous five items into view
|
||||
* to achieve sort of a paging effect.
|
||||
*
|
||||
* @param maxItems The maximum items, 0 means "no limit" (which is also the default).
|
||||
*
|
||||
* @see getMaxSwipeItems
|
||||
*/
|
||||
void setMaxSwipeItems(uint16_t maxItems);
|
||||
|
||||
/**
|
||||
* Gets maximum swipe items as set by setMaxSwipeItems.
|
||||
*
|
||||
* @return The maximum swipe items, 0 means "no limit".
|
||||
*
|
||||
* @see setMaxSwipeItems
|
||||
*/
|
||||
uint16_t getMaxSwipeItems() const;
|
||||
|
||||
/**
|
||||
* Sets drag acceleration times 10, so "10" means "1", "15" means "1.5". 10 makes the
|
||||
* containers follow the finger, higher values makes the containers move faster. This
|
||||
* can often be useful if the list is very long.
|
||||
*
|
||||
* @param acceleration The drag acceleration.
|
||||
*
|
||||
* @see getDragAcceleration
|
||||
*
|
||||
* @note The reason for multiplying the acceleration by 10 is to avoid introducing floating
|
||||
* point arithmetic.
|
||||
*/
|
||||
void setDragAcceleration(uint16_t acceleration);
|
||||
|
||||
/**
|
||||
* Gets drag acceleration (times 10).
|
||||
*
|
||||
* @return The drag acceleration.
|
||||
*
|
||||
* @see setDragAcceleration
|
||||
*
|
||||
* @note The reason for multiplying the acceleration by 10 is to avoid introducing floating
|
||||
* point arithmetic.
|
||||
*/
|
||||
uint16_t getDragAcceleration() const;
|
||||
|
||||
/**
|
||||
* Sets overshoot percentage when dragging a non-circular list. This is the size relative to an
|
||||
* item that can be dragged further than the actual list. Setting this to 50, it is possible to
|
||||
* drag the list to show an empty space half the size of an item. Setting this to 0 prevents
|
||||
* dragging further than the actual elements in the list.
|
||||
*
|
||||
* @param percentage The overshoot percentage.
|
||||
*
|
||||
* @see getOvershootPercentage
|
||||
*/
|
||||
void setOvershootPercentage(uint8_t percentage)
|
||||
{
|
||||
overshootPercentage = percentage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets overshoot percentage, as previously set using setOvershootPercentage.
|
||||
*
|
||||
* @return The overshoot percentage.
|
||||
*
|
||||
* @see setOvershootPercentage
|
||||
*/
|
||||
uint8_t getOvershootPercentage() const
|
||||
{
|
||||
return overshootPercentage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables horizontal scrolling to be passed to the children in the list (in case a child
|
||||
* widget is able to handle drag events). By default, scrolling in either direction is
|
||||
* disabled. This function can be used to explicitly (dis)allow scrolling in the
|
||||
* horizontal direction.
|
||||
*
|
||||
* @param enable If true, horizontal scrolling is enabled. If false (default), scrolling is
|
||||
* disabled.
|
||||
*/
|
||||
void allowHorizontalDrag(bool enable);
|
||||
|
||||
/**
|
||||
* Enables the vertical scroll.
|
||||
*
|
||||
* Enables the vertical scroll to be passed to the children in the list (in case a child
|
||||
* widget is able to handle drag events). By default, scrolling in either direction is
|
||||
* disabled. This function can be used to explicitly (dis)allow scrolling in the
|
||||
* vertical direction.
|
||||
*
|
||||
* @param enable If true, vertical scrolling is enabled. If false (default), scrolling is
|
||||
* disabled.
|
||||
*/
|
||||
void allowVerticalDrag(bool enable);
|
||||
|
||||
/**
|
||||
* Go to a specific item, possibly with animation. The given item index is scrolled into view. If
|
||||
* animationSteps is omitted, the default number of animation steps is used. If
|
||||
* animationSteps is 0 no animation will be used, otherwise the number of animation
|
||||
* steps specified is used.
|
||||
*
|
||||
* @param itemIndex Zero-based index of the item.
|
||||
* @param animationSteps (Optional) The steps to use for the animation. 0 means no animation.
|
||||
* If omitted, default animation steps are used.
|
||||
*
|
||||
* @see setAnimationSteps
|
||||
*/
|
||||
virtual void animateToItem(int16_t itemIndex, int16_t animationSteps = -1);
|
||||
|
||||
/**
|
||||
* Sets Callback which will be called when the selected item is clicked.
|
||||
*
|
||||
* @param [in] callback The callback.
|
||||
*/
|
||||
void setItemSelectedCallback(GenericCallback<int16_t>& callback);
|
||||
|
||||
/**
|
||||
* Callback, called when the set animation ended.
|
||||
*
|
||||
* @param [in] callback The ended callback.
|
||||
*/
|
||||
void setAnimationEndedCallback(GenericCallback<>& callback);
|
||||
|
||||
/**
|
||||
* Set Callback which will be called when a item is pressed.
|
||||
*
|
||||
* @param [in] callback The callback.
|
||||
*/
|
||||
void setItemPressedCallback(GenericCallback<int16_t>& callback);
|
||||
|
||||
/**
|
||||
* Query if an animation is ongoing. This can be good to know if getSelectedItem()
|
||||
* is called, as the result might not be as expected if isAnimating() returns true,
|
||||
* since the display is not showing the selected item in the right place yet.
|
||||
*
|
||||
* @return true if animating, false if not.
|
||||
*/
|
||||
bool isAnimating() const;
|
||||
|
||||
/**
|
||||
* Stops an animation if one is ongoing. Immediately moves to the item which is being
|
||||
* animated to.
|
||||
*/
|
||||
void stopAnimation();
|
||||
|
||||
virtual void handleDragEvent(const DragEvent& event);
|
||||
|
||||
virtual void handleGestureEvent(const GestureEvent& event);
|
||||
|
||||
virtual void handleTickEvent();
|
||||
|
||||
/**
|
||||
* Inform the scroll list that the contents of an item has changed and force all
|
||||
* drawables with the given item index to be updated via the callback provided. This is
|
||||
* important as a circular list with very few items might display the same item more
|
||||
* than once and all these items should be updated.
|
||||
*
|
||||
* @param itemIndex Zero-based index of the changed item.
|
||||
*/
|
||||
virtual void itemChanged(int itemIndex);
|
||||
|
||||
/** Removed all drawables and initializes the content of these items. */
|
||||
virtual void initialize()
|
||||
{
|
||||
list.refreshDrawables();
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Sets display offset of first item.
|
||||
*
|
||||
* @param offset The offset.
|
||||
*/
|
||||
virtual void setOffset(int32_t offset);
|
||||
|
||||
/**
|
||||
* Gets display offset of first item.
|
||||
*
|
||||
* @return The offset.
|
||||
*/
|
||||
virtual int32_t getOffset() const;
|
||||
|
||||
/**
|
||||
* Get the position for an item. The position should ensure that the item is in view as
|
||||
* defined by the semantics of the actual scroll class. If the item is already in view,
|
||||
* the current offset is returned and not the offset of the given item.
|
||||
*
|
||||
* @param itemIndex Zero-based index of the item.
|
||||
*
|
||||
* @return The position for item.
|
||||
*/
|
||||
virtual int32_t getPositionForItem(int16_t itemIndex) = 0;
|
||||
|
||||
/**
|
||||
* Gets normalized offset from a given offset from 0 down to -numItems*itemSize.
|
||||
*
|
||||
* @param offset The offset.
|
||||
*
|
||||
* @return The normalized offset.
|
||||
*/
|
||||
int getNormalizedOffset(int offset) const;
|
||||
|
||||
/**
|
||||
* Keep offset inside limits. Return the new offset that is inside the limits of the
|
||||
* scroll list, with the overShoot value added at both ends of the list.
|
||||
*
|
||||
* @param newOffset The new offset.
|
||||
* @param overShoot The over shoot.
|
||||
*
|
||||
* @return The new offset inside the limits.
|
||||
*/
|
||||
virtual int32_t keepOffsetInsideLimits(int32_t newOffset, int16_t overShoot) const = 0;
|
||||
|
||||
/**
|
||||
* Gets nearest offset aligned to a multiple of itemSize.
|
||||
*
|
||||
* @param offset The offset.
|
||||
*
|
||||
* @return The nearest aligned offset.
|
||||
*/
|
||||
virtual int32_t getNearestAlignedOffset(int32_t offset) const;
|
||||
|
||||
/**
|
||||
* Animate to a new position/offset using the given number of steps.
|
||||
*
|
||||
* @param position The new position.
|
||||
* @param steps (Optional) The steps.
|
||||
*/
|
||||
virtual void animateToPosition(int32_t position, int16_t steps = -1);
|
||||
|
||||
/** Values that represent animation states. */
|
||||
enum AnimationState
|
||||
{
|
||||
NO_ANIMATION, ///< No animation
|
||||
ANIMATING_GESTURE, ///< Animating a gesture
|
||||
ANIMATING_DRAG ///< Animating a drag
|
||||
};
|
||||
|
||||
DrawableList list; ///< The list
|
||||
int16_t numberOfDrawables; ///< Number of drawables
|
||||
int16_t distanceBeforeAlignedItem; ///< The distance before aligned item
|
||||
|
||||
int16_t itemSize; ///< Size of the item (including margin)
|
||||
uint16_t swipeAcceleration; ///< The swipe acceleration x10
|
||||
uint16_t dragAcceleration; ///< The drag acceleration x10
|
||||
uint16_t maxSwipeItems; ///< The maximum swipe items
|
||||
EasingEquation easingEquation; ///< The easing equation used for animation
|
||||
uint16_t defaultAnimationSteps; ///< The animation steps
|
||||
uint8_t overshootPercentage; ///< The overshoot percentage when dragging
|
||||
|
||||
GenericCallback<int16_t>* itemSelectedCallback; ///< The item selected callback
|
||||
GenericCallback<>* itemLockedInCallback; ///< The item locked in callback
|
||||
GenericCallback<>* animationEndedCallback; ///< The animation ended callback
|
||||
GenericCallback<int16_t>* itemPressedCallback; ///< The item pressed callback
|
||||
|
||||
AnimationState currentAnimationState; ///< The current animation state
|
||||
int gestureStep; ///< The current gesture step
|
||||
int gestureStepsTotal; ///< The total gesture steps
|
||||
int gestureStart; ///< The gesture start
|
||||
int gestureEnd; ///< The gesture end
|
||||
|
||||
int16_t xClick; ///< The x coordinate of a click
|
||||
int16_t yClick; ///< The y coordinate of a click
|
||||
int32_t initialSwipeOffset; ///< The initial swipe offset
|
||||
|
||||
bool draggableX; ///< Is the container draggable in the horizontal direction.
|
||||
bool draggableY; ///< Is the container draggable in the vertical direction.
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_SCROLLBASE_HPP
|
||||
@ -0,0 +1,151 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/scrollers/ScrollList.hpp
|
||||
*
|
||||
* Declares the touchgfx::ScrollList class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_SCROLLLIST_HPP
|
||||
#define TOUCHGFX_SCROLLLIST_HPP
|
||||
|
||||
#include <touchgfx/Callback.hpp>
|
||||
#include <touchgfx/containers/scrollers/DrawableList.hpp>
|
||||
#include <touchgfx/containers/scrollers/ScrollBase.hpp>
|
||||
#include <touchgfx/events/ClickEvent.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A simple list of scrolling drawables. Since a long list of drawables only display a few of
|
||||
* items at any one time, the drawables are re-used to preserve resources.
|
||||
*
|
||||
* @see DrawableList
|
||||
*/
|
||||
class ScrollList : public ScrollBase
|
||||
{
|
||||
public:
|
||||
ScrollList();
|
||||
|
||||
virtual void setWidth(int16_t width);
|
||||
|
||||
virtual void setHeight(int16_t height);
|
||||
|
||||
virtual void setDrawableSize(int16_t drawableSize, int16_t drawableMargin);
|
||||
|
||||
/**
|
||||
* Setup a list of drawables and provide a function to call to update a given Drawable
|
||||
* with new contents.
|
||||
*
|
||||
* @param [in] drawableListItems The drawables allocated.
|
||||
* @param [in] updateDrawableCallback A callback to update the contents of a specific
|
||||
* drawable with a specific item.
|
||||
*
|
||||
* @see DrawableList::setDrawables
|
||||
*/
|
||||
virtual void setDrawables(DrawableListItemsInterface& drawableListItems, GenericCallback<DrawableListItemsInterface*, int16_t, int16_t>& updateDrawableCallback);
|
||||
|
||||
/**
|
||||
* Sets window size, i.e. the number of items that should always be visible. The default
|
||||
* value is 1. If three items are visible on the display and window size is set to three,
|
||||
* no part of the screen will be blank (unless the list contains less than three items
|
||||
* and the list is not circular).
|
||||
*
|
||||
* @param items The number of items that should always be visible.
|
||||
*
|
||||
* @note This only applies to non-circular lists.
|
||||
*/
|
||||
void setWindowSize(int16_t items);
|
||||
|
||||
/**
|
||||
* Sets distance offset before and after the "visible" drawables in the ScrollList. This
|
||||
* allows the actual area where widgets are placed to have a little extra area where
|
||||
* parts of drawables can be seen. For example if the ScrollList is 200, each drawable
|
||||
* is 50 and distance before and distance after are 25, then there is room for three
|
||||
* visible drawables inside the ScrollList. When scrolling, part of the scrolled out
|
||||
* drawables can be seen before and after the three drawables. In this case 25/50 = 50%
|
||||
* of a drawable can be seen before and after the three drawables in the ScrollList.
|
||||
*
|
||||
* @param paddingBefore The distance before the first drawable in the ScrollList.
|
||||
* @param paddingAfter The distance after the last drawable in the ScrollList.
|
||||
*
|
||||
* @see getPaddingBefore, getPaddingAfter
|
||||
*/
|
||||
void setPadding(int16_t paddingBefore, int16_t paddingAfter);
|
||||
|
||||
/**
|
||||
* Gets distance before first drawable in ScrollList.
|
||||
*
|
||||
* @return The distance before.
|
||||
*
|
||||
* @see setPadding, getPaddingAfter
|
||||
*/
|
||||
int16_t getPaddingBefore() const;
|
||||
|
||||
/**
|
||||
* Gets distance after last drawable in ScrollList.
|
||||
*
|
||||
* @return The distance after the last drawable in the ScrollList.
|
||||
*
|
||||
* @see setPadding, getPaddingBefore
|
||||
*/
|
||||
int16_t getPaddingAfter() const;
|
||||
|
||||
/**
|
||||
* Set snapping. If snapping is false, the items can flow freely. If snapping is true,
|
||||
* the items will snap into place so an item is always in the "selected" spot.
|
||||
*
|
||||
* @param snap true to snap.
|
||||
*
|
||||
* @see getSnapping
|
||||
*/
|
||||
void setSnapping(bool snap);
|
||||
|
||||
/**
|
||||
* Gets the current snap stetting.
|
||||
*
|
||||
* @return true if snapping is set, false otherwise.
|
||||
*
|
||||
* @see setSnapping
|
||||
*/
|
||||
bool getSnapping() const;
|
||||
|
||||
/**
|
||||
* Gets an item.
|
||||
*
|
||||
* @param drawableIndex Zero-based index of the drawable.
|
||||
*
|
||||
* @return The item.
|
||||
*/
|
||||
int16_t getItem(int16_t drawableIndex)
|
||||
{
|
||||
return list.getItemIndex(drawableIndex);
|
||||
}
|
||||
|
||||
virtual void handleClickEvent(const ClickEvent& event);
|
||||
|
||||
protected:
|
||||
virtual int32_t getPositionForItem(int16_t itemIndex);
|
||||
|
||||
virtual int32_t getNearestAlignedOffset(int32_t offset) const;
|
||||
|
||||
virtual int32_t keepOffsetInsideLimits(int32_t newOffset, int16_t overShoot) const;
|
||||
|
||||
int16_t paddingAfterLastItem; ///< The distance after last item
|
||||
bool snapping; ///< Is snapping enabled?
|
||||
int windowSize; ///< Number of items that should always be visible
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_SCROLLLIST_HPP
|
||||
@ -0,0 +1,54 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/scrollers/ScrollWheel.hpp
|
||||
*
|
||||
* Declares the touchgfx::ScrollWheel class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_SCROLLWHEEL_HPP
|
||||
#define TOUCHGFX_SCROLLWHEEL_HPP
|
||||
|
||||
#include <touchgfx/Callback.hpp>
|
||||
#include <touchgfx/containers/scrollers/DrawableList.hpp>
|
||||
#include <touchgfx/containers/scrollers/ScrollWheelBase.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A scroll wheel is very much like the digit selector on a padlock with numbers. The digits
|
||||
* always snap into place and exactly one number is always the "selected" number. Thus,
|
||||
* a scroll wheel is a list of identically styled drawables which can be scrolled
|
||||
* through. One of the items in the list is the "selected" one, and scrolling through
|
||||
* the list can be done in various ways. The ScrollWheel uses the DrawableList to make
|
||||
* it possible to handle a huge number of items using only a limited number of drawables
|
||||
* by reusing drawables that are no longer in view.
|
||||
*
|
||||
* @see ScrollWheelBase, DrawableList, ScrollWheelWithSelectionStyle
|
||||
*/
|
||||
class ScrollWheel : public ScrollWheelBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Sets the drawables used by the scroll wheel. The drawables are updated through a
|
||||
* callback will put the right data in the drawable.
|
||||
*
|
||||
* @param [in] drawableListItems Number of drawables.
|
||||
* @param [in] updateDrawableCallback The update drawable callback.
|
||||
*/
|
||||
virtual void setDrawables(DrawableListItemsInterface& drawableListItems, GenericCallback<DrawableListItemsInterface*, int16_t, int16_t>& updateDrawableCallback);
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_SCROLLWHEEL_HPP
|
||||
@ -0,0 +1,100 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/scrollers/ScrollWheelBase.hpp
|
||||
*
|
||||
* Declares the touchgfx::ScrollWheelBase class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_SCROLLWHEELBASE_HPP
|
||||
#define TOUCHGFX_SCROLLWHEELBASE_HPP
|
||||
|
||||
#include <touchgfx/Callback.hpp>
|
||||
#include <touchgfx/containers/scrollers/ScrollBase.hpp>
|
||||
#include <touchgfx/events/ClickEvent.hpp>
|
||||
#include <touchgfx/events/DragEvent.hpp>
|
||||
#include <touchgfx/events/GestureEvent.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A base class for a scroll wheel. A scroll wheel is very much like the digit selector on a
|
||||
* padlock with numbers. The digits always snap into place and exactly one number is
|
||||
* always the "selected" number. Using ScrollWheel, all elements look the same, but an
|
||||
* underlying bitmap can help emphasize the "selected" element. The
|
||||
* ScrollWheelWithSelectionStyle can have a completely different style on the "selected"
|
||||
* item - the font can be larger or bold and images can change color - this can help to
|
||||
* give a kind of 3D effect using very few resources.
|
||||
*
|
||||
* @see ScrollWheel, ScrollWheelWithSelectionStyle
|
||||
*/
|
||||
class ScrollWheelBase : public ScrollBase
|
||||
{
|
||||
public:
|
||||
ScrollWheelBase();
|
||||
|
||||
/**
|
||||
* Sets selected item offset, measured in pixels, from the edge of the widget. The
|
||||
* offset is the relative x coordinate if the ScrollWheel is horizontal, otherwise it is
|
||||
* the relative y coordinate. If this value is zero, the selected item is placed at the
|
||||
* very start of the widget.
|
||||
*
|
||||
* @param offset The offset.
|
||||
*
|
||||
* @see getSelectedItemOffset
|
||||
*/
|
||||
virtual void setSelectedItemOffset(int16_t offset);
|
||||
|
||||
/**
|
||||
* Gets offset of selected item measured in pixels relative to the start of the widget.
|
||||
*
|
||||
* @return The selected item offset.
|
||||
*
|
||||
* @see setSelectedItemOffset
|
||||
*/
|
||||
virtual int16_t getSelectedItemOffset() const;
|
||||
|
||||
/**
|
||||
* Gets selected item. If an animation is in progress, the item that is being scrolled
|
||||
* to is returned, not the item that happens to be flying by at the time.
|
||||
*
|
||||
* @return The selected item.
|
||||
*/
|
||||
int getSelectedItem() const;
|
||||
|
||||
virtual int32_t keepOffsetInsideLimits(int32_t newOffset, int16_t overShoot) const;
|
||||
|
||||
virtual void handleClickEvent(const ClickEvent& event);
|
||||
|
||||
virtual void handleDragEvent(const DragEvent& event);
|
||||
|
||||
virtual void handleGestureEvent(const GestureEvent& event);
|
||||
|
||||
/**
|
||||
* Sets Callback which will be called when the ScrollWheel animates to a new item.
|
||||
*
|
||||
* @param [in] callback The callback.
|
||||
*/
|
||||
void setAnimateToCallback(GenericCallback<int16_t>& callback);
|
||||
|
||||
protected:
|
||||
virtual int32_t getPositionForItem(int16_t itemIndex);
|
||||
|
||||
virtual void animateToPosition(int32_t position, int16_t steps = -1);
|
||||
|
||||
GenericCallback<int16_t>* animateToCallback; ///< The animate to callback
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_SCROLLWHEELBASE_HPP
|
||||
@ -0,0 +1,187 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2018(-2023) STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the TouchGFX 4.22.0 distribution.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file in
|
||||
* the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @file touchgfx/containers/scrollers/ScrollWheelWithSelectionStyle.hpp
|
||||
*
|
||||
* Declares the touchgfx::ScrollWheelWithSelectionStyle class.
|
||||
*/
|
||||
#ifndef TOUCHGFX_SCROLLWHEELWITHSELECTIONSTYLE_HPP
|
||||
#define TOUCHGFX_SCROLLWHEELWITHSELECTIONSTYLE_HPP
|
||||
|
||||
#include <touchgfx/Callback.hpp>
|
||||
#include <touchgfx/containers/scrollers/DrawableList.hpp>
|
||||
#include <touchgfx/containers/scrollers/ScrollWheelBase.hpp>
|
||||
#include <touchgfx/hal/Types.hpp>
|
||||
|
||||
namespace touchgfx
|
||||
{
|
||||
/**
|
||||
* A scroll wheel is very much like the digit selector on a padlock with numbers. The digits
|
||||
* always snap into place and exactly one number is always the "selected" number.
|
||||
* Similar to an ordinary ScrollWheel, but with a different style for the selected item
|
||||
* which can thus be bold, have a different color or similar effect to highlight it and
|
||||
* help create a 3D effect using very few resources.
|
||||
*
|
||||
* @see DrawableList, ScrollWheel
|
||||
*/
|
||||
class ScrollWheelWithSelectionStyle : public ScrollWheelBase
|
||||
{
|
||||
public:
|
||||
ScrollWheelWithSelectionStyle();
|
||||
|
||||
virtual void setWidth(int16_t width);
|
||||
|
||||
virtual void setHeight(int16_t height);
|
||||
|
||||
virtual void setHorizontal(bool horizontal);
|
||||
|
||||
virtual void setCircular(bool circular);
|
||||
|
||||
virtual void setNumberOfItems(int16_t numberOfItems);
|
||||
|
||||
virtual void setSelectedItemOffset(int16_t offset);
|
||||
|
||||
/**
|
||||
* Sets selected item extra size to make the size of the area for the center drawables
|
||||
* larger.
|
||||
*
|
||||
* @param extraSizeBefore The extra size before.
|
||||
* @param extraSizeAfter The extra size after.
|
||||
*
|
||||
* @see setSelectedItemOffset
|
||||
*/
|
||||
virtual void setSelectedItemExtraSize(int16_t extraSizeBefore, int16_t extraSizeAfter);
|
||||
|
||||
/**
|
||||
* Gets selected item extra size before.
|
||||
*
|
||||
* @return The selected item extra size before.
|
||||
*
|
||||
* @see setSelectedItemExtraSize
|
||||
*/
|
||||
virtual int16_t getSelectedItemExtraSizeBefore() const;
|
||||
|
||||
/**
|
||||
* Gets selected item extra size after.
|
||||
*
|
||||
* @return The selected item extra size after.
|
||||
*
|
||||
* @see setSelectedItemExtraSize
|
||||
*/
|
||||
virtual int16_t getSelectedItemExtraSizeAfter() const;
|
||||
|
||||
/**
|
||||
* Sets margin around selected item. This like an invisible area added before and after
|
||||
* the selected item (including extra size).
|
||||
*
|
||||
* @param marginBefore The margin before.
|
||||
* @param marginAfter The margin after.
|
||||
*
|
||||
* @see setSelectedItemOffset, setSelectedItemExtraSize
|
||||
*/
|
||||
virtual void setSelectedItemMargin(int16_t marginBefore, int16_t marginAfter);
|
||||
|
||||
/**
|
||||
* Gets selected item margin before.
|
||||
*
|
||||
* @return The selected item margin before.
|
||||
*
|
||||
* @see setSelectedItemMargin
|
||||
*/
|
||||
virtual int16_t getSelectedItemMarginBefore() const;
|
||||
|
||||
/**
|
||||
* Gets selected item margin after.
|
||||
*
|
||||
* @return The selected item margin after.
|
||||
*
|
||||
* @see setSelectedItemMargin
|
||||
*/
|
||||
virtual int16_t getSelectedItemMarginAfter() const;
|
||||
|
||||
/**
|
||||
* Sets the selected item offset. This is the distance from the beginning of the
|
||||
* ScrollWheel measured in pixels. The distance before and after that should also be
|
||||
* drawn using the center drawables - for example to extend area of emphasized elements -
|
||||
* can also be specified. Further, if a gap is needed between the "normal" drawables and
|
||||
* the center drawables - for example to give the illusion that that items disappear
|
||||
* under a graphical element, only to appear in the center.
|
||||
*
|
||||
* This is a combination of setSelectedItemOffset, setSelectedItemExtraSize and
|
||||
* setSelectedItemMargin.
|
||||
*
|
||||
* @param offset The offset of the selected item.
|
||||
* @param extraSizeBefore The extra size before the selected item.
|
||||
* @param extraSizeAfter The extra size after the selected item.
|
||||
* @param marginBefore The margin before the selected item.
|
||||
* @param marginAfter The margin after the selected item.
|
||||
*
|
||||
* @see setSelectedItemOffset, setSelectedItemExtraSize, setSelectedItemMargin
|
||||
*/
|
||||
virtual void setSelectedItemPosition(int16_t offset, int16_t extraSizeBefore, int16_t extraSizeAfter, int16_t marginBefore, int16_t marginAfter);
|
||||
|
||||
/**
|
||||
* @copydoc ScrollWheelBase::setDrawableSize
|
||||
*/
|
||||
virtual void setDrawableSize(int16_t drawableSize, int16_t drawableMargin);
|
||||
|
||||
/**
|
||||
* Setups the widget. Numerous parameters control the position of the widget, the two
|
||||
* scroll lists inside and the values in them.
|
||||
*
|
||||
* @param [in] drawableListItems Number of drawables in outer array.
|
||||
* @param [in] updateDrawableCallback The callback to update a drawable.
|
||||
* @param [in] centerDrawableListItems Number of drawables in center array.
|
||||
* @param [in] updateCenterDrawableCallback The callback to update a center drawable.
|
||||
*/
|
||||
virtual void setDrawables(DrawableListItemsInterface& drawableListItems, GenericCallback<DrawableListItemsInterface*, int16_t, int16_t>& updateDrawableCallback,
|
||||
DrawableListItemsInterface& centerDrawableListItems, GenericCallback<DrawableListItemsInterface*, int16_t, int16_t>& updateCenterDrawableCallback);
|
||||
|
||||
virtual void itemChanged(int itemIndex);
|
||||
|
||||
virtual void initialize()
|
||||
{
|
||||
ScrollWheelBase::initialize();
|
||||
listCenter.refreshDrawables();
|
||||
listAfter.refreshDrawables();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void setOffset(int32_t offset);
|
||||
|
||||
/**
|
||||
* Refresh drawable lists layout. Ensure that the three DrawableLists are places
|
||||
* correctly and setup properly. This is typically done after the
|
||||
* ScrollWheelWithSelectionStyle has been resized or the size of the selected item is
|
||||
* changed.
|
||||
*/
|
||||
void refreshDrawableListsLayout();
|
||||
|
||||
int16_t drawablesInFirstList; ///< List of drawables in firsts
|
||||
DrawableList listCenter; ///< The center list
|
||||
DrawableList listAfter; ///< The list of items after the center
|
||||
int16_t extraSizeBeforeSelectedItem; ///< The distance before selected item
|
||||
int16_t extraSizeAfterSelectedItem; ///< The distance after selected item
|
||||
int16_t marginBeforeSelectedItem; ///< The distance before selected item
|
||||
int16_t marginAfterSelectedItem; ///< The distance after selected item
|
||||
|
||||
DrawableListItemsInterface* drawables; ///< The drawables at the beginning and end of the scroll wheel
|
||||
DrawableListItemsInterface* centerDrawables; ///< The drawables at the center of the scroll wheel
|
||||
|
||||
GenericCallback<DrawableListItemsInterface*, int16_t, int16_t>* originalUpdateDrawableCallback; ///< The original update drawable callback
|
||||
GenericCallback<DrawableListItemsInterface*, int16_t, int16_t>* originalUpdateCenterDrawableCallback; ///< The original update center drawable callback
|
||||
};
|
||||
|
||||
} // namespace touchgfx
|
||||
|
||||
#endif // TOUCHGFX_SCROLLWHEELWITHSELECTIONSTYLE_HPP
|
||||
Reference in New Issue
Block a user