mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-25 16:17:10 +02:00
Cap the width of setting names in SettingDialog to the width of the longest
Setting values are now displayed 10 pixels to the right of setting names, as passed to MenuSetting::draw. This commit also contains the following cleanups: * The height of a row is passed to MenuSetting's draw and touchscreen methods. * MenuSettingRGBA's magic constant (36) to separate the text for a color's four components is now a named constant. * MenuSettingRGBA's color preview squares are now rowHeight - 2 pixels tall, and have a white border surrounded by a black border to help view the color it contains in both light and dark themes. * The rectangle behind the selected setting's name is now drawn by that setting's drawSelected method.
This commit is contained in:
parent
15472a073e
commit
bac622fc39
@ -39,17 +39,21 @@ MenuSetting::~MenuSetting()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuSetting::draw(int y)
|
void MenuSetting::draw(int /*valueX*/, int y, int /*h*/)
|
||||||
{
|
{
|
||||||
gmenu2x->s->write( gmenu2x->font, name, 5, y, Font::HAlignLeft, Font::VAlignTop );
|
gmenu2x->s->write( gmenu2x->font, name, 5, y, Font::HAlignLeft, Font::VAlignTop );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuSetting::handleTS()
|
void MenuSetting::handleTS(int /*valueX*/, int /*y*/, int /*h*/)
|
||||||
{
|
{
|
||||||
buttonBox.handleTS();
|
buttonBox.handleTS();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuSetting::drawSelected(int /*y*/)
|
void MenuSetting::drawSelected(int valueX, int y, int h)
|
||||||
{
|
{
|
||||||
|
// The selection rectangle
|
||||||
|
gmenu2x->s->box(0, y, valueX - 5, h,
|
||||||
|
gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
|
||||||
|
|
||||||
buttonBox.paint(gmenu2x->s, 5);
|
buttonBox.paint(gmenu2x->s, 5);
|
||||||
}
|
}
|
||||||
|
@ -44,13 +44,14 @@ public:
|
|||||||
const std::string &description);
|
const std::string &description);
|
||||||
virtual ~MenuSetting();
|
virtual ~MenuSetting();
|
||||||
|
|
||||||
virtual void draw(int y);
|
virtual void draw(int valueX, int y, int h);
|
||||||
virtual void handleTS();
|
virtual void handleTS(int valueX, int y, int h);
|
||||||
|
|
||||||
virtual bool handleButtonPress(InputManager::Button button) = 0;
|
virtual bool handleButtonPress(InputManager::Button button) = 0;
|
||||||
virtual void drawSelected(int y);
|
virtual void drawSelected(int valueX, int y, int h);
|
||||||
virtual bool edited() = 0;
|
virtual bool edited() = 0;
|
||||||
|
|
||||||
|
const std::string &getName() { return name; }
|
||||||
const std::string &getDescription() { return description; }
|
const std::string &getDescription() { return description; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,10 +65,10 @@ void MenuSettingBool::initButton()
|
|||||||
buttonBox.add(btn);
|
buttonBox.add(btn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuSettingBool::draw(int y)
|
void MenuSettingBool::draw(int valueX, int y, int h)
|
||||||
{
|
{
|
||||||
MenuSetting::draw(y);
|
MenuSetting::draw(valueX, y, h);
|
||||||
gmenu2x->s->write( gmenu2x->font, strvalue, 155, y, Font::HAlignLeft, Font::VAlignTop );
|
gmenu2x->s->write( gmenu2x->font, strvalue, valueX, y, Font::HAlignLeft, Font::VAlignTop );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MenuSettingBool::handleButtonPress(InputManager::Button button)
|
bool MenuSettingBool::handleButtonPress(InputManager::Button button)
|
||||||
|
@ -48,7 +48,7 @@ public:
|
|||||||
int *value);
|
int *value);
|
||||||
virtual ~MenuSettingBool() {}
|
virtual ~MenuSettingBool() {}
|
||||||
|
|
||||||
virtual void draw(int y);
|
virtual void draw(int valueX, int y, int h);
|
||||||
virtual bool handleButtonPress(InputManager::Button button);
|
virtual bool handleButtonPress(InputManager::Button button);
|
||||||
virtual bool edited();
|
virtual bool edited();
|
||||||
|
|
||||||
|
@ -67,10 +67,10 @@ MenuSettingInt::MenuSettingInt(
|
|||||||
buttonBox.add(btn);
|
buttonBox.add(btn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuSettingInt::draw(int y)
|
void MenuSettingInt::draw(int valueX, int y, int h)
|
||||||
{
|
{
|
||||||
MenuSetting::draw(y);
|
MenuSetting::draw(valueX, y, h);
|
||||||
gmenu2x->s->write(gmenu2x->font, strvalue, 155, y, Font::HAlignLeft, Font::VAlignTop);
|
gmenu2x->s->write(gmenu2x->font, strvalue, valueX, y, Font::HAlignLeft, Font::VAlignTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MenuSettingInt::handleButtonPress(InputManager::Button button)
|
bool MenuSettingInt::handleButtonPress(InputManager::Button button)
|
||||||
|
@ -44,7 +44,7 @@ public:
|
|||||||
virtual ~MenuSettingInt() {}
|
virtual ~MenuSettingInt() {}
|
||||||
|
|
||||||
virtual bool handleButtonPress(InputManager::Button button);
|
virtual bool handleButtonPress(InputManager::Button button);
|
||||||
virtual void draw(int);
|
virtual void draw(int valueX, int y, int h);
|
||||||
virtual bool edited();
|
virtual bool edited();
|
||||||
|
|
||||||
virtual void setValue(int value);
|
virtual void setValue(int value);
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
using std::string;
|
using std::string;
|
||||||
using std::stringstream;
|
using std::stringstream;
|
||||||
|
|
||||||
|
constexpr unsigned int COMPONENT_WIDTH = 36;
|
||||||
|
|
||||||
MenuSettingRGBA::MenuSettingRGBA(
|
MenuSettingRGBA::MenuSettingRGBA(
|
||||||
GMenu2X *gmenu2x, Touchscreen &ts_,
|
GMenu2X *gmenu2x, Touchscreen &ts_,
|
||||||
const string &name, const string &description, RGBAColor *value)
|
const string &name, const string &description, RGBAColor *value)
|
||||||
@ -49,28 +51,28 @@ MenuSettingRGBA::MenuSettingRGBA(
|
|||||||
updateButtonBox();
|
updateButtonBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuSettingRGBA::draw(int y) {
|
void MenuSettingRGBA::draw(int valueX, int y, int h) {
|
||||||
this->y = y;
|
MenuSetting::draw(valueX, y, h);
|
||||||
MenuSetting::draw(y);
|
gmenu2x->s->rectangle( valueX, y + 1, h - 2, h - 2, 0,0,0,255 );
|
||||||
gmenu2x->s->rectangle( 153, y+1, 11, 11, 0,0,0,255 );
|
gmenu2x->s->rectangle( valueX + 1, y + 2, h - 4, h - 4, 255,255,255,255 );
|
||||||
gmenu2x->s->box( 154, y+2, 9, 9, value() );
|
gmenu2x->s->box( valueX + 2, y + 3, h - 6, h - 6, value() );
|
||||||
gmenu2x->s->write( gmenu2x->font, "R: "+strR, 169, y, Font::HAlignLeft, Font::VAlignTop );
|
gmenu2x->s->write( gmenu2x->font, "R: "+strR, valueX + h + 3, y, Font::HAlignLeft, Font::VAlignTop );
|
||||||
gmenu2x->s->write( gmenu2x->font, "G: "+strG, 205, y, Font::HAlignLeft, Font::VAlignTop );
|
gmenu2x->s->write( gmenu2x->font, "G: "+strG, valueX + h + 3 + COMPONENT_WIDTH, y, Font::HAlignLeft, Font::VAlignTop );
|
||||||
gmenu2x->s->write( gmenu2x->font, "B: "+strB, 241, y, Font::HAlignLeft, Font::VAlignTop );
|
gmenu2x->s->write( gmenu2x->font, "B: "+strB, valueX + h + 3 + COMPONENT_WIDTH * 2, y, Font::HAlignLeft, Font::VAlignTop );
|
||||||
gmenu2x->s->write( gmenu2x->font, "A: "+strA, 277, y, Font::HAlignLeft, Font::VAlignTop );
|
gmenu2x->s->write( gmenu2x->font, "A: "+strA, valueX + h + 3 + COMPONENT_WIDTH * 3, y, Font::HAlignLeft, Font::VAlignTop );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuSettingRGBA::handleTS() {
|
void MenuSettingRGBA::handleTS(int valueX, int y, int h) {
|
||||||
if (ts.pressed()) {
|
if (ts.pressed()) {
|
||||||
for (int i=0; i<4; i++) {
|
for (int i=0; i<4; i++) {
|
||||||
if (i!=selPart && ts.inRect(166+i*36,y,36,14)) {
|
if (i!=selPart && ts.inRect(valueX + h + i * COMPONENT_WIDTH,y,COMPONENT_WIDTH,h)) {
|
||||||
selPart = i;
|
selPart = i;
|
||||||
i = 4;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuSetting::handleTS();
|
MenuSetting::handleTS(valueX, y, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MenuSettingRGBA::handleButtonPress(InputManager::Button button)
|
bool MenuSettingRGBA::handleButtonPress(InputManager::Button button)
|
||||||
@ -199,12 +201,12 @@ unsigned short MenuSettingRGBA::getSelPart()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuSettingRGBA::drawSelected(int y)
|
void MenuSettingRGBA::drawSelected(int valueX, int y, int h)
|
||||||
{
|
{
|
||||||
int x = 166+selPart*36;
|
int x = valueX + selPart * COMPONENT_WIDTH;
|
||||||
gmenu2x->s->box( x, y, 36, 14, gmenu2x->skinConfColors[COLOR_SELECTION_BG] );
|
gmenu2x->s->box( x + h, y, COMPONENT_WIDTH, h, gmenu2x->skinConfColors[COLOR_SELECTION_BG] );
|
||||||
|
|
||||||
MenuSetting::drawSelected(y);
|
MenuSetting::drawSelected(valueX, y, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MenuSettingRGBA::edited()
|
bool MenuSettingRGBA::edited()
|
||||||
|
@ -32,7 +32,6 @@ class MenuSettingRGBA : public MenuSetting {
|
|||||||
private:
|
private:
|
||||||
Touchscreen &ts;
|
Touchscreen &ts;
|
||||||
unsigned short selPart;
|
unsigned short selPart;
|
||||||
int y;
|
|
||||||
std::string strR, strG, strB, strA;
|
std::string strR, strG, strB, strA;
|
||||||
RGBAColor originalValue;
|
RGBAColor originalValue;
|
||||||
RGBAColor *_value;
|
RGBAColor *_value;
|
||||||
@ -53,10 +52,10 @@ public:
|
|||||||
RGBAColor *value);
|
RGBAColor *value);
|
||||||
virtual ~MenuSettingRGBA() {};
|
virtual ~MenuSettingRGBA() {};
|
||||||
|
|
||||||
virtual void draw(int y);
|
virtual void draw(int valueX, int y, int h);
|
||||||
virtual void handleTS();
|
virtual void handleTS(int valueX, int y, int h);
|
||||||
virtual bool handleButtonPress(InputManager::Button button);
|
virtual bool handleButtonPress(InputManager::Button button);
|
||||||
virtual void drawSelected(int y);
|
virtual void drawSelected(int valueX, int y, int h);
|
||||||
virtual bool edited();
|
virtual bool edited();
|
||||||
|
|
||||||
void setSelPart(unsigned short value);
|
void setSelPart(unsigned short value);
|
||||||
|
@ -37,10 +37,10 @@ MenuSettingStringBase::~MenuSettingStringBase()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuSettingStringBase::draw(int y)
|
void MenuSettingStringBase::draw(int valueX, int y, int h)
|
||||||
{
|
{
|
||||||
MenuSetting::draw(y);
|
MenuSetting::draw(valueX, y, h);
|
||||||
gmenu2x->s->write(gmenu2x->font, value(), 155, y,
|
gmenu2x->s->write(gmenu2x->font, value(), valueX, y,
|
||||||
Font::HAlignLeft, Font::VAlignTop);
|
Font::HAlignLeft, Font::VAlignTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public:
|
|||||||
const std::string &description, std::string *value);
|
const std::string &description, std::string *value);
|
||||||
virtual ~MenuSettingStringBase();
|
virtual ~MenuSettingStringBase();
|
||||||
|
|
||||||
virtual void draw(int y);
|
virtual void draw(int valueX, int y, int h);
|
||||||
virtual bool handleButtonPress(InputManager::Button button);
|
virtual bool handleButtonPress(InputManager::Button button);
|
||||||
virtual bool edited();
|
virtual bool edited();
|
||||||
|
|
||||||
|
@ -72,6 +72,11 @@ bool SettingsDialog::exec() {
|
|||||||
uint rowHeight = gmenu2x->font->getLineSpacing() + 1; // gp2x=15+1 / pandora=19+1
|
uint rowHeight = gmenu2x->font->getLineSpacing() + 1; // gp2x=15+1 / pandora=19+1
|
||||||
uint numRows = (gmenu2x->resY - topBarHeight - 20) / rowHeight;
|
uint numRows = (gmenu2x->resY - topBarHeight - 20) / rowHeight;
|
||||||
|
|
||||||
|
uint maxNameWidth = 0;
|
||||||
|
for (auto it = voices.begin(); it != voices.end(); it++) {
|
||||||
|
maxNameWidth = max(maxNameWidth, (uint) gmenu2x->font->getTextWidth((*it)->getName()));
|
||||||
|
}
|
||||||
|
|
||||||
while (!close) {
|
while (!close) {
|
||||||
if (ts.available()) ts.poll();
|
if (ts.available()) ts.poll();
|
||||||
|
|
||||||
@ -89,19 +94,10 @@ bool SettingsDialog::exec() {
|
|||||||
|
|
||||||
//selection
|
//selection
|
||||||
uint iY = topBarHeight + 2 + (sel - firstElement) * rowHeight;
|
uint iY = topBarHeight + 2 + (sel - firstElement) * rowHeight;
|
||||||
gmenu2x->s->setClipRect(clipRect);
|
|
||||||
if (sel<voices.size()) {
|
|
||||||
gmenu2x->s->box(
|
|
||||||
1, iY, 148, rowHeight - 2,
|
|
||||||
gmenu2x->skinConfColors[COLOR_SELECTION_BG]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
gmenu2x->s->clearClipRect();
|
|
||||||
|
|
||||||
//selected option
|
//selected option
|
||||||
voices[sel]->drawSelected(iY);
|
voices[sel]->drawSelected(maxNameWidth + 15, iY, rowHeight);
|
||||||
|
|
||||||
gmenu2x->s->setClipRect(clipRect);
|
|
||||||
if (ts_pressed && !ts.pressed()) {
|
if (ts_pressed && !ts.pressed()) {
|
||||||
ts_pressed = false;
|
ts_pressed = false;
|
||||||
}
|
}
|
||||||
@ -110,7 +106,7 @@ bool SettingsDialog::exec() {
|
|||||||
}
|
}
|
||||||
for (i=firstElement; i<voices.size() && i<firstElement+numRows; i++) {
|
for (i=firstElement; i<voices.size() && i<firstElement+numRows; i++) {
|
||||||
iY = i-firstElement;
|
iY = i-firstElement;
|
||||||
voices[i]->draw(iY * rowHeight + topBarHeight + 2);
|
voices[i]->draw(maxNameWidth + 15, iY * rowHeight + topBarHeight + 2, rowHeight);
|
||||||
if (ts.available() && ts.pressed() && ts.inRect(
|
if (ts.available() && ts.pressed() && ts.inRect(
|
||||||
touchRect.x, touchRect.y + (iY * rowHeight),
|
touchRect.x, touchRect.y + (iY * rowHeight),
|
||||||
touchRect.w, rowHeight
|
touchRect.w, rowHeight
|
||||||
@ -119,7 +115,6 @@ bool SettingsDialog::exec() {
|
|||||||
sel = i;
|
sel = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gmenu2x->s->clearClipRect();
|
|
||||||
|
|
||||||
gmenu2x->drawScrollBar(numRows, voices.size(), firstElement);
|
gmenu2x->drawScrollBar(numRows, voices.size(), firstElement);
|
||||||
|
|
||||||
@ -127,7 +122,7 @@ bool SettingsDialog::exec() {
|
|||||||
writeSubTitle(voices[sel]->getDescription());
|
writeSubTitle(voices[sel]->getDescription());
|
||||||
|
|
||||||
gmenu2x->s->flip();
|
gmenu2x->s->flip();
|
||||||
voices[sel]->handleTS();
|
voices[sel]->handleTS(maxNameWidth + 15, iY, rowHeight);
|
||||||
|
|
||||||
InputManager::Button button = inputMgr.waitForPressedButton();
|
InputManager::Button button = inputMgr.waitForPressedButton();
|
||||||
if (!voices[sel]->handleButtonPress(button)) {
|
if (!voices[sel]->handleButtonPress(button)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user