And brought the new font out of the font dialog and into the font button. We should be good now...

This commit is contained in:
Pietro Gagliardi 2016-04-18 01:12:25 -04:00
parent dcbbced23b
commit 4d025172fe
2 changed files with 28 additions and 4 deletions

View File

@ -18,7 +18,17 @@ uiWindowsDefineControlWithOnDestroy(
static void updateFontButtonLabel(uiFontButton *b) static void updateFontButtonLabel(uiFontButton *b)
{ {
// TODO // TODO make this dynamically sized
// TODO also include the style, but from where? libui or DirectWrite?
WCHAR text[1024];
WCHAR *family;
family = toUTF16(b->desc.Family);
_snwprintf(text, 1024, L"%s %g", family, b->desc.Size);
uiFree(family);
// TODO error check
SendMessageW(b->hwnd, WM_SETTEXT, 0, (LPARAM) text);
// changing the text might necessitate a change in the button's size // changing the text might necessitate a change in the button's size
uiWindowsControlQueueRelayout(uiWindowsControl(b)); uiWindowsControlQueueRelayout(uiWindowsControl(b));
} }
@ -94,8 +104,7 @@ uiFontButton *uiNewFontButton(void)
b = (uiFontButton *) uiNewControl(uiFontButtonType()); b = (uiFontButton *) uiNewControl(uiFontButtonType());
b->hwnd = uiWindowsEnsureCreateControlHWND(0, b->hwnd = uiWindowsEnsureCreateControlHWND(0,
// TODO L"button", L"you should not be seeing this",
L"button", L"Arial 10",
BS_PUSHBUTTON | WS_TABSTOP, BS_PUSHBUTTON | WS_TABSTOP,
hInstance, NULL, hInstance, NULL,
TRUE); TRUE);
@ -106,6 +115,7 @@ uiFontButton *uiNewFontButton(void)
b->desc.Weight = uiDrawTextWeightNormal; b->desc.Weight = uiDrawTextWeightNormal;
b->desc.Italic = uiDrawTextItalicNormal; b->desc.Italic = uiDrawTextItalicNormal;
b->desc.Stretch = uiDrawTextStretchNormal; b->desc.Stretch = uiDrawTextStretchNormal;
updateFontButtonLabel(b);
uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b)); uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b));
//TODO uiButtonOnClicked(b, defaultOnClicked, NULL); //TODO uiButtonOnClicked(b, defaultOnClicked, NULL);

View File

@ -528,6 +528,10 @@ static void endFontDialog(struct fontDialog *f, INT_PTR code)
static INT_PTR tryFinishDialog(struct fontDialog *f, WPARAM wParam) static INT_PTR tryFinishDialog(struct fontDialog *f, WPARAM wParam)
{ {
WCHAR *wfamily;
IDWriteFont *font;
struct dwriteAttr attr;
// cancelling // cancelling
if (LOWORD(wParam) != IDOK) { if (LOWORD(wParam) != IDOK) {
endFontDialog(f, 1); endFontDialog(f, 1);
@ -535,8 +539,18 @@ static INT_PTR tryFinishDialog(struct fontDialog *f, WPARAM wParam)
} }
// OK // OK
// TODO fill f->desc here wfamily = cbGetItemText(f->familyCombobox, f->curFamily);
f->desc->Family = toUTF8(wfamily);
uiFree(wfamily);
f->desc->Size = f->curSize; f->desc->Size = f->curSize;
font = (IDWriteFont *) cbGetItemData(f->styleCombobox, f->curStyle);
attr.dweight = font->GetWeight();
attr.ditalic = font->GetStyle();
attr.dstretch = font->GetStretch();
dwriteAttrToAttr(&attr);
f->desc->Weight = attr.weight;
f->desc->Italic = attr.italic;
f->desc->Stretch = attr.stretch;
endFontDialog(f, 2); endFontDialog(f, 2);
return TRUE; return TRUE;
} }