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

Improved layout of the Input Panels

Instead of relying on static pixel values for position and size of
the widgets, the input panels now scale their widgets based on the
selected system font size.
This commit is contained in:
Tim Taenny
2019-06-12 22:06:27 +02:00
committed by Carlos R. Mafra
parent 26bb94a8e7
commit f9236c8d20
2 changed files with 30 additions and 22 deletions

View File

@@ -357,6 +357,7 @@ WMInputPanel *WMCreateInputPanel(WMScreen * scrPtr, WMWindow * owner, const char
{ {
WMInputPanel *panel; WMInputPanel *panel;
int x, dw = 0, aw = 0, w; int x, dw = 0, aw = 0, w;
int fw, fh;
panel = wmalloc(sizeof(WMInputPanel)); panel = wmalloc(sizeof(WMInputPanel));
@@ -366,16 +367,17 @@ WMInputPanel *WMCreateInputPanel(WMScreen * scrPtr, WMWindow * owner, const char
panel->win = WMCreateWindowWithStyle(scrPtr, "inputPanel", WMTitledWindowMask); panel->win = WMCreateWindowWithStyle(scrPtr, "inputPanel", WMTitledWindowMask);
WMSetWindowTitle(panel->win, ""); WMSetWindowTitle(panel->win, "");
WMResizeWidget(panel->win, 320, 160); WMGetScaleBaseFromSystemFont(scrPtr, &fw, &fh);
WMResizeWidget(panel->win, ScaleX(320), ScaleY(160));
if (title) { if (title) {
WMFont *largeFont; WMFont *largeFont;
largeFont = WMBoldSystemFontOfSize(scrPtr, 24); largeFont = WMBoldSystemFontOfSize(scrPtr, ScaleY(24));
panel->tLbl = WMCreateLabel(panel->win); panel->tLbl = WMCreateLabel(panel->win);
WMMoveWidget(panel->tLbl, 20, 16); WMMoveWidget(panel->tLbl, ScaleX(20), ScaleY(16));
WMResizeWidget(panel->tLbl, 320 - 40, WMFontHeight(largeFont) + 4); WMResizeWidget(panel->tLbl, ScaleX(320) - 2 * ScaleX(20), WMFontHeight(largeFont) + ScaleY(4));
WMSetLabelText(panel->tLbl, title); WMSetLabelText(panel->tLbl, title);
WMSetLabelTextAlignment(panel->tLbl, WALeft); WMSetLabelTextAlignment(panel->tLbl, WALeft);
WMSetLabelFont(panel->tLbl, largeFont); WMSetLabelFont(panel->tLbl, largeFont);
@@ -385,15 +387,15 @@ WMInputPanel *WMCreateInputPanel(WMScreen * scrPtr, WMWindow * owner, const char
if (msg) { if (msg) {
panel->mLbl = WMCreateLabel(panel->win); panel->mLbl = WMCreateLabel(panel->win);
WMMoveWidget(panel->mLbl, 20, 50); WMMoveWidget(panel->mLbl, ScaleX(20), ScaleY(50));
WMResizeWidget(panel->mLbl, 320 - 40, WMFontHeight(scrPtr->normalFont) * 2); WMResizeWidget(panel->mLbl, ScaleX(320) - 2 * ScaleX(20), WMFontHeight(scrPtr->normalFont) * 2);
WMSetLabelText(panel->mLbl, msg); WMSetLabelText(panel->mLbl, msg);
WMSetLabelTextAlignment(panel->mLbl, WALeft); WMSetLabelTextAlignment(panel->mLbl, WALeft);
} }
panel->text = WMCreateTextField(panel->win); panel->text = WMCreateTextField(panel->win);
WMMoveWidget(panel->text, 20, 85); WMMoveWidget(panel->text, ScaleX(20), ScaleY(85));
WMResizeWidget(panel->text, 320 - 40, WMWidgetHeight(panel->text)); WMResizeWidget(panel->text, ScaleX(320) - 2 * ScaleX(20), ScaleY(20));
WMSetTextFieldText(panel->text, defaultText); WMSetTextFieldText(panel->text, defaultText);
WMAddNotificationObserver(endedEditingObserver, panel, WMTextDidEndEditingNotification, panel->text); WMAddNotificationObserver(endedEditingObserver, panel, WMTextDidEndEditingNotification, panel->text);
@@ -409,29 +411,29 @@ WMInputPanel *WMCreateInputPanel(WMScreen * scrPtr, WMWindow * owner, const char
if (aw > w) if (aw > w)
w = aw; w = aw;
w += 30; w += ScaleX(30);
x = 310; x = ScaleX(310);
if (okButton) { if (okButton) {
x -= w + 10; x -= w + ScaleX(10);
panel->defBtn = WMCreateCustomButton(panel->win, WBBPushInMask panel->defBtn = WMCreateCustomButton(panel->win, WBBPushInMask
| WBBPushChangeMask | WBBPushLightMask); | WBBPushChangeMask | WBBPushLightMask);
WMSetButtonAction(panel->defBtn, inputBoxOnClick, panel); WMSetButtonAction(panel->defBtn, inputBoxOnClick, panel);
WMMoveWidget(panel->defBtn, x, 124); WMMoveWidget(panel->defBtn, x, ScaleY(124));
WMResizeWidget(panel->defBtn, w, 24); WMResizeWidget(panel->defBtn, w, ScaleY(24));
WMSetButtonText(panel->defBtn, okButton); WMSetButtonText(panel->defBtn, okButton);
WMSetButtonImage(panel->defBtn, scrPtr->buttonArrow); WMSetButtonImage(panel->defBtn, scrPtr->buttonArrow);
WMSetButtonAltImage(panel->defBtn, scrPtr->pushedButtonArrow); WMSetButtonAltImage(panel->defBtn, scrPtr->pushedButtonArrow);
WMSetButtonImagePosition(panel->defBtn, WIPRight); WMSetButtonImagePosition(panel->defBtn, WIPRight);
} }
if (cancelButton) { if (cancelButton) {
x -= w + 10; x -= w + ScaleX(10);
panel->altBtn = WMCreateCommandButton(panel->win); panel->altBtn = WMCreateCommandButton(panel->win);
WMSetButtonAction(panel->altBtn, inputBoxOnClick, panel); WMSetButtonAction(panel->altBtn, inputBoxOnClick, panel);
WMMoveWidget(panel->altBtn, x, 124); WMMoveWidget(panel->altBtn, x, ScaleY(124));
WMResizeWidget(panel->altBtn, w, 24); WMResizeWidget(panel->altBtn, w, ScaleY(24));
WMSetButtonText(panel->altBtn, cancelButton); WMSetButtonText(panel->altBtn, cancelButton);
} }

View File

@@ -428,6 +428,7 @@ int wAdvancedInputDialog(WScreen *scr, const char *title, const char *message, c
WMPoint center; WMPoint center;
WMInputPanelWithHistory *p; WMInputPanelWithHistory *p;
char *filename; char *filename;
int pwidth, pheight;
filename = HistoryFileName(name); filename = HistoryFileName(name);
p = wmalloc(sizeof(WMInputPanelWithHistory)); p = wmalloc(sizeof(WMInputPanelWithHistory));
@@ -440,14 +441,16 @@ int wAdvancedInputDialog(WScreen *scr, const char *title, const char *message, c
p->variants = NULL; p->variants = NULL;
p->varpos = 0; p->varpos = 0;
WMCreateEventHandler(WMWidgetView(p->panel->text), KeyPressMask, handleHistoryKeyPress, p); WMCreateEventHandler(WMWidgetView(p->panel->text), KeyPressMask, handleHistoryKeyPress, p);
pwidth = WMWidgetWidth(p->panel->win);
pheight = WMWidgetHeight(p->panel->win);
parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 320, 160, 0, 0, 0); parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, pwidth, pheight, 0, 0, 0);
XSelectInput(dpy, parent, KeyPressMask | KeyReleaseMask); XSelectInput(dpy, parent, KeyPressMask | KeyReleaseMask);
XReparentWindow(dpy, WMWidgetXID(p->panel->win), parent, 0, 0); XReparentWindow(dpy, WMWidgetXID(p->panel->win), parent, 0, 0);
center = getCenter(scr, 320, 160); center = getCenter(scr, pwidth, pheight);
wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y, 320, 160); wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y, pwidth, pheight);
wwin->client_leader = WMWidgetXID(p->panel->win); wwin->client_leader = WMWidgetXID(p->panel->win);
@@ -491,16 +494,19 @@ int wInputDialog(WScreen *scr, const char *title, const char *message, char **te
WMInputPanel *panel; WMInputPanel *panel;
char *result; char *result;
WMPoint center; WMPoint center;
int pwidth, pheight;
panel = WMCreateInputPanel(scr->wmscreen, NULL, title, message, *text, _("OK"), _("Cancel")); panel = WMCreateInputPanel(scr->wmscreen, NULL, title, message, *text, _("OK"), _("Cancel"));
pwidth = WMWidgetWidth(panel->win);
pheight = WMWidgetHeight(panel->win);
parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, 320, 160, 0, 0, 0); parent = XCreateSimpleWindow(dpy, scr->root_win, 0, 0, pwidth, pheight, 0, 0, 0);
XSelectInput(dpy, parent, KeyPressMask | KeyReleaseMask); XSelectInput(dpy, parent, KeyPressMask | KeyReleaseMask);
XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0); XReparentWindow(dpy, WMWidgetXID(panel->win), parent, 0, 0);
center = getCenter(scr, 320, 160); center = getCenter(scr, pwidth, pheight);
wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y, 320, 160); wwin = wManageInternalWindow(scr, parent, None, NULL, center.x, center.y, pwidth, pheight);
wwin->client_leader = WMWidgetXID(panel->win); wwin->client_leader = WMWidgetXID(panel->win);