Added better color customization support for generic list cells ()

* Added better color customization support for generic list cells
This commit is contained in:
SMJS 2024-06-06 10:03:36 +02:00 committed by GitHub
parent 99958c02c9
commit 9a3a66ff3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 5 deletions
loader
include/Geode/ui
src/ui/nodes

View file

@ -7,6 +7,10 @@
namespace geode {
class GEODE_DLL GenericListCell : public TableViewCell {
protected:
cocos2d::ccColor3B m_primaryColor;
cocos2d::ccColor3B m_secondaryColor;
GLubyte m_opacity;
GenericListCell(char const* name, cocos2d::CCSize size);
void draw() override;
@ -14,7 +18,10 @@ namespace geode {
public:
static GenericListCell* create(char const* key, cocos2d::CCSize size);
void updateBGColor(int index);
virtual void updateBGColor(int index);
void setPrimaryColor(cocos2d::ccColor3B color);
void setSecondaryColor(cocos2d::ccColor3B color);
void setOpacity(GLubyte opacity);
};
/**

View file

@ -7,7 +7,10 @@
using namespace geode::prelude;
GenericListCell::GenericListCell(char const* name, CCSize size) :
TableViewCell(name, size.width, size.height) {}
TableViewCell(name, size.width, size.height),
m_primaryColor(ccc3(0xa1, 0x58, 0x2c)),
m_secondaryColor(ccc3(0xc2, 0x72, 0x3e)),
m_opacity(0xff) {}
void GenericListCell::draw() {
auto size = this->getContentSize();
@ -27,9 +30,9 @@ GenericListCell* GenericListCell::create(char const* key, CCSize size) {
}
void GenericListCell::updateBGColor(int index) {
if (index & 1) m_backgroundLayer->setColor(ccc3(0xc2, 0x72, 0x3e));
else m_backgroundLayer->setColor(ccc3(0xa1, 0x58, 0x2c));
m_backgroundLayer->setOpacity(0xff);
if (index & 1) m_backgroundLayer->setColor(m_secondaryColor);
else m_backgroundLayer->setColor(m_primaryColor);
m_backgroundLayer->setOpacity(m_opacity);
}
void ListView::setupList(float) {
@ -78,3 +81,15 @@ ListView* ListView::create(CCArray* items, float itemHeight, float width, float
CC_SAFE_DELETE(ret);
return nullptr;
}
void GenericListCell::setPrimaryColor(cocos2d::ccColor3B color) {
m_primaryColor = color;
}
void GenericListCell::setSecondaryColor(cocos2d::ccColor3B color) {
m_secondaryColor = color;
}
void GenericListCell::setOpacity(GLubyte opacity) {
m_opacity = opacity;
}