Improved layout of the Alert Panels

Instead of relying on static pixel values for position and size of
the widgets, the alert panels now scale their widgets based on the
selected system font size.
This commit is contained in:
Tim Taenny authored and Carlos R. Mafra committed 2019-06-12 23:42:27 +01:00
1 parent b185d46286
commit 26bb94a8e7
2 files changed
+46 -22

No files matched your search

+33 -15
View File
@@ -92,6 +92,8 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow * owner,
int dw = 0, aw = 0, ow = 0, w;
WMBox *hbox;
WMPixmap *icon;
int fw, fh;
int pwidth, pheight;
panel = wmalloc(sizeof(WMAlertPanel));
@@ -101,9 +103,22 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow * owner,
panel->win = WMCreateWindowWithStyle(scrPtr, "alertPanel", WMTitledWindowMask);
}
/* calculate and set the panel's size */
WMGetScaleBaseFromSystemFont(scrPtr, &fw, &fh);
pwidth = ScaleX(400);
pheight = ScaleY(5) /* upper margin */
+ 64 /* icon size */
+ ScaleY(5) /* space between icon and divider line */
+ 2 /* divider line */
+ ScaleY(5); /* space between divider line and message */
if (msg)
pheight += WMFontHeight(scrPtr->normalFont) * 4 + ScaleY(5);
pheight += ScaleY(44);
WMResizeWidget(panel->win, pwidth, pheight);
WMSetWindowInitialPosition(panel->win,
(scrPtr->rootView->size.width - WMWidgetWidth(panel->win)) / 2,
(scrPtr->rootView->size.height - WMWidgetHeight(panel->win)) / 2);
(scrPtr->rootView->size.width - pwidth) / 2,
(scrPtr->rootView->size.height - pheight) / 2);
WMSetWindowTitle(panel->win, "");
@@ -113,10 +128,10 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow * owner,
WMMapWidget(panel->vbox);
hbox = WMCreateBox(panel->vbox);
WMSetBoxBorderWidth(hbox, 5);
WMSetBoxBorderWidth(hbox, ScaleX(5));
WMSetBoxHorizontal(hbox, True);
WMMapWidget(hbox);
WMAddBoxSubview(panel->vbox, WMWidgetView(hbox), False, True, 74, 0, 5);
WMAddBoxSubview(panel->vbox, WMWidgetView(hbox), False, True, 64 + 2 * ScaleY(5), 0, ScaleY(5));
panel->iLbl = WMCreateLabel(hbox);
WMSetLabelImagePosition(panel->iLbl, WIPImageOnly);
@@ -149,7 +164,7 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow * owner,
panel->line = WMCreateFrame(panel->win);
WMMapWidget(panel->line);
WMAddBoxSubview(panel->vbox, WMWidgetView(panel->line), False, True, 2, 2, 5);
WMAddBoxSubview(panel->vbox, WMWidgetView(panel->line), False, True, 2, 2, ScaleY(5));
WMSetFrameRelief(panel->line, WRGroove);
if (msg) {
@@ -157,16 +172,16 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow * owner,
WMSetLabelWraps(panel->mLbl, True);
WMMapWidget(panel->mLbl);
WMAddBoxSubview(panel->vbox, WMWidgetView(panel->mLbl), True, True,
WMFontHeight(scrPtr->normalFont) * 4, 0, 5);
WMFontHeight(scrPtr->normalFont) * 4, 0, ScaleY(5));
WMSetLabelText(panel->mLbl, msg);
WMSetLabelTextAlignment(panel->mLbl, WACenter);
}
panel->hbox = WMCreateBox(panel->vbox);
WMSetBoxBorderWidth(panel->hbox, 10);
WMSetBoxBorderWidth(panel->hbox, ScaleX(10));
WMSetBoxHorizontal(panel->hbox, True);
WMMapWidget(panel->hbox);
WMAddBoxSubview(panel->vbox, WMWidgetView(panel->hbox), False, True, 44, 0, 0);
WMAddBoxSubview(panel->vbox, WMWidgetView(panel->hbox), False, True, ScaleY(44), 0, 0);
/* create buttons */
if (otherButton)
@@ -180,19 +195,19 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow * owner,
dw = dw + (scrPtr->buttonArrow ? scrPtr->buttonArrow->width : 0);
aw += 30;
ow += 30;
dw += 30;
aw += ScaleX(30);
ow += ScaleX(30);
dw += ScaleX(30);
w = WMAX(dw, WMAX(aw, ow));
if ((w + 10) * 3 < 400) {
if ((w + ScaleX(10)) * 3 < pwidth) {
aw = w;
ow = w;
dw = w;
} else {
int t;
t = 400 - 40 - aw - ow - dw;
t = pwidth - 4 * ScaleX(10) - aw - ow - dw;
aw += t / 3;
ow += t / 3;
dw += t / 3;
@@ -200,6 +215,7 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow * owner,
if (defaultButton) {
panel->defBtn = WMCreateCommandButton(panel->hbox);
WMResizeWidget(panel->defBtn, dw, ScaleY(24));
WMSetButtonAction(panel->defBtn, alertPanelOnClick, panel);
WMAddBoxSubviewAtEnd(panel->hbox, WMWidgetView(panel->defBtn), False, True, dw, 0, 0);
WMSetButtonText(panel->defBtn, defaultButton);
@@ -209,14 +225,16 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow * owner,
}
if (alternateButton) {
panel->altBtn = WMCreateCommandButton(panel->hbox);
WMAddBoxSubviewAtEnd(panel->hbox, WMWidgetView(panel->altBtn), False, True, aw, 0, 5);
WMResizeWidget(panel->altBtn, aw, ScaleY(24));
WMAddBoxSubviewAtEnd(panel->hbox, WMWidgetView(panel->altBtn), False, True, aw, 0, ScaleX(5));
WMSetButtonAction(panel->altBtn, alertPanelOnClick, panel);
WMSetButtonText(panel->altBtn, alternateButton);
}
if (otherButton) {
panel->othBtn = WMCreateCommandButton(panel->hbox);
WMResizeWidget(panel->othBtn, ow, ScaleY(24));
WMSetButtonAction(panel->othBtn, alertPanelOnClick, panel);
WMAddBoxSubviewAtEnd(panel->hbox, WMWidgetView(panel->othBtn), False, True, ow, 0, 5);
WMAddBoxSubviewAtEnd(panel->hbox, WMWidgetView(panel->othBtn), False, True, ow, 0, ScaleX(5));
WMSetButtonText(panel->othBtn, otherButton);
}
+13 -7
View File
@@ -75,15 +75,18 @@ int wMessageDialog(WScreen *scr, const char *title, const char *message, const c
WWindow *wwin;
int result;
WMPoint center;
int pwidth, pheight;
panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message, defBtn, altBtn, othBtn);
pwidth = WMWidgetWidth(panel->win);
pheight = WMWidgetHeight(panel->win);
parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 400, 180, 0, 0, 0);
parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, pwidth, pheight, 0, 0, 0);
XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
center = getCenter(scr, 400, 180);
wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y, 400, 180);
center = getCenter(scr, pwidth, pheight);
wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y, pwidth, pheight);
wwin->client_leader = WMWidgetXID(panel->win);
WMMapWidget(panel->win);
@@ -121,24 +124,27 @@ int wExitDialog(WScreen *scr, const char *title, const char *message, const char
WWindow *wwin;
WMPoint center;
int result;
int pwidth, pheight;
panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message, defBtn, altBtn, othBtn);
pwidth = WMWidgetWidth(panel->win);
pheight = WMWidgetHeight(panel->win);
/* add save session button */
saveSessionBtn = WMCreateSwitchButton(panel->hbox);
WMSetButtonAction(saveSessionBtn, toggleSaveSession, NULL);
WMAddBoxSubview(panel->hbox, WMWidgetView(saveSessionBtn), False, True, 200, 0, 0);
WMAddBoxSubview(panel->hbox, WMWidgetView(saveSessionBtn), False, True, pwidth / 2, 0, 0);
WMSetButtonText(saveSessionBtn, _("Save workspace state"));
WMSetButtonSelected(saveSessionBtn, wPreferences.save_session_on_exit);
WMRealizeWidget(saveSessionBtn);
WMMapWidget(saveSessionBtn);
parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 400, 180, 0, 0, 0);
parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, pwidth, pheight, 0, 0, 0);
XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
center = getCenter(scr, 400, 180);
wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y, 400, 180);
center = getCenter(scr, pwidth, pheight);
wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y, pwidth, pheight);
wwin->client_leader = WMWidgetXID(panel->win);