mirror of
https://github.com/stella-emu/stella.git
synced 2026-10-12 02:23:16 +00:00
EditTextWidget now takes number of characters and lines, rather than raw pixel sizes.
This commit is contained in:
@@ -90,7 +90,7 @@ CartridgeCMWidget::CartridgeCMWidget(
|
||||
// Ram state (combination of several bits in SWCHA)
|
||||
myRAMLabel = new StaticTextWidget(boss, _font, "Ram State");
|
||||
myRAM = new EditTextWidget(boss, _nfont,
|
||||
EditTextWidget::calcWidth(_nfont, " Write-only "));
|
||||
static_cast<int>(string_view(" Write-only ").size()));
|
||||
myRAM->setEditable(false, true);
|
||||
|
||||
reflow();
|
||||
|
||||
@@ -89,18 +89,15 @@ void CartridgeELFStateWidget::initialize()
|
||||
|
||||
// The readouts are as wide as the value they hold, in characters
|
||||
myTimeVcsLabel = new StaticTextWidget(_boss, _font, "Time VCS:");
|
||||
myCurrentCyclesVcs = new EditTextWidget(_boss, _font,
|
||||
16 * _font.getMaxCharWidth());
|
||||
myCurrentCyclesVcs = new EditTextWidget(_boss, _font, 16);
|
||||
myCurrentCyclesVcs->setEditable(false, true);
|
||||
|
||||
myTimeArmLabel = new StaticTextWidget(_boss, _font, "Time ARM:");
|
||||
myCurrentCyclesArm = new EditTextWidget(_boss, _font,
|
||||
16 * _font.getMaxCharWidth());
|
||||
myCurrentCyclesArm = new EditTextWidget(_boss, _font, 16);
|
||||
myCurrentCyclesArm->setEditable(false, true);
|
||||
|
||||
myQueueSizeLabel = new StaticTextWidget(_boss, _font, "Bus queue size:");
|
||||
myQueueSize = new EditTextWidget(_boss, _font,
|
||||
4 * _font.getMaxCharWidth());
|
||||
myQueueSize = new EditTextWidget(_boss, _font, 4);
|
||||
myQueueSize->setEditable(false, true);
|
||||
|
||||
myNextTransaction = new StaticTextWidget(_boss, _font,
|
||||
|
||||
@@ -145,12 +145,12 @@ void CartridgeEnhancedWidget::createPlusROM()
|
||||
myPlusROMLabel = new StaticTextWidget(_boss, _font, "PlusROM:");
|
||||
|
||||
myPlusROMHostLabel = new StaticTextWidget(_boss, _font, "Host");
|
||||
myPlusROMHostWidget = new EditTextWidget(_boss, _font, 1, _lineHeight,
|
||||
myPlusROMHostWidget = new EditTextWidget(_boss, _font, 1,
|
||||
myCart.myPlusROM->getHost());
|
||||
myPlusROMHostWidget->setEditable(false);
|
||||
|
||||
myPlusROMPathLabel = new StaticTextWidget(_boss, _font, "Path");
|
||||
myPlusROMPathWidget = new EditTextWidget(_boss, _font, 1, _lineHeight,
|
||||
myPlusROMPathWidget = new EditTextWidget(_boss, _font, 1,
|
||||
myCart.myPlusROM->getPath());
|
||||
myPlusROMPathWidget->setEditable(false);
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ CpuWidget::CpuWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n
|
||||
: Widget(boss, lfont, 0, 0),
|
||||
CommandSender(boss)
|
||||
{
|
||||
const int fontHeight = lfont.getFontHeight();
|
||||
const std::array<string, 4> labels = { "SP", "A", "X", "Y" };
|
||||
|
||||
// Create every widget; reflow() positions and sizes them for the area the
|
||||
@@ -48,7 +47,7 @@ CpuWidget::CpuWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n
|
||||
addFocusWidget(myPCGrid);
|
||||
|
||||
// Read-only textbox containing the current PC label
|
||||
myPCLabel = new EditTextWidget(boss, nfont, 1, fontHeight + 1, "");
|
||||
myPCLabel = new EditTextWidget(boss, nfont, 1, "");
|
||||
myPCLabel->setEditable(false, true);
|
||||
|
||||
// 1x4 grid with labels for the other CPU registers
|
||||
@@ -74,7 +73,7 @@ CpuWidget::CpuWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n
|
||||
// Labels showing the source of data for the SP/A/X/Y registers
|
||||
for(int i = 0; i < 4; ++i)
|
||||
{
|
||||
myCpuDataSrc[i] = new EditTextWidget(boss, nfont, 1, fontHeight + 1);
|
||||
myCpuDataSrc[i] = new EditTextWidget(boss, nfont, 1);
|
||||
myCpuDataSrc[i]->setToolTip("Source label of last read for " + labels[i] + ".");
|
||||
myCpuDataSrc[i]->setEditable(false, true);
|
||||
}
|
||||
@@ -96,7 +95,7 @@ CpuWidget::CpuWidget(GuiObject* boss, const GUI::Font& lfont, const GUI::Font& n
|
||||
|
||||
// Last write destination address
|
||||
myDestText = new StaticTextWidget(boss, lfont, "Dest");
|
||||
myCpuDataDest = new EditTextWidget(boss, nfont, 1, fontHeight + 1);
|
||||
myCpuDataDest = new EditTextWidget(boss, nfont, 1);
|
||||
myCpuDataDest->setToolTip("Destination label of last write.");
|
||||
myCpuDataDest->setEditable(false, true);
|
||||
// NOLINTEND(cppcoreguidelines-prefer-member-initializer)
|
||||
|
||||
@@ -559,8 +559,7 @@ void DebuggerDialog::addStatusArea()
|
||||
myTiaZoom = new TiaZoomWidget(this, *myNFont);
|
||||
addToFocusList(myTiaZoom->getFocusList());
|
||||
|
||||
myMessageBox = new EditTextWidget(this, *myLFont, 1,
|
||||
myLFont->getLineHeight());
|
||||
myMessageBox = new EditTextWidget(this, *myLFont, 1);
|
||||
// NOLINTEND(cppcoreguidelines-prefer-member-initializer)
|
||||
myMessageBox->setEditable(false, false);
|
||||
myMessageBox->clearFlags(Widget::FLAG_RETAIN_FOCUS);
|
||||
|
||||
@@ -184,7 +184,7 @@ TiaWidget::TiaWidget(GuiObject* boss, const GUI::Font& lfont,
|
||||
myNusizP0->setID(kNusizP0ID);
|
||||
addFocusWidget(myNusizP0);
|
||||
|
||||
myNusizP0Text = new EditTextWidget(boss, nfont, 1, lineHeight);
|
||||
myNusizP0Text = new EditTextWidget(boss, nfont, 1);
|
||||
myNusizP0Text->setEditable(false, true);
|
||||
|
||||
////////////////////////////
|
||||
@@ -251,7 +251,7 @@ TiaWidget::TiaWidget(GuiObject* boss, const GUI::Font& lfont,
|
||||
myNusizP1->setID(kNusizP1ID);
|
||||
addFocusWidget(myNusizP1);
|
||||
|
||||
myNusizP1Text = new EditTextWidget(boss, nfont, 1, lineHeight);
|
||||
myNusizP1Text = new EditTextWidget(boss, nfont, 1);
|
||||
myNusizP1Text->setEditable(false, true);
|
||||
|
||||
////////////////////////////
|
||||
|
||||
@@ -72,7 +72,7 @@ void BrowserDialog::initialize(int max_w, int max_h)
|
||||
|
||||
// Currently selected item
|
||||
_name = new StaticTextWidget(this, _font, "Name");
|
||||
_selected = new EditTextWidget(this, _font, _w, "");
|
||||
_selected = new EditTextWidget(this, _font, 1, "");
|
||||
addFocusWidget(_selected);
|
||||
|
||||
// Directory-navigation buttons
|
||||
|
||||
+3
-2
@@ -539,8 +539,9 @@ MyDialog::MyDialog(OSystem& osystem, DialogContainer& parent, const GUI::Font& f
|
||||
> and nowhere else. So: **a label or a text field the layout does not stretch must
|
||||
> be built with its real, font-derived width** — for a `StaticTextWidget` that
|
||||
> means the short ctor (which derives it from the text), and for an
|
||||
> `EditTextWidget`, `EditTextWidget::calcWidth(font, chars)`. Only the widget's
|
||||
> *position*, and any size the layout will assign, belong in `layout()`.
|
||||
> `EditTextWidget`, its own ctor stated directly in characters (`chars`, not
|
||||
> pixels). Only the widget's *position*, and any size the layout will assign,
|
||||
> belong in `layout()`.
|
||||
>
|
||||
> This misbehaves *intermittently*, which makes it nasty: `refreshFontMetrics()`
|
||||
> recomputes a `StaticTextWidget`'s width from its label, so a clipped label
|
||||
|
||||
@@ -23,19 +23,15 @@
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
EditTextWidget::EditTextWidget(GuiObject* boss, const GUI::Font& font,
|
||||
int w, int h, string_view text)
|
||||
: EditableWidget(boss, font, w, h + 2, text)
|
||||
int chars, int lines, string_view text)
|
||||
: EditableWidget(boss, font, calcWidth(font, chars), calcHeight(font, lines) + 2, text),
|
||||
_lines{std::max(1, lines)}
|
||||
{
|
||||
_flags = Widget::FLAG_ENABLED | Widget::FLAG_CLEARBG
|
||||
| Widget::FLAG_RETAIN_FOCUS | Widget::FLAG_TRACK_MOUSE;
|
||||
|
||||
EditableWidget::startEditMode(); // We're always in edit mode
|
||||
|
||||
// A box taller than one line was built to show several (each further line
|
||||
// adds a font height to the first line's row); remember how many, so a font
|
||||
// change can restore the height
|
||||
_lines = std::max(1, 1 + (h - font.getLineHeight()) / font.getFontHeight());
|
||||
|
||||
if(_font.isLarge())
|
||||
_textOfs = 5;
|
||||
else
|
||||
@@ -44,8 +40,8 @@ EditTextWidget::EditTextWidget(GuiObject* boss, const GUI::Font& font,
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
EditTextWidget::EditTextWidget(GuiObject* boss, const GUI::Font& font,
|
||||
int w, string_view text)
|
||||
: EditTextWidget(boss, font, w, calcHeight(font), text)
|
||||
int chars, string_view text)
|
||||
: EditTextWidget(boss, font, chars, 1, text)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -54,10 +50,10 @@ void EditTextWidget::refreshFontMetrics()
|
||||
{
|
||||
Widget::refreshFontMetrics();
|
||||
|
||||
// Restore the framed height (lineHeight + 2, plus a font height for each line
|
||||
// beyond the first) and the text offset for the live font; the width is
|
||||
// dialog-chosen and re-applied by the owning layout().
|
||||
_h = _font.getLineHeight() + 2 + _font.getFontHeight() * (_lines - 1);
|
||||
// Restore the framed height for the live font and the number of lines I was
|
||||
// built to show; the width is dialog-chosen and re-applied by the owning
|
||||
// layout().
|
||||
_h = calcHeight(_font, _lines) + 2;
|
||||
_textOfs = _font.isLarge() ? 5 : 3;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,16 +25,21 @@
|
||||
class EditTextWidget : public EditableWidget
|
||||
{
|
||||
public:
|
||||
EditTextWidget(GuiObject* boss, const GUI::Font& font,
|
||||
int w, int h, string_view text = "");
|
||||
|
||||
/**
|
||||
A box of a single line: I take my height from the font, so a dialog states
|
||||
only how WIDE a field it needs (which is its own decision — see calcWidth).
|
||||
For a box of several lines, pass calcHeight(font, lines) to the ctor above.
|
||||
A box `chars` characters wide and `lines` lines tall. State the content
|
||||
you need to show — how many characters, how many lines — and I derive my
|
||||
own pixel size from the font; see calcWidth()/calcHeight() if a dialog
|
||||
ever needs that pixel size itself (to line a column up with a sibling
|
||||
that isn't an EditTextWidget, say).
|
||||
*/
|
||||
EditTextWidget(GuiObject* boss, const GUI::Font& font,
|
||||
int w, string_view text = "");
|
||||
int chars, int lines, string_view text = "");
|
||||
|
||||
/**
|
||||
A box of a single line, `chars` characters wide.
|
||||
*/
|
||||
EditTextWidget(GuiObject* boss, const GUI::Font& font,
|
||||
int chars, string_view text = "");
|
||||
|
||||
~EditTextWidget() override = default;
|
||||
|
||||
|
||||
@@ -109,8 +109,7 @@ EventMappingWidget::EventMappingWidget(GuiObject* boss, const GUI::Font& font)
|
||||
|
||||
// Label and (read-only) display for the currently selected event's mapping
|
||||
myActionLabel = new StaticTextWidget(boss, font, "Action");
|
||||
myKeyMapping = new EditTextWidget(boss, font, 1,
|
||||
EditTextWidget::calcHeight(font, ACTION_LINES), "");
|
||||
myKeyMapping = new EditTextWidget(boss, font, 1, ACTION_LINES, "");
|
||||
myKeyMapping->setEditable(false, true);
|
||||
myKeyMapping->clearFlags(Widget::FLAG_RETAIN_FOCUS);
|
||||
// NOLINTEND(cppcoreguidelines-prefer-member-initializer)
|
||||
|
||||
@@ -706,9 +706,6 @@ void GameInfoDialog::addHighScoresTab()
|
||||
{
|
||||
// 4) High Scores properties. The tab's controls are parented to a content
|
||||
// pane; the pane lays them out (see setLayout below) whenever the tab is sized
|
||||
const int awidth = EditTextWidget::calcWidth(_font, 4); // addresses
|
||||
const int swidth = EditTextWidget::calcWidth(_font, HSM::MAX_SPECIAL_NAME); // special
|
||||
const int fwidth = EditTextWidget::calcWidth(_font, 3); // variants
|
||||
WidgetArray wid;
|
||||
VariantList items;
|
||||
|
||||
@@ -731,21 +728,20 @@ void GameInfoDialog::addHighScoresTab()
|
||||
|
||||
// Variations
|
||||
myVariationsLabel = new StaticTextWidget(pane, _font, "Variations");
|
||||
myVariations = new EditTextWidget(pane, _font, fwidth);
|
||||
myVariations = new EditTextWidget(pane, _font, 3);
|
||||
myVariations->setTextFilter(fVars);
|
||||
myVariations->setMaxLen(3);
|
||||
myVariations->setToolTip("Define the number of game variations.");
|
||||
wid.push_back(myVariations);
|
||||
|
||||
myVarAddressLabel = new StaticTextWidget(pane, _font, "Address");
|
||||
myVarAddress = new EditTextWidget(pane, _font, awidth);
|
||||
myVarAddress = new EditTextWidget(pane, _font, 4);
|
||||
myVarAddress->setTextFilter(fAddr);
|
||||
myVarAddress->setMaxLen(4);
|
||||
myVarAddress->setToolTip("Define the address (in hex format) where the variation number "
|
||||
"is stored.");
|
||||
wid.push_back(myVarAddress);
|
||||
myVarAddressVal = new EditTextWidget(pane, _font,
|
||||
EditTextWidget::calcWidth(_font, 3));
|
||||
myVarAddressVal = new EditTextWidget(pane, _font, 3);
|
||||
myVarAddressVal->setEditable(false);
|
||||
|
||||
myVarsBCD = new CheckboxWidget(pane, _font, "BCD", kHiScoresChanged);
|
||||
@@ -785,14 +781,13 @@ void GameInfoDialog::addHighScoresTab()
|
||||
myScoreAddressesLabel = new StaticTextWidget(pane, _font, "Addresses");
|
||||
for(uInt32 a = 0; a < HSM::MAX_SCORE_ADDR; ++a)
|
||||
{
|
||||
myScoreAddress[a] = new EditTextWidget(pane, _font, awidth);
|
||||
myScoreAddress[a] = new EditTextWidget(pane, _font, 4);
|
||||
myScoreAddress[a]->setTextFilter(fAddr);
|
||||
myScoreAddress[a]->setMaxLen(4);
|
||||
myScoreAddress[a]->setToolTip("Define the addresses (in hex format, highest byte first) "
|
||||
"where the score is stored.");
|
||||
wid.push_back(myScoreAddress[a]);
|
||||
myScoreAddressVal[a] = new EditTextWidget(pane, _font,
|
||||
EditTextWidget::calcWidth(_font, 2));
|
||||
myScoreAddressVal[a] = new EditTextWidget(pane, _font, 2);
|
||||
myScoreAddressVal[a]->setEditable(false);
|
||||
}
|
||||
|
||||
@@ -802,7 +797,7 @@ void GameInfoDialog::addHighScoresTab()
|
||||
|
||||
// Special
|
||||
mySpecialLabel = new StaticTextWidget(pane, _font, "Special");
|
||||
mySpecialName = new EditTextWidget(pane, _font, swidth);
|
||||
mySpecialName = new EditTextWidget(pane, _font, HSM::MAX_SPECIAL_NAME);
|
||||
mySpecialName->setTextFilter(fText);
|
||||
mySpecialName->setMaxLen(HSM::MAX_SPECIAL_NAME);
|
||||
mySpecialName->setToolTip("Define a short label (up to 5 chars) for the optional,\ngame's "
|
||||
@@ -810,14 +805,13 @@ void GameInfoDialog::addHighScoresTab()
|
||||
wid.push_back(mySpecialName);
|
||||
|
||||
mySpecialAddressLabel = new StaticTextWidget(pane, _font, "Address");
|
||||
mySpecialAddress = new EditTextWidget(pane, _font, awidth);
|
||||
mySpecialAddress = new EditTextWidget(pane, _font, 4);
|
||||
mySpecialAddress->setTextFilter(fAddr);
|
||||
mySpecialAddress->setMaxLen(4);
|
||||
mySpecialAddress->setToolTip("Define the address (in hex format) where the special "
|
||||
"number is stored.");
|
||||
wid.push_back(mySpecialAddress);
|
||||
mySpecialAddressVal = new EditTextWidget(pane, _font,
|
||||
EditTextWidget::calcWidth(_font, 3));
|
||||
mySpecialAddressVal = new EditTextWidget(pane, _font, 3);
|
||||
mySpecialAddressVal->setEditable(false);
|
||||
|
||||
mySpecialBCD = new CheckboxWidget(pane, _font, "BCD", kHiScoresChanged);
|
||||
|
||||
@@ -175,7 +175,7 @@ HighScoresDialog::HighScoresDialog(OSystem& osystem, DialogContainer& parent,
|
||||
TextAlign::Center);
|
||||
myNameWidgets[r] = new StaticTextWidget(this, _font, "");
|
||||
myEditNameWidgets[r] = new EditTextWidget(this, _font,
|
||||
EditTextWidget::calcWidth(_font, NAME_FIELD));
|
||||
static_cast<int>(NAME_FIELD.size()));
|
||||
myEditNameWidgets[r]->setFlags(EditTextWidget::FLAG_INVISIBLE);
|
||||
myEditNameWidgets[r]->setEnabled(false);
|
||||
myDateWidgets[r] = new StaticTextWidget(this, _font, "");
|
||||
|
||||
@@ -42,7 +42,7 @@ JoystickDialog::JoystickDialog(GuiObject* boss, const GUI::Font& font,
|
||||
// Joystick ID
|
||||
myIDLabel = new StaticTextWidget(this, font, "Controller ID");
|
||||
myJoyText = new EditTextWidget(this, font,
|
||||
EditTextWidget::calcWidth(font, "Unplugged"), "");
|
||||
static_cast<int>(string_view("Unplugged").size()), "");
|
||||
myJoyText->setEditable(false);
|
||||
|
||||
// Port
|
||||
|
||||
@@ -56,13 +56,11 @@ RomAuditDialog::RomAuditDialog(OSystem& osystem, DialogContainer& parent,
|
||||
// Show results of ROM audit
|
||||
myRenamedLabel = new StaticTextWidget(this, font,
|
||||
"ROMs with properties (renamed)");
|
||||
myResults1 = new EditTextWidget(this, font,
|
||||
EditTextWidget::calcWidth(font, 5));
|
||||
myResults1 = new EditTextWidget(this, font, 5);
|
||||
myResults1->setEditable(false, true);
|
||||
mySkippedLabel = new StaticTextWidget(this, font,
|
||||
"ROMs without properties (skipped)");
|
||||
myResults2 = new EditTextWidget(this, font,
|
||||
EditTextWidget::calcWidth(font, 5));
|
||||
myResults2 = new EditTextWidget(this, font, 5);
|
||||
myResults2->setEditable(false, true);
|
||||
|
||||
myWarningLabel = new StaticTextWidget(this, font,
|
||||
|
||||
@@ -610,8 +610,7 @@ void VideoAudioDialog::addBezelTab()
|
||||
wid.push_back(myOpenBrowserButton);
|
||||
|
||||
// The path widens with the tab, but it says how much room a path needs
|
||||
myBezelPath = new EditTextWidget(pane, _font,
|
||||
EditTextWidget::calcWidth(_font, 24));
|
||||
myBezelPath = new EditTextWidget(pane, _font, 24);
|
||||
wid.push_back(myBezelPath);
|
||||
|
||||
myBezelShowWindowed = new CheckboxWidget(pane, _font, "Windowed modes");
|
||||
|
||||
Reference in New Issue
Block a user