mirror of https://github.com/stella-emu/stella.git
PopupWidget layout improved
This commit is contained in:
parent
7fcbb8f401
commit
6629393e65
|
@ -26,7 +26,7 @@
|
|||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
ContextMenu::ContextMenu(GuiObject* boss, const GUI::Font& font,
|
||||
const VariantList& items, int cmd)
|
||||
const VariantList& items, int cmd, int width)
|
||||
: Dialog(boss->instance(), boss->parent()),
|
||||
CommandSender(boss),
|
||||
_rowHeight(font.getLineHeight()),
|
||||
|
@ -41,7 +41,8 @@ ContextMenu::ContextMenu(GuiObject* boss, const GUI::Font& font,
|
|||
_font(font),
|
||||
_cmd(cmd),
|
||||
_xorig(0),
|
||||
_yorig(0)
|
||||
_yorig(0),
|
||||
_maxWidth(width)
|
||||
{
|
||||
addItems(items);
|
||||
}
|
||||
|
@ -53,15 +54,15 @@ void ContextMenu::addItems(const VariantList& items)
|
|||
_entries = items;
|
||||
|
||||
// Resize to largest string
|
||||
int maxwidth = 0;
|
||||
int maxwidth = _maxWidth;
|
||||
for(const auto& e: _entries)
|
||||
maxwidth = std::max(maxwidth, _font.getStringWidth(e.first));
|
||||
|
||||
_x = _y = 0;
|
||||
#ifndef FLAT_UI
|
||||
_w = maxwidth + 10;
|
||||
_w = maxwidth + 15;
|
||||
#else
|
||||
_w = maxwidth + 10 + 5;
|
||||
_w = maxwidth + 23;
|
||||
#endif
|
||||
_h = 1; // recalculate this in ::recalc()
|
||||
|
||||
|
@ -553,10 +554,17 @@ void ContextMenu::drawDialog()
|
|||
{
|
||||
// Draw menu border and background
|
||||
s.fillRect(_x+1, _y+1, _w-2, _h-2, kWidColor);
|
||||
#ifndef FLAT_UI
|
||||
s.box(_x, _y, _w, _h, kColor, kShadowColor);
|
||||
|
||||
// Draw the entries, taking scroll buttons into account
|
||||
int x = _x + 2, y = _y + 2, w = _w - 4;
|
||||
#else
|
||||
s.frameRect(_x, _y, _w, _h, kTextColor);
|
||||
|
||||
// Draw the entries, taking scroll buttons into account
|
||||
int x = _x + 1, y = _y + 1, w = _w - 2;
|
||||
#endif
|
||||
|
||||
// Show top scroll area
|
||||
int offset = _selectedOffset;
|
||||
|
|
|
@ -42,7 +42,7 @@ class ContextMenu : public Dialog, public CommandSender
|
|||
|
||||
public:
|
||||
ContextMenu(GuiObject* boss, const GUI::Font& font,
|
||||
const VariantList& items, int cmd = 0);
|
||||
const VariantList& items, int cmd = 0, int width = 0);
|
||||
virtual ~ContextMenu() = default;
|
||||
|
||||
/** Add the given items to the widget. */
|
||||
|
@ -124,6 +124,7 @@ class ContextMenu : public Dialog, public CommandSender
|
|||
int _cmd;
|
||||
|
||||
uInt32 _xorig, _yorig;
|
||||
uInt32 _maxWidth;
|
||||
|
||||
private:
|
||||
// Following constructors and assignment operators not supported
|
||||
|
|
|
@ -59,9 +59,9 @@ PopUpWidget::PopUpWidget(GuiObject* boss, const GUI::Font& font,
|
|||
{
|
||||
_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS;
|
||||
_bgcolor = kDlgColor;
|
||||
_bgcolorhi = kWidColor;
|
||||
_bgcolorhi = kDlgColor; // do not highlight the label
|
||||
_textcolor = kTextColor;
|
||||
_textcolorhi = kTextColor;
|
||||
_textcolorhi = kTextColor; // do not highlight the label
|
||||
|
||||
if(!_label.empty() && _labelWidth == 0)
|
||||
_labelWidth = _font.getStringWidth(_label);
|
||||
|
@ -76,7 +76,7 @@ PopUpWidget::PopUpWidget(GuiObject* boss, const GUI::Font& font,
|
|||
myTextY = (_h - _font.getFontHeight()) / 2;
|
||||
myArrowsY = (_h - 8) / 2;
|
||||
|
||||
myMenu = make_unique<ContextMenu>(this, font, list, cmd);
|
||||
myMenu = make_unique<ContextMenu>(this, font, list, cmd, w);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
@ -230,8 +230,8 @@ void PopUpWidget::drawWidget(bool hilite)
|
|||
s.vLine(x, _y, _y+_h-1, kColor);
|
||||
s.vLine(x + w - 1, _y, _y +_h - 1, kShadowColor);
|
||||
#else
|
||||
s.frameRect(x, _y, w - 16, _h, kColor);
|
||||
s.frameRect(x + w - 17, _y, 17, _h, hilite ? kTextColorHi : kColor);
|
||||
s.frameRect(x, _y, w, _h, kColor);
|
||||
s.frameRect(x + w - 16, _y + 1, 15, _h - 2, hilite ? kTextColorHi : kBGColorLo);
|
||||
#endif // !FLAT_UI
|
||||
|
||||
#ifndef FLAT_UI
|
||||
|
@ -242,12 +242,12 @@ void PopUpWidget::drawWidget(bool hilite)
|
|||
!isEnabled() ? kColor : hilite ? kTextColorHi : kTextColor);
|
||||
#else
|
||||
// Fill the background
|
||||
s.fillRect(x + 1, _y + 1, w - 2 - 16, _h - 2, kWidColor);
|
||||
s.fillRect(x + w - 15 - 1, _y + 1, 15, _h - 2, kBGColorHi);
|
||||
s.fillRect(x + 1, _y + 1, w - 17, _h - 2, kWidColor);
|
||||
s.fillRect(x + w - 15, _y + 2, 13, _h - 4, kBGColorHi);
|
||||
//s.vLine(x + w - 17, _y, _y + _h - 1, kShadowColor);
|
||||
// Draw an arrow pointing down at the right end to signal this is a dropdown/popup
|
||||
s.drawBitmap(down_arrow, x + w - 13, _y + myArrowsY + 1,
|
||||
!isEnabled() ? kCheckColor : kTextColor, 9u, 8u);
|
||||
!isEnabled() ? kColor : kTextColor, 9u, 8u);
|
||||
#endif
|
||||
|
||||
// Draw the selected entry, if any
|
||||
|
|
Loading…
Reference in New Issue