TouchGFX之Mixins

Mixin类扩展控件的功能,例如使之能够将移动或透明度值变化制作成动画。 在Move Animator和Fade Animator Mixin的基础上,TouchGFX Designer交互能够生成将移动或透明度值变化制作成动画的代码。 这些Mixin可通过TouchGFX Designer或在用户代码中手动添加到控件。

Move Animator Mixin使控件能够将从当前位置到指定结束位置的移动制作成动画。

Fade Animator Mixin使控件能够将其从当前透明度值至指定结束透明度值的渐隐过程制作成动画。

Click Listener Mixin用回调扩展控件,使控件能够响应触控输入。

Draggable mixin使控件能够通过触控输入被四处拖拽。

下面创建四个box,分别勾选Mixin的四种扩展功能来做这个实验

代码实现点击box3之后,box1线性循环移动,box2线性循环渐隐

cpp 复制代码
#ifndef SCREENVIEW_HPP
#define SCREENVIEW_HPP

#include <gui_generated/screen_screen/screenViewBase.hpp>
#include <gui/screen_screen/screenPresenter.hpp>

class screenView : public screenViewBase
{
public:
    screenView();
    virtual ~screenView() {}
    virtual void setupScreen();
    virtual void tearDownScreen();
		void boxMoveAnimationEndedHandler(const touchgfx::MoveAnimator<Box>& comp);
		void boxClickHandler(const Box& b, const ClickEvent& e);
			
protected:
		Callback <screenView, const touchgfx::MoveAnimator<Box>&> boxMoveAnimationEndedCallback;
		Callback<screenView, const Box&, const ClickEvent&> boxClickedCallback;
private:
		uint8_t tag;
};

#endif // SCREENVIEW_HPP
cpp 复制代码
#include <gui/screen_screen/screenView.hpp>

screenView::screenView() : boxMoveAnimationEndedCallback(this, &screenView::boxMoveAnimationEndedHandler), boxClickedCallback(this, &screenView::boxClickHandler), tag(0)
{

}

void screenView::setupScreen()
{
    screenViewBase::setupScreen();
		box3.setClickAction(boxClickedCallback);
		box1.setMoveAnimationEndedAction(boxMoveAnimationEndedCallback);
}

void screenView::tearDownScreen()
{
    screenViewBase::tearDownScreen();
}

void screenView::boxClickHandler(const Box& b, const ClickEvent& evt)
{
    if (&b == &box3)
    {
			box1.startMoveAnimation(0, 0, 40, EasingEquations::linearEaseNone, EasingEquations::linearEaseNone);
			box2.startFadeAnimation(0, 40, EasingEquations::linearEaseNone);
    }
}

void screenView::boxMoveAnimationEndedHandler(const touchgfx::MoveAnimator<touchgfx::Box>& b)
{
    if (&b == &box1)
    {
			if(tag == 0)
			{
				tag = 1;
        box1.startMoveAnimation(200, 200, 40, EasingEquations::linearEaseNone, EasingEquations::linearEaseNone);
				box2.startFadeAnimation(255, 40, EasingEquations::linearEaseNone);
			}
			else
			{
				tag = 0;
				box1.startMoveAnimation(0, 0, 40, EasingEquations::linearEaseNone, EasingEquations::linearEaseNone);
				box2.startFadeAnimation(0, 40, EasingEquations::linearEaseNone);
			}
    }
}

运行模拟器

相关推荐
振南的单片机世界12 小时前
2MHz/50MHz玄机:GPIO速度档选错,信号直接“烂尾”
arm开发·stm32·单片机·嵌入式硬件
ARM|X86+FPGA工业主板厂家16 小时前
基于ARM+FPGA平台在精密测控领域的应用:ZYNQ千兆以太网高速数据记录仪
arm开发·fpga开发
ARM|X86+FPGA工业主板厂家19 小时前
基于ARM+FPGA平台在精密测控领域的应用:ZYNQ FPGA图像预处理加速系统
arm开发·fpga开发
LCMICRO-133108477462 天前
国产长芯微LPS7118完全pin-pin替代ADP7118,是一款采用 CMOS 技术设计的低噪声、高 PSRR、快速瞬态响应、低压差线性稳压器
arm开发·单片机·嵌入式硬件·fpga开发·硬件工程·线性稳压器·adp7118
LCMICRO-133108477462 天前
国产长芯微LM3042完全P2P替代LT3042,是一款高性能低压差线性稳压器
arm开发·单片机·嵌入式硬件·fpga开发·硬件工程·线性稳压器·lt3042
2401_827501282 天前
Linux系统移植
linux·arm开发·单片机
神罚天下ET3 天前
典型arm位单片机启动流程(从上电到main.c)
c语言·arm开发·单片机
振南的单片机世界3 天前
高优先级“插队”,低优先级让路:中断嵌套的核心规则
arm开发·stm32·单片机·嵌入式硬件
Dlrb12114 天前
ARM---IMX6ULL 的 PWM 模块介绍及其程序的编写
arm开发·arm·pwm·imx6ull·lcd屏幕
byte轻骑兵4 天前
如何定制BlueZ编译:开启/关闭BLE/音频模块的编译参数配置
linux·arm开发·蓝牙·bluez·电脑蓝牙