From a33cad448a20791839c240ad1aa1a325019476c3 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Thu, 27 Feb 2014 20:37:08 +0100 Subject: [PATCH] CComponentsItem: add methodes to set width and height via percent value Percent value is related to current screen or parent size --- src/gui/components/cc_base.h | 5 +++++ src/gui/components/cc_item.cpp | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/gui/components/cc_base.h b/src/gui/components/cc_base.h index 5f71048b3..5bb3741ca 100644 --- a/src/gui/components/cc_base.h +++ b/src/gui/components/cc_base.h @@ -296,6 +296,11 @@ class CComponentsItem : public CComponents ///do center item on screen or within a parent form, parameter along_mode assigns direction of centering virtual void setCenterPos(int along_mode = CC_ALONG_X | CC_ALONG_Y); + + ///set item height, parameter as uint8_t, as percent value related to current height of parent form or screen + virtual void setHeightP(const uint8_t& h_percent); + ///set item width, parameter as uint8_t, as percent value related to current width of parent form or screen + virtual void setWidthP(const uint8_t& w_percent); }; #endif diff --git a/src/gui/components/cc_item.cpp b/src/gui/components/cc_item.cpp index fc74d73b0..400560666 100644 --- a/src/gui/components/cc_item.cpp +++ b/src/gui/components/cc_item.cpp @@ -190,3 +190,13 @@ void CComponentsItem::setCenterPos(int along_mode) if (along_mode & CC_ALONG_Y) y = cc_parent ? cc_parent->getHeight() - height/2 : getScreenStartY(height); } + +void CComponentsItem::setHeightP(const uint8_t& h_percent) +{ + height = cc_parent ? h_percent*cc_parent->getWidth()/100 : h_percent*frameBuffer->getScreenWidth()/100; +} + +void CComponentsItem::setWidthP(const uint8_t& w_percent) +{ + width = cc_parent ? w_percent*cc_parent->getHeight()/100 : w_percent*frameBuffer->getScreenHeight()/100; +}