1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-20 04:48:06 +01:00

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
2019-06-12 22:06:26 +02:00
committed by Carlos R. Mafra
parent b185d46286
commit 26bb94a8e7
2 changed files with 46 additions and 22 deletions

View File

@@ -92,6 +92,8 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow * owner,
int dw = 0, aw = 0, ow = 0, w; int dw = 0, aw = 0, ow = 0, w;
WMBox *hbox; WMBox *hbox;
WMPixmap *icon; WMPixmap *icon;
int fw, fh;
int pwidth, pheight;
panel = wmalloc(sizeof(WMAlertPanel)); panel = wmalloc(sizeof(WMAlertPanel));
@@ -101,9 +103,22 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow * owner,
panel->win = WMCreateWindowWithStyle(scrPtr, "alertPanel", WMTitledWindowMask); 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, WMSetWindowInitialPosition(panel->win,
(scrPtr->rootView->size.width - WMWidgetWidth(panel->win)) / 2, (scrPtr->rootView->size.width - pwidth) / 2,
(scrPtr->rootView->size.height - WMWidgetHeight(panel->win)) / 2); (scrPtr->rootView->size.height - pheight) / 2);
WMSetWindowTitle(panel->win, ""); WMSetWindowTitle(panel->win, "");
@@ -113,10 +128,10 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow * owner,
WMMapWidget(panel->vbox); WMMapWidget(panel->vbox);
hbox = WMCreateBox(panel->vbox); hbox = WMCreateBox(panel->vbox);
WMSetBoxBorderWidth(hbox, 5); WMSetBoxBorderWidth(hbox, ScaleX(5));
WMSetBoxHorizontal(hbox, True); WMSetBoxHorizontal(hbox, True);
WMMapWidget(hbox); 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); panel->iLbl = WMCreateLabel(hbox);
WMSetLabelImagePosition(panel->iLbl, WIPImageOnly); WMSetLabelImagePosition(panel->iLbl, WIPImageOnly);
@@ -149,7 +164,7 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow * owner,
panel->line = WMCreateFrame(panel->win); panel->line = WMCreateFrame(panel->win);
WMMapWidget(panel->line); 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); WMSetFrameRelief(panel->line, WRGroove);
if (msg) { if (msg) {
@@ -157,16 +172,16 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow * owner,
WMSetLabelWraps(panel->mLbl, True); WMSetLabelWraps(panel->mLbl, True);
WMMapWidget(panel->mLbl); WMMapWidget(panel->mLbl);
WMAddBoxSubview(panel->vbox, WMWidgetView(panel->mLbl), True, True, 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); WMSetLabelText(panel->mLbl, msg);
WMSetLabelTextAlignment(panel->mLbl, WACenter); WMSetLabelTextAlignment(panel->mLbl, WACenter);
} }
panel->hbox = WMCreateBox(panel->vbox); panel->hbox = WMCreateBox(panel->vbox);
WMSetBoxBorderWidth(panel->hbox, 10); WMSetBoxBorderWidth(panel->hbox, ScaleX(10));
WMSetBoxHorizontal(panel->hbox, True); WMSetBoxHorizontal(panel->hbox, True);
WMMapWidget(panel->hbox); 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 */ /* create buttons */
if (otherButton) if (otherButton)
@@ -180,19 +195,19 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow * owner,
dw = dw + (scrPtr->buttonArrow ? scrPtr->buttonArrow->width : 0); dw = dw + (scrPtr->buttonArrow ? scrPtr->buttonArrow->width : 0);
aw += 30; aw += ScaleX(30);
ow += 30; ow += ScaleX(30);
dw += 30; dw += ScaleX(30);
w = WMAX(dw, WMAX(aw, ow)); w = WMAX(dw, WMAX(aw, ow));
if ((w + 10) * 3 < 400) { if ((w + ScaleX(10)) * 3 < pwidth) {
aw = w; aw = w;
ow = w; ow = w;
dw = w; dw = w;
} else { } else {
int t; int t;
t = 400 - 40 - aw - ow - dw; t = pwidth - 4 * ScaleX(10) - aw - ow - dw;
aw += t / 3; aw += t / 3;
ow += t / 3; ow += t / 3;
dw += t / 3; dw += t / 3;
@@ -200,6 +215,7 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow * owner,
if (defaultButton) { if (defaultButton) {
panel->defBtn = WMCreateCommandButton(panel->hbox); panel->defBtn = WMCreateCommandButton(panel->hbox);
WMResizeWidget(panel->defBtn, dw, ScaleY(24));
WMSetButtonAction(panel->defBtn, alertPanelOnClick, panel); WMSetButtonAction(panel->defBtn, alertPanelOnClick, panel);
WMAddBoxSubviewAtEnd(panel->hbox, WMWidgetView(panel->defBtn), False, True, dw, 0, 0); WMAddBoxSubviewAtEnd(panel->hbox, WMWidgetView(panel->defBtn), False, True, dw, 0, 0);
WMSetButtonText(panel->defBtn, defaultButton); WMSetButtonText(panel->defBtn, defaultButton);
@@ -209,14 +225,16 @@ WMAlertPanel *WMCreateAlertPanel(WMScreen * scrPtr, WMWindow * owner,
} }
if (alternateButton) { if (alternateButton) {
panel->altBtn = WMCreateCommandButton(panel->hbox); 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); WMSetButtonAction(panel->altBtn, alertPanelOnClick, panel);
WMSetButtonText(panel->altBtn, alternateButton); WMSetButtonText(panel->altBtn, alternateButton);
} }
if (otherButton) { if (otherButton) {
panel->othBtn = WMCreateCommandButton(panel->hbox); panel->othBtn = WMCreateCommandButton(panel->hbox);
WMResizeWidget(panel->othBtn, ow, ScaleY(24));
WMSetButtonAction(panel->othBtn, alertPanelOnClick, panel); 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); WMSetButtonText(panel->othBtn, otherButton);
} }

View File

@@ -75,15 +75,18 @@ int wMessageDialog(WScreen *scr, const char *title, const char *message, const c
WWindow *wwin; WWindow *wwin;
int result; int result;
WMPoint center; WMPoint center;
int pwidth, pheight;
panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message, defBtn, altBtn, othBtn); 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); XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
center = getCenter(scr, 400, 180); center = getCenter(scr, pwidth, pheight);
wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y, 400, 180); wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y, pwidth, pheight);
wwin->client_leader = WMWidgetXID(panel->win); wwin->client_leader = WMWidgetXID(panel->win);
WMMapWidget(panel->win); WMMapWidget(panel->win);
@@ -121,24 +124,27 @@ int wExitDialog(WScreen *scr, const char *title, const char *message, const char
WWindow *wwin; WWindow *wwin;
WMPoint center; WMPoint center;
int result; int result;
int pwidth, pheight;
panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message, defBtn, altBtn, othBtn); panel = WMCreateAlertPanel(scr->wmscreen, NULL, title, message, defBtn, altBtn, othBtn);
pwidth = WMWidgetWidth(panel->win);
pheight = WMWidgetHeight(panel->win);
/* add save session button */ /* add save session button */
saveSessionBtn = WMCreateSwitchButton(panel->hbox); saveSessionBtn = WMCreateSwitchButton(panel->hbox);
WMSetButtonAction(saveSessionBtn, toggleSaveSession, NULL); 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")); WMSetButtonText(saveSessionBtn, _("Save workspace state"));
WMSetButtonSelected(saveSessionBtn, wPreferences.save_session_on_exit); WMSetButtonSelected(saveSessionBtn, wPreferences.save_session_on_exit);
WMRealizeWidget(saveSessionBtn); WMRealizeWidget(saveSessionBtn);
WMMapWidget(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); XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
center = getCenter(scr, 400, 180); center = getCenter(scr, pwidth, pheight);
wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y, 400, 180); wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y, pwidth, pheight);
wwin->client_leader = WMWidgetXID(panel->win); wwin->client_leader = WMWidgetXID(panel->win);