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

View File

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

View File

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