滑动菜单

ScreenView.hpp

#ifndef SCREEN1VIEW_HPP
#define SCREEN1VIEW_HPP

#include <gui/common/FrontendApplication.hpp>
#include <mvp/View.hpp>
#include <gui/screen1_screen/Screen1Presenter.hpp>
#include <touchgfx/widgets/Box.hpp>
#include <touchgfx/containers/scrollers/ScrollWheel.hpp>
#include <gui/containers/CustomContainer1.hpp>
#include <touchgfx/containers/SwipeContainer.hpp>
#include <touchgfx/containers/Container.hpp>
#include <touchgfx/containers/scrollers/ScrollList.hpp>
#include <gui/containers/CustomContainer2.hpp>
#include <touchgfx/widgets/ButtonWithIcon.hpp>
#include <touchgfx/widgets/ButtonWithLabel.hpp>

class Screen1View : public touchgfx::View<Screen1Presenter>
{
public:
	Screen1View();
	virtual ~Screen1View() {};
	virtual void setupScreen();
	virtual void tearDownScreen();

	virtual void scrollWheel1UpdateItem(CustomContainer1& item, int16_t itemIndex);
 	virtual void scrollList1UpdateItem(CustomContainer2& item, int16_t itemIndex);

protected:
	FrontendApplication& application() {
		return *static_cast<FrontendApplication*>(touchgfx::Application::getInstance());
	}
	
    /*
     * Member Declarations
     */
    touchgfx::Box __background;
    touchgfx::Box box1;
    touchgfx::ScrollWheel scrollWheel1;
    touchgfx::DrawableListItems<CustomContainer1, 3> scrollWheel1ListItems;
    touchgfx::SwipeContainer swipeContainer1;
    touchgfx::Container swipeContainer1Page1;
    touchgfx::TextArea textArea2;
    touchgfx::Container swipeContainer1Page2;
    touchgfx::TextArea textArea3;
    touchgfx::Container swipeContainer1Page3;
    touchgfx::ScrollList scrollList1;
    touchgfx::DrawableListItems<CustomContainer2, 3> scrollList1ListItems;

    touchgfx::TextArea textArea4;
    touchgfx::Container swipeContainer1Page4;
    touchgfx::TextArea textArea1;


private:
	touchgfx::Callback<Screen1View, touchgfx::DrawableListItemsInterface*, int16_t, int16_t> updateItemCallback;
	void updateItemCallbackHandler(touchgfx::DrawableListItemsInterface* items, int16_t containerIndex, int16_t itemIndex);
	
	touchgfx::Callback<Screen1View, int16_t> scrollListClickedCallback;
	void scrollListClickHandler(int16_t itemIndex);
};

#endif // SCREEN1VIEW_HPP

 ScreenView.cpp

#include <gui/screen1_screen/Screen1View.hpp>
#include <touchgfx/Color.hpp>
#include "BitmapDatabase.hpp"
#include <texts/TextKeysAndLanguages.hpp>

#include <gui/screen2_screen/Screen2View.hpp>
#include <gui/screen3_screen/Screen3View.hpp>
#include <gui/screen4_screen/Screen4View.hpp>
#include <gui/screen5_screen/Screen5View.hpp>
#include <gui/screen6_screen/Screen6View.hpp>





