@@ -56,14 +56,14 @@ class UILIB_API LabelTemplate : public InheritType
56
56
* @brief 获取当前字体编号
57
57
* @return 返回字体编号,该编号在 global.xml 中标识
58
58
*/
59
- int GetFont () const ;
59
+ std::wstring GetFont () const ;
60
60
61
61
/* *
62
62
* @brief 设置当前字体
63
63
* @param[in] index 要设置的字体编号,该编号必须在 global.xml 中存在
64
64
* @return 无
65
65
*/
66
- void SetFont (int index );
66
+ void SetFont (const std::wstring& strFontId );
67
67
68
68
/* *
69
69
* @brief 获取文字边距
@@ -105,7 +105,7 @@ class UILIB_API LabelTemplate : public InheritType
105
105
void SetLineLimit (bool bLineLimit);
106
106
107
107
protected:
108
- int m_iFont ;
108
+ std::wstring m_sFontId ;
109
109
UINT m_uTextStyle;
110
110
bool m_bSingleLine;
111
111
bool m_bLineLimit;
@@ -119,7 +119,7 @@ class UILIB_API LabelTemplate : public InheritType
119
119
120
120
template <typename InheritType>
121
121
LabelTemplate<InheritType>::LabelTemplate() :
122
- m_iFont ( 1 ),
122
+ m_sFontId ( ),
123
123
m_uTextStyle(DT_LEFT | DT_TOP | DT_END_ELLIPSIS | DT_NOCLIP | DT_SINGLELINE),
124
124
m_bSingleLine(true ),
125
125
m_bLineLimit(false ),
@@ -226,7 +226,7 @@ CSize LabelTemplate<InheritType>::EstimateText(CSize szAvailable, bool& bReEstim
226
226
CSize fixedSize;
227
227
if (!GetText ().empty ()) {
228
228
auto pRender = this ->m_pWindow ->GetRenderContext ();
229
- UiRect rect = pRender->MeasureText (GetText (), m_iFont , m_uTextStyle, width);
229
+ UiRect rect = pRender->MeasureText (GetText (), m_sFontId , m_uTextStyle, width);
230
230
if (this ->GetFixedWidth () == DUI_LENGTH_AUTO) {
231
231
fixedSize.cx = rect.right - rect.left + m_rcTextPadding.left + m_rcTextPadding.right ;
232
232
}
@@ -239,7 +239,7 @@ CSize LabelTemplate<InheritType>::EstimateText(CSize szAvailable, bool& bReEstim
239
239
int maxWidth = szAvailable.cx - m_rcTextPadding.left - m_rcTextPadding.right ;
240
240
if (estimateWidth > maxWidth) {
241
241
estimateWidth = maxWidth;
242
- UiRect newRect = pRender->MeasureText (GetText (), m_iFont , m_uTextStyle, estimateWidth);
242
+ UiRect newRect = pRender->MeasureText (GetText (), m_sFontId , m_uTextStyle, estimateWidth);
243
243
estimateHeight = newRect.bottom - newRect.top ;
244
244
}
245
245
}
@@ -288,7 +288,7 @@ void LabelTemplate<InheritType>::SetAttribute(const std::wstring& strName, const
288
288
else if (strName == _T (" singleline" )) SetSingleLine (strValue == _T (" true" ));
289
289
else if (strName == _T (" text" )) SetText (strValue);
290
290
else if (strName == _T (" textid" )) SetTextId (strValue);
291
- else if (strName == _T (" font" )) SetFont (_ttoi ( strValue. c_str ()) );
291
+ else if (strName == _T (" font" )) SetFont (strValue);
292
292
else if (strName == _T (" normaltextcolor" )) SetStateTextColor (kControlStateNormal , strValue);
293
293
else if (strName == _T (" hottextcolor" )) SetStateTextColor (kControlStateHot , strValue);
294
294
else if (strName == _T (" pushedtextcolor" )) SetStateTextColor (kControlStatePushed , strValue);
@@ -339,22 +339,22 @@ void LabelTemplate<InheritType>::PaintText(IRenderContext* pRender)
339
339
std::wstring clrColor = GetStateTextColor (kControlStateNormal );
340
340
if (!clrColor.empty ()) {
341
341
DWORD dwClrColor = GlobalManager::GetTextColor (clrColor);
342
- pRender->DrawText (rc, GetText (), dwClrColor, m_iFont , m_uTextStyle, 255 , m_bLineLimit);
342
+ pRender->DrawText (rc, GetText (), dwClrColor, m_sFontId , m_uTextStyle, 255 , m_bLineLimit);
343
343
}
344
344
345
345
if (this ->m_nHotAlpha > 0 ) {
346
346
std::wstring clrColor = GetStateTextColor (kControlStateHot );
347
347
if (!clrColor.empty ()) {
348
348
DWORD dwClrColor = GlobalManager::GetTextColor (clrColor);
349
- pRender->DrawText (rc, GetText (), dwClrColor, m_iFont , m_uTextStyle, (BYTE)this ->m_nHotAlpha , m_bLineLimit);
349
+ pRender->DrawText (rc, GetText (), dwClrColor, m_sFontId , m_uTextStyle, (BYTE)this ->m_nHotAlpha , m_bLineLimit);
350
350
}
351
351
}
352
352
353
353
return ;
354
354
}
355
355
}
356
356
357
- pRender->DrawText (rc, GetText (), dwClrColor, m_iFont , m_uTextStyle, 255 , m_bLineLimit);
357
+ pRender->DrawText (rc, GetText (), dwClrColor, m_sFontId , m_uTextStyle, 255 , m_bLineLimit);
358
358
}
359
359
360
360
template <typename InheritType>
@@ -387,15 +387,15 @@ void LabelTemplate<InheritType>::SetStateTextColor(ControlStateType stateType, c
387
387
}
388
388
389
389
template <typename InheritType>
390
- int LabelTemplate<InheritType>::GetFont() const
390
+ std::wstring LabelTemplate<InheritType>::GetFont() const
391
391
{
392
- return m_iFont ;
392
+ return m_sFontId ;
393
393
}
394
394
395
395
template <typename InheritType>
396
- void LabelTemplate<InheritType>::SetFont(int index )
396
+ void LabelTemplate<InheritType>::SetFont(const std::wstring& strFontId )
397
397
{
398
- m_iFont = index ;
398
+ m_sFontId = strFontId ;
399
399
this ->Invalidate ();
400
400
}
401
401
0 commit comments