CppKore: try parent font if current is absent

This allows for setting uniform fonts on all controls, by only assigning the font once to the parent control. Else each control needs to have its own set.
This commit is contained in:
Kawe Mazidjatari 2024-04-17 20:26:03 +02:00
parent 29ff073ae3
commit 4c99efa889
2 changed files with 7 additions and 2 deletions

View File

@ -231,8 +231,13 @@ namespace Forms
SetWindowLongPtrA(this->_Handle, GWLP_USERDATA, (intptr_t)this);
// Setup the default font if none was previously set
if (this->_Font == nullptr)
this->_Font = std::make_unique<Drawing::Font>(this->_Handle, (HFONT)GetStockObject(DEFAULT_GUI_FONT));
if (this->_Parent && this->_Parent->_Font)
this->_Font = std::make_unique<Drawing::Font>(this->_Handle, this->_Parent->_Font.get()->GetFontHandle());
else
this->_Font = std::make_unique<Drawing::Font>(this->_Handle, (HFONT)GetStockObject(DEFAULT_GUI_FONT));
// Notify the window of the font selection
SendMessageA(this->_Handle, WM_SETFONT, (WPARAM)this->_Font->GetFontHandle(), NULL);

View File

@ -146,7 +146,7 @@ namespace Forms
// Retrieves the current font for this control.
Drawing::Font* GetFont();
// Retrieves the current font for this control.
// Sets the current font for this control.
void SetFont(Drawing::Font* Font);
// The parent of this control.