Screen1View::Screen1View() :
    updateItemCallback(this, &Screen1View::updateItemCallbackHandler) , 
	scrollListClickedCallback(this , &Screen1View::scrollListClickHandler)
{
}
//210 ,105, 30
void Screen1View::setupScreen()
{	 
	__background.setPosition(0, 0, 280, 456);
    __background.setColor(touchgfx::Color::getColorFrom24BitRGB(65, 105 ,225));

    box1.setPosition(0, 0, 280, 153);
    box1.setColor(touchgfx::Color::getColorFrom24BitRGB(210 ,105, 30));

	scrollWheel1.setPosition(0, 0, 280, 153);
    scrollWheel1.setHorizontal(false);
    scrollWheel1.setCircular(true);
    scrollWheel1.setEasingEquation(touchgfx::EasingEquations::bounceEaseIn);
    scrollWheel1.setSwipeAcceleration(10);
    scrollWheel1.setDragAcceleration(10);
    scrollWheel1.setNumberOfItems(5);
    scrollWheel1.setSelectedItemOffset(0);
    scrollWheel1.setDrawableSize(65, 40);
    scrollWheel1.setDrawables(scrollWheel1ListItems, updateItemCallback);
    scrollWheel1.animateToItem(1, 0);

    swipeContainer1.setXY(0, 153);
    swipeContainer1.setSwipeCutoff(50);
    swipeContainer1.setEndSwipeElasticWidth(50);

    swipeContainer1Page1.setWidth(280);
    swipeContainer1Page1.setHeight(303);

    textArea2.setXY(89, 71);
    textArea2.setColor(touchgfx::Color::getColorFrom24BitRGB(0, 0, 0));
    textArea2.setLinespacing(0);
    textArea2.setTypedText(touchgfx::TypedText(T_RESOURCEID_PAGE1));
    swipeContainer1Page1.add(textArea2);
    swipeContainer1.add(swipeContainer1Page1);

    swipeContainer1Page2.setWidth(280);
    swipeContainer1Page2.setHeight(303);

    textArea3.setXY(100, 64);
    textArea3.setColor(touchgfx::Color::getColorFrom24BitRGB(0, 0, 0));
    textArea3.setLinespacing(0);
    textArea3.setTypedText(touchgfx::TypedText(T_RESOURCEID_PAGE2));
    swipeContainer1Page2.add(textArea3);
    swipeContainer1.add(swipeContainer1Page2);

    swipeContainer1Page3.setWidth(280);
    swipeContainer1Page3.setHeight(303);


    scrollList1.setPosition(21, 41, 238, 242);
    scrollList1.setHorizontal(false);
    scrollList1.setCircular(true);
    scrollList1.setEasingEquation(touchgfx::EasingEquations::backEaseOut);
    scrollList1.setSwipeAcceleration(10);
    scrollList1.setDragAcceleration(10);
    scrollList1.setNumberOfItems(5);
    scrollList1.setPadding(0, 0);
    scrollList1.setSnapping(true);
    scrollList1.setDrawableSize(61, 80);
    scrollList1.setDrawables(scrollList1ListItems, updateItemCallback);
	scrollList1.setItemSelectedCallback(scrollListClickedCallback);
	
    swipeContainer1Page3.add(scrollList1);

    textArea4.setXY(60, 7);
    textArea4.setColor(touchgfx::Color::getColorFrom24BitRGB(0, 0, 0));
    textArea4.setLinespacing(0);
    textArea4.setTypedText(touchgfx::TypedText(T_RESOURCEI_PAGE3));
    swipeContainer1Page3.add(textArea4);
    swipeContainer1.add(swipeContainer1Page3);

    swipeContainer1Page4.setWidth(280);
    swipeContainer1Page4.setHeight(303);

    textArea1.setXY(106, 64);
    textArea1.setColor(touchgfx::Color::getColorFrom24BitRGB(0, 0, 0));
    textArea1.setLinespacing(0);
    textArea1.setTypedText(touchgfx::TypedText(T_RESOURCEI_PAGE4));
    swipeContainer1Page4.add(textArea1);
    swipeContainer1.add(swipeContainer1Page4);
    swipeContainer1.setSelectedPage(2);

    add(__background);
    add(box1);
    add(scrollWheel1);
    add(swipeContainer1);
	touchgfx_printf("app start");

}

void Screen1View::tearDownScreen()
{

}

void Screen1View::scrollWheel1UpdateItem(CustomContainer1& item, int16_t itemIndex)
{
	item.scrollWheel1UpdateItem(item, itemIndex);
}

void Screen1View::scrollList1UpdateItem(CustomContainer2& item, int16_t itemIndex)
{
	item.scrollWheel1UpdateItem(item, itemIndex);
}

