enhanced PlusROM dialog to show device id

This commit is contained in:
Thomas Jentzsch 2023-02-08 09:50:36 +01:00
parent bbbaced452
commit e9ec5a09d3
3 changed files with 41 additions and 24 deletions

View File

@ -48,24 +48,18 @@ InputTextDialog::InputTextDialog(GuiObject* boss, const GUI::Font& lfont,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
InputTextDialog::InputTextDialog(OSystem& osystem, DialogContainer& parent,
const GUI::Font& font, string_view label,
string_view title, int numInput)
const GUI::Font& font, const StringList& labels,
string_view title, int widthChars)
: Dialog(osystem, parent, font, title),
CommandSender(nullptr)
{
StringList labels;
clear();
labels.emplace_back(label);
initialize(font, font, labels,
static_cast<int>(label.length()) + (numInput ? numInput : 24) + 2,
numInput);
initialize(font, font, labels, widthChars);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void InputTextDialog::initialize(const GUI::Font& lfont, const GUI::Font& nfont,
const StringList& labels, int widthChars,
int numInput)
const StringList& labels, int widthChars)
{
const int lineHeight = Dialog::lineHeight(),
fontHeight = Dialog::fontHeight(),
@ -79,7 +73,9 @@ void InputTextDialog::initialize(const GUI::Font& lfont, const GUI::Font& nfont,
// Calculate real dimensions
_w = HBORDER * 2 + fontWidth * widthChars;
_h = buttonHeight + lineHeight + VGAP + static_cast<int>(labels.size()) * (lineHeight + VGAP) + _th + VBORDER * 2;
_h = buttonHeight + lineHeight + VGAP
+ static_cast<int>(labels.size()) * (lineHeight + VGAP)
+ _th + VBORDER * 2;
// Determine longest label
size_t maxIdx = 0;
@ -105,9 +101,7 @@ void InputTextDialog::initialize(const GUI::Font& lfont, const GUI::Font& nfont,
xpos += lwidth + fontWidth;
auto* w = new EditTextWidget(this, nfont, xpos, ypos,
_w - xpos - HBORDER, lineHeight, "");
if(numInput)
w->setMaxLen(numInput);
_w - xpos - HBORDER, lineHeight);
wid.push_back(w);
myInput.push_back(w);
@ -115,8 +109,7 @@ void InputTextDialog::initialize(const GUI::Font& lfont, const GUI::Font& nfont,
}
xpos = HBORDER; ypos += VGAP;
myMessage = new StaticTextWidget(this, lfont, xpos, ypos, _w - 2 * xpos, fontHeight,
"", TextAlign::Left);
myMessage = new StaticTextWidget(this, lfont, xpos, ypos, _w - 2 * xpos, fontHeight);
myMessage->setTextColor(kTextColorEm);
addToFocusList(wid);
@ -197,6 +190,13 @@ void InputTextDialog::setTextFilter(const EditableWidget::TextFilter& f, int idx
myInput[idx]->setTextFilter(f);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void InputTextDialog::setMaxLen(int len, int idx)
{
myInput[idx]->setMaxLen(len);
myInput[idx]->setWidth((len + 1) * Dialog::fontWidth());
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void InputTextDialog::setToolTip(string_view str, int idx)
{
@ -211,6 +211,12 @@ void InputTextDialog::setFocus(int idx)
Dialog::setFocus(getFocusList()[idx]);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void InputTextDialog::setEditable(bool editable, int idx)
{
myInput[idx]->setEditable(editable);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void InputTextDialog::handleCommand(CommandSender* sender, int cmd,
int data, int id)

View File

@ -35,8 +35,8 @@ class InputTextDialog : public Dialog, public CommandSender
const GUI::Font& nfont, const StringList& labels,
string_view title = "");
InputTextDialog(OSystem& osystem, DialogContainer& parent,
const GUI::Font& font, string_view label, string_view title,
int numInput = 0);
const GUI::Font& font, const StringList& labels,
string_view title, int widthChars);
~InputTextDialog() override = default;
@ -50,17 +50,18 @@ class InputTextDialog : public Dialog, public CommandSender
void setText(string_view str, int idx = 0);
void setTextFilter(const EditableWidget::TextFilter& f, int idx = 0);
void setMaxLen(int len, int idx = 0);
void setToolTip(string_view str, int idx = 0);
void setEmitSignal(int cmd) { myCmd = cmd; }
void setMessage(string_view title);
void setFocus(int idx = 0);
void setEditable(bool editable, int idx = 0);
protected:
void initialize(const GUI::Font& lfont, const GUI::Font& nfont,
const StringList& labels, int widthChars = 39,
int numInput = 0);
const StringList& labels, int widthChars = 39);
void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
/** This dialog uses its own positioning, so we override Dialog::center() */

View File

@ -21,24 +21,34 @@
#include "PlusRomsSetupDialog.hxx"
static constexpr int MAX_NICK_LEN = 16;
static constexpr int ID_LEN = 32;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PlusRomsSetupDialog::PlusRomsSetupDialog(OSystem& osystem, DialogContainer& parent,
const GUI::Font& font)
: InputTextDialog(osystem, parent, font, "Nickname", "PlusROM backends setup", MAX_NICK_LEN)
: InputTextDialog(osystem, parent, font, StringList { "Nickname", "Device-ID" },
"PlusROM backends setup",
static_cast<int>(string("Device-ID").length()) + ID_LEN + 2)
{
const EditableWidget::TextFilter filter = [](char c) {
return isalnum(c) || (c == ' ') || (c == '_') || (c == '.');
};
setTextFilter(filter);
setToolTip("Enter your PlusROM backends nickname here.");
// setup "Nickname":
setTextFilter(filter, 0);
setMaxLen(MAX_NICK_LEN, 0);
setToolTip("Enter your PlusROM backends nickname here.", 0);
// setup "Device-ID":
setMaxLen(ID_LEN, 1);
setEditable(false, 1);
setToolTip("PlusROM Device-ID/hash", 1);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PlusRomsSetupDialog::loadConfig()
{
setText(instance().settings().getString("plusroms.nick"));
setText(instance().settings().getString("plusroms.nick"), 0);
setText(instance().settings().getString("plusroms.fixedid"), 1);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -