1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-02-13 20:35:54 +01:00

Added ScaleX and ScaleY macros to WINGs

To reduce code duplication the ScaleX and ScaleY macros have been
moved to WUtil.h. Along with the function WMGetScaleBaseFromSystemFont
these macros can be used in all panels to scale the widgets based on
the current system font size instead of giving fixed pixel sizes which
messes up the panels if a larger system font is selected in WPrefs.

Use the macros in the following way:

    instead of   WMResizeWidget(widget, 128, 64);
                 WMMoveWidget(widget, 32, 32);

    use          int fw, fh;
                 WMGetScaleBaseFromSystemFont(scr->wmscreen, &fw, &fh);
                 WMResizeWidget(widget, ScaleX(128), ScaleY(64));
                 WMMoveWidget(widget, ScaleX(32), ScaleY(32));
This commit is contained in:
Tim Taenny
2019-06-12 22:06:25 +02:00
committed by Carlos R. Mafra
parent 8f29bdc690
commit b185d46286
4 changed files with 66 additions and 54 deletions

View File

@@ -795,6 +795,8 @@ char* WMGetFontName(WMFont *font);
unsigned int WMFontHeight(WMFont *font);
void WMGetScaleBaseFromSystemFont(WMScreen *scrPtr, int *alphabetWidth, int *fontHeight);
void WMSetWidgetDefaultFont(WMScreen *scr, WMFont *font);
void WMSetWidgetDefaultBoldFont(WMScreen *scr, WMFont *font);

View File

@@ -193,6 +193,16 @@ typedef void WMNotificationObserverAction(void *observerData,
sizeof(array) / sizeof(array[0]); \
})
/* These macros can be used to adjust the location and size pixel values in
* the panel layouts so that they match the configured size of the system
* font (useful with high DPI screens, where you have to increase this size).
* The macros require two local variables to be set:
* fw: the width of the alphabet in the current system font
* fh: the height of the current system font
* Use the WMGetScaleBaseFromSystemFont function to set these values.
*/
#define ScaleX(value) ((int)((double)value / 164.0 * (double)fw + 0.5))
#define ScaleY(value) ((int)((double)value / 14.0 * (double)fh + 0.5))
/* ---[ WINGs/memory.c ]-------------------------------------------------- */

View File

@@ -237,6 +237,16 @@ char *WMGetFontName(WMFont * font)
return font->name;
}
void WMGetScaleBaseFromSystemFont(WMScreen *scrPtr, int *alphabetWidth, int *fontHeight)
{
WMFont *font;
font = WMDefaultSystemFont(scrPtr);
*alphabetWidth = WMWidthOfString(font, "abcdefghijklmnopqrstuvwxyz", 26);
*fontHeight = WMFontHeight(font);
WMReleaseFont(font);
}
WMFont *WMDefaultSystemFont(WMScreen * scrPtr)
{
return WMRetainFont(scrPtr->normalFont);