libui/windows/label.cpp

58 lines
1.3 KiB
C++
Raw Normal View History

// 11 april 2015
2016-04-22 19:03:10 -05:00
#include "uipriv_windows.hpp"
struct uiLabel {
uiWindowsControl c;
HWND hwnd;
};
2016-04-29 12:50:08 -05:00
uiWindowsControlAllDefaults(uiLabel)
// via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
#define labelHeight 8
static void uiLabelMinimumSize(uiWindowsControl *c, int *width, int *height)
{
uiLabel *l = uiLabel(c);
2016-04-29 12:50:08 -05:00
uiWindowsSizing sizing;
int y;
*width = uiWindowsWindowTextWidth(l->hwnd);
2016-04-29 12:50:08 -05:00
y = labelHeight;
uiWindowsGetSizing(l->hwnd, &sizing);
uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &y);
2016-04-29 12:50:08 -05:00
*height = y;
}
char *uiLabelText(uiLabel *l)
{
2016-04-22 19:03:10 -05:00
return uiWindowsWindowText(l->hwnd);
}
void uiLabelSetText(uiLabel *l, const char *text)
{
uiWindowsSetWindowText(l->hwnd, text);
// changing the text might necessitate a change in the label's size
uiWindowsControlMinimumSizeChanged(uiWindowsControl(l));
}
2015-04-16 08:33:21 -05:00
uiLabel *uiNewLabel(const char *text)
{
uiLabel *l;
WCHAR *wtext;
2016-04-29 12:50:08 -05:00
uiWindowsNewControl(uiLabel, l);
wtext = toUTF16(text);
2015-08-31 11:33:44 -05:00
l->hwnd = uiWindowsEnsureCreateControlHWND(0,
L"static", wtext,
// SS_LEFTNOWORDWRAP clips text past the end; SS_NOPREFIX avoids accelerator translation
// controls are vertically aligned to the top by default (thanks Xeek in irc.freenode.net/#winapi)
SS_LEFTNOWORDWRAP | SS_NOPREFIX,
hInstance, NULL,
TRUE);
uiprivFree(wtext);
return l;
}