GUI: button widget auto size with screen width

This commit is contained in:
Die4Ever 2022-05-23 16:36:56 -05:00 committed by Eugene Sandulenko
parent 8d9dc02374
commit e36d66f0e5
3 changed files with 25 additions and 10 deletions

View File

@ -240,7 +240,7 @@ void LauncherDialog::build() {
new ButtonWidget(this, _title + ".QuitButton", _("~Q~uit"), _("Quit ScummVM"), kQuitCmd);
new ButtonWidget(this, _title + ".AboutButton", _("A~b~out"), _("About ScummVM"), kAboutCmd);
new ButtonWidget(this, _title + ".OptionsButton", _("Global ~O~ptions..."), _("Change global ScummVM options"), kOptionsCmd, 0, _c("Global Opts...", "lowres"));
new ButtonWidget(this, _title + ".OptionsButton", _("Global ~O~ptions..."), _("Change global ScummVM options"), kOptionsCmd, 0, _c("Global ~O~pts...", "lowres"));
// Above the lowest button rows: two more buttons (directly below the list box)
DropdownButtonWidget *addButton =
@ -986,7 +986,7 @@ void LauncherSimple::build() {
// Add edit button
_editButton =
new ButtonWidget(this, "Launcher.EditGameButton", _("~G~ame Options..."), _("Change game options"), kEditGameCmd, 0, _c("Game Opts...", "lowres"));
new ButtonWidget(this, "Launcher.EditGameButton", _("~G~ame Options..."), _("Change game options"), kEditGameCmd, 0, _c("~G~ame Opts...", "lowres"));
// Add list with game titles
_list = new GroupedListWidget(this, "Launcher.GameList", Common::U32String(), kListSearchCmd);

View File

@ -349,10 +349,16 @@ void StaticTextWidget::setFont(ThemeEngine::FontStyle font, Common::Language lan
ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &label, const Common::U32String &tooltip, uint32 cmd, uint8 hotkey, const Common::U32String &lowresLabel)
: StaticTextWidget(boss, x, y, w, h, cleanupHotkey(label), Graphics::kTextAlignCenter, tooltip), CommandSender(boss),
_cmd(cmd), _hotkey(hotkey), _duringPress(false) {
_lowresLabel = lowresLabel;
_lowresLabel = cleanupHotkey(lowresLabel);
if (hotkey == 0)
_hotkey = parseHotkey(label);
if (hotkey == 0) {
_highresHotkey = parseHotkey(label);
_hotkey = _highresHotkey;
_lowresHotkey = parseHotkey(lowresLabel);
} else {
_highresHotkey = hotkey;
_lowresHotkey = hotkey;
}
setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
_type = kButtonWidget;
@ -361,10 +367,16 @@ ButtonWidget::ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const Co
ButtonWidget::ButtonWidget(GuiObject *boss, const Common::String &name, const Common::U32String &label, const Common::U32String &tooltip, uint32 cmd, uint8 hotkey, const Common::U32String &lowresLabel)
: StaticTextWidget(boss, name, cleanupHotkey(label), tooltip), CommandSender(boss),
_cmd(cmd), _hotkey(hotkey), _duringPress(false) {
_lowresLabel = lowresLabel;
_lowresLabel = cleanupHotkey(lowresLabel);
if (hotkey == 0)
_hotkey = parseHotkey(label);
if (hotkey == 0) {
_highresHotkey = parseHotkey(label);
_hotkey = _highresHotkey;
_lowresHotkey = parseHotkey(lowresLabel);
} else {
_highresHotkey = hotkey;
_lowresHotkey = hotkey;
}
setFlags(WIDGET_ENABLED/* | WIDGET_BORDER*/ | WIDGET_CLEARBG);
_type = kButtonWidget;
@ -403,13 +415,14 @@ void ButtonWidget::setLabel(const Common::String &label) {
}
void ButtonWidget::setLowresLabel(const Common::U32String &label) {
_lowresLabel = label;
_lowresLabel = cleanupHotkey(label);
}
const Common::U32String &ButtonWidget::getLabel() {
bool useLowres = false;
if (!_lowresLabel.empty())
useLowres = g_gui.theme()->getStringWidth(_label) > _w;
useLowres = g_system->getOverlayWidth() <= 320;
_hotkey = useLowres ? _lowresHotkey : _highresHotkey;
return useLowres ? _lowresLabel : _label;
}

View File

@ -225,6 +225,8 @@ class ButtonWidget : public StaticTextWidget, public CommandSender {
protected:
uint32 _cmd;
uint8 _hotkey;
uint8 _highresHotkey;
uint8 _lowresHotkey;
Common::U32String _lowresLabel;
public:
ButtonWidget(GuiObject *boss, int x, int y, int w, int h, const Common::U32String &label, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0, uint8 hotkey = 0, const Common::U32String &lowresLabel = Common::U32String());