Skip to content

Commit

Permalink
GUI: Automatically extend the width of single column pop-up dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
ccawley2011 authored and sev- committed Dec 25, 2022
1 parent 5f0f7fd commit 9728584
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions gui/widgets/popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,37 +58,36 @@ void PopUpDialog::open() {

// Calculate real popup dimensions
_h = _entries.size() * _lineHeight + 2;
_w = 0;

for (uint i = 0; i < _entries.size(); i++) {
int width = g_gui.getStringWidth(_entries[i]);

if (width > _w)
_w = width;
}


_entriesPerColumn = 1;

// Perform clipping / switch to scrolling mode if we don't fit on the screen
// FIXME - OSystem should send out notification messages when the screen
// resolution changes... we could generalize CommandReceiver and CommandSender.

const int screenW = g_system->getOverlayWidth();
const int screenH = g_system->getOverlayHeight();

// HACK: For now, we do not do scrolling. Instead, we draw the dialog
// in two columns if it's too tall.

if (_h >= screenH) {
const int screenW = g_system->getOverlayWidth();

_twoColumns = true;
_entriesPerColumn = _entries.size() / 2;

if (_entries.size() & 1)
_entriesPerColumn++;

_h = _entriesPerColumn * _lineHeight + 2;
_w = 0;

for (uint i = 0; i < _entries.size(); i++) {
int width = g_gui.getStringWidth(_entries[i]);

if (width > _w)
_w = width;
}

_w = 2 * _w + 10;

if (!(_w & 1))
Expand All @@ -99,15 +98,19 @@ void PopUpDialog::open() {
_y = _boss->getAbsY() - (_selection - _entriesPerColumn) * _lineHeight;
}

if (_w >= screenW)
_w = screenW - 1;
if (_x < 0)
_x = 0;
if (_x + _w >= screenW)
_x = screenW - 1 - _w;
} else
} else {
_twoColumns = false;

_w = MAX<uint16>(_boss->getWidth(), _w + 20);
}

if (_w >= screenW)
_w = screenW - 1;
if (_x < 0)
_x = 0;
if (_x + _w >= screenW)
_x = screenW - 1 - _w;

if (_h >= screenH)
_h = screenH - 1;
if (_y < 0)
Expand Down Expand Up @@ -413,7 +416,7 @@ void PopUpDialog::drawMenuEntry(int entry, bool hilite) {
g_gui.theme()->drawText(
r2,
name, hilite ? ThemeEngine::kStateHighlight : ThemeEngine::kStateEnabled,
alignment, ThemeEngine::kTextInversionNone, pad
alignment, ThemeEngine::kTextInversionNone, pad, false
);
}
}
Expand Down

0 comments on commit 9728584

Please sign in to comment.