void Screen1View::updateItemCallbackHandler(touchgfx::DrawableListItemsInterface* items, int16_t containerIndex, int16_t itemIndex)
{
	if (items == &scrollList1ListItems || items == &scrollWheel1ListItems)
	{
		touchgfx_printf(">>>>>>>>>>>>	itemIndex :  %d\n",itemIndex );
	}
	
    if (items == &scrollList1ListItems)
    {
        touchgfx::Drawable* d = items->getDrawable(containerIndex);
        CustomContainer2* cc = (CustomContainer2*)d;
        scrollList1UpdateItem(*cc, itemIndex);
    }
    else if (items == &scrollWheel1ListItems)
    {
        touchgfx::Drawable* d = items->getDrawable(containerIndex);
        CustomContainer1* cc = (CustomContainer1*)d;
        scrollWheel1UpdateItem(*cc, itemIndex);
    }
}


#if 1
void Screen1View::scrollListClickHandler(int16_t itemIndex)
{
	touchgfx_printf("scrollListClickHandler %d\n",itemIndex);

	//application().gotoScreen2ScreenNoTransition();

	switch (itemIndex % 5)
	{
		case 0:
			application().gotoScreen2ScreenNoTransition();
			break;
		case 1:
			application().gotoScreen3ScreenSlideTransitionEast();
			break;
		case 2:
			application().gotoScreen4ScreenCoverTransitionEast();
			break;
		case 3:
			application().gotoScreen5ScreenWipeTransitionEast();
			break;
		case 4:
			application().gotoScreen6ScreenSlideTransitionWest();
			break;
	} 
}


#endif

 item.hpp

#ifndef CUSTOMCONTAINER2_HPP
#define CUSTOMCONTAINER2_HPP

#include <gui_generated/containers/CustomContainer2Base.hpp>

class CustomContainer2 : public CustomContainer2Base
{
public:
    CustomContainer2();
    virtual ~CustomContainer2() {}

    virtual void initialize();

	virtual void scrollWheel1UpdateItem(CustomContainer2& item, int16_t itemIndex);
	virtual void setXY (int16_t x, int16_t y);	
protected:

/*
 * Member Declarations
 */
	touchgfx::Image image1;
	touchgfx::TextArea textArea1;

};

#endif // CUSTOMCONTAINER2_HPP

item.cpp

#include <gui/containers/CustomContainer2.hpp>
#include "BitmapDatabase.hpp"
#include <texts/TextKeysAndLanguages.hpp>
#include <touchgfx/Color.hpp>


TEXTS buttonNameArraylist [5] =
{
	T_RESOURCEID6,
	T_RESOURCEID7,
	T_RESOURCEID8,
	T_RESOURCEID9,
	T_RESOURCEID10
};

uint16_t iconArraylist [5] =
{
	BITMAP_HUAWEI_ID,
	BITMAP_OPPO_ID,		
	BITMAP_XIAOMI_ID,
	BITMAP_YIJIA_ID,
	BITMAP_HONOR_ID
};
	
CustomContainer2::CustomContainer2()
{
    setWidth(280);
    setHeight(65);

    image1.setXY(53, 5);
    image1.setBitmap(touchgfx::Bitmap(BITMAP_HUAWEI_ID));

    textArea1.setPosition(110, 21, 77, 22);
    textArea1.setColor(touchgfx::Color::getColorFrom24BitRGB(255, 255, 255));
    textArea1.setLinespacing(0);
    textArea1.setTypedText(touchgfx::TypedText(T_SINGLEUSEID1));

    add(image1);
    add(textArea1);

}

void CustomContainer2::initialize()
{
    CustomContainer2Base::initialize();
}

void CustomContainer2::scrollWheel1UpdateItem(CustomContainer2& item, int16_t itemIndex)
{
	image1.setBitmap(touchgfx::Bitmap( iconArraylist[itemIndex]));
	textArea1.setTypedText( touchgfx::TypedText (buttonNameArraylist[itemIndex]));
	textArea1.invalidate();
}

void CustomContainer2::setXY (int16_t x, int16_t y)
{
	//touchgfx_printf("x:%d , y:%d \n",x,y);
	
	//y = x + ( (y - 60)*(y - 60)/300) ;
	
	touchgfx::Drawable::setX(x);
	touchgfx::Drawable::setY((y));
}

 

效果图

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值