Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML中的Font节点添加id属性,支持font自定义,同时兼容过去的索引方式 #42

Merged
merged 3 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/resources/themes/default/cef/cef.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<HBox height="auto">
<Button class="btn_global_blue_80x30" name="btn_back" text="后退" width="60"/>
<Button class="btn_global_blue_80x30" name="btn_forward" text="前进" width="60" margin="5,0,5"/>
<RichEdit class="simple prompt input" name="edit_url" width="stretch" height="28" valign="center" padding="5,5,5,5" font="1" prompttext="请输入网址"/>
<RichEdit class="simple prompt input" name="edit_url" width="stretch" height="28" valign="center" padding="5,5,5,5" prompttext="请输入网址"/>
<Button class="btn_global_blue_80x30" name="btn_navigate" text="转到" width="60" margin="5"/>
<Button class="btn_global_blue_80x30" name="btn_refresh" text="刷新" width="60" margin="5"/>
</HBox>
Expand Down
2 changes: 1 addition & 1 deletion bin/resources/themes/default/controls/controls.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<Control class="splitline_hor_level1"/>
<!-- RichEdit -->
<RichEdit class="prompt" name="edit" bkcolor="bk_wnd_lightcolor" width="stretch" height="stretch"
font="1" multiline="true" vscrollbar="true" hscrollbar="true" autovscroll="true"
multiline="true" vscrollbar="true" hscrollbar="true" autovscroll="true"
normaltextcolor="darkcolor" wantreturnmsg="true" rich="true"/>
</VBox>
</VBox>
Expand Down
142 changes: 71 additions & 71 deletions bin/resources/themes/default/global.xml

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions bin/resources/themes/default/layouts/login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,33 @@
</HBox>
<HBox height="auto">
<Control />
<Button name="register_account" margin="0,5,15,10" halign="right" text="注册" cursortype="hand" font="24" normaltextcolor="link_green"/>
<Button name="enter_login" margin="0,5,15,10" halign="right" text="直接登录" cursortype="hand" font="24" normaltextcolor="link_green" visible="false"/>
<Button name="register_account" margin="0,5,15,10" halign="right" text="注册" cursortype="hand" font="system_underline_12" normaltextcolor="link_green"/>
<Button name="enter_login" margin="0,5,15,10" halign="right" text="直接登录" cursortype="hand" font="system_underline_12" normaltextcolor="link_green" visible="false"/>
</HBox>
<!--帐号和密码-->
<VBox name="enter_panel" width="240" height="auto" margin="20,0,20,0" bkimage="user_password.png">
<HBox height="41" padding="14,1,10,0">
<Control name="usericon" width="16" height="16" valign="center" normalimage="user_1.png" disabledimage="user_2.png"/>
<RichEdit class="simple prompt" name="username" width="stretch" height="auto" margin="10,0,10,0" valign="center" font="2" prompttext="帐号"/>
<RichEdit class="simple prompt" name="username" width="stretch" height="auto" margin="10,0,10,0" valign="center" font="system_14" prompttext="帐号"/>
</HBox>
<HBox name="nick_name_panel" height="40" padding="14,1,0,0" visible="false" margin="0,0,0,0">
<Control name="nick_name_icon" width="16" height="16" valign="center" normalimage="nickname.png" disabledimage="nickname.png"/>
<RichEdit class="simple prompt" name="nickname" width="stretch" height="auto" margin="10,0,10,0" valign="center" font="2" prompttext="昵称"/>
<RichEdit class="simple prompt" name="nickname" width="stretch" height="auto" margin="10,0,10,0" valign="center" font="system_14" prompttext="昵称"/>
</HBox>
<HBox height="41" padding="14,0,10,1" margin="0,2,0,0">
<Control name="passwordicon" width="16" height="16" valign="center" normalimage="password_1.png" disabledimage="password_2.png"/>
<RichEdit class="simple prompt" name="password" width="stretch" height="auto" margin="10,0,10,0" valign="center" font="2" password="true" prompttext="密码"/>
<RichEdit class="simple prompt" name="password" width="stretch" height="auto" margin="10,0,10,0" valign="center" font="system_14" password="true" prompttext="密码"/>
</HBox>
</VBox>
</VBox>
<!--登录提示-->
<Label name="login_ing_tip" margin="20,20,20,0" font="1" text="正在登录..." visible="false"/>
<Label name="login_error_tip" margin="20,20,20,0" font="1" normaltextcolor="obvious_tip" visible="false"/>
<Label name="login_ing_tip" margin="20,20,20,0" font="system_12" text="正在登录..." visible="false"/>
<Label name="login_error_tip" margin="20,20,20,0" font="system_12" normaltextcolor="obvious_tip" visible="false"/>
<!--登录和取消按钮-->
<Box width="240" height="40" margin="20,20,20,20">
<Button class="btn_global_blue_80x30" name="btn_login" width="240" height="40" font="8" text="登录"/>
<Button class="btn_global_blue_80x30" name="btn_register" width="240" height="40" font="8" text="注册" visible="false"/>
<Button class="btn_global_red_80x30" name="btn_cancel" width="240" height="40" font="8" text="取消登录" visible="false"/>
<Button class="btn_global_blue_80x30" name="btn_login" width="240" height="40" font="system_bold_16" text="登录"/>
<Button class="btn_global_blue_80x30" name="btn_register" width="240" height="40" font="system_bold_16" text="注册" visible="false"/>
<Button class="btn_global_red_80x30" name="btn_cancel" width="240" height="40" font="system_bold_16" text="取消登录" visible="false"/>
</Box>
</VBox>
</Box>
Expand Down
2 changes: 1 addition & 1 deletion bin/resources/themes/default/layouts/wechat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<!-- 好友列表 -->
<VBox width="270" bkcolor="light_gray">
<Box padding="10,8,10,8" height="auto">
<RichEdit class="simple prompt input" name="nickname" width="stretch" height="35" padding="25,8,8,8" font="1" borderround="5,5" prompttext="搜索"/>
<RichEdit class="simple prompt input" name="nickname" width="stretch" height="35" padding="25,8,8,8" borderround="5,5" prompttext="搜索"/>
<Control width="auto" height="auto" margin="6,9" bkimage="search_icon.png"/>
</Box>
<VBox>
Expand Down
2 changes: 1 addition & 1 deletion bin/resources/themes/default/msgbox/msgbox.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Button class="btn_wnd_close" name="closebtn" margin="10,6,0,0"/>
</HBox>

<RichEdit name="content" width="300" margin="20,30,20,30" font="3" multiline="true" vscrollbar="false" autovscroll="false" enabled="false" rich="true"/>
<RichEdit name="content" width="300" margin="20,30,20,30" font="system_16" multiline="true" vscrollbar="false" autovscroll="false" enabled="false" rich="true"/>

<HBox height="auto" margin="0,0,20,20" childmargin="10">
<Control />
Expand Down
10 changes: 5 additions & 5 deletions bin/resources/themes/default/multi_browser/multi_browser.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
</HBox>

<HBox height="30" margin="10,2,10,2" childmargin="3">
<Button class="btn_global_blue_80x30" name="btn_back" width="50" height="30" textid="STRID_CEF_BROWSER_BACKWARD" valign="center" font="1" />
<Button class="btn_global_blue_80x30" name="btn_forward" width="50" height="30" textid="STRID_CEF_BROWSER_FORWARD" valign="center" font="1" />
<Button class="btn_global_blue_80x30" name="btn_refresh" width="50" height="30" textid="STRID_CEF_BROWSER_REFRESH" valign="center" font="1" />
<Button class="btn_global_blue_80x30" name="btn_back" width="50" height="30" textid="STRID_CEF_BROWSER_BACKWARD" valign="center" font="system_12" />
<Button class="btn_global_blue_80x30" name="btn_forward" width="50" height="30" textid="STRID_CEF_BROWSER_FORWARD" valign="center" font="system_12" />
<Button class="btn_global_blue_80x30" name="btn_refresh" width="50" height="30" textid="STRID_CEF_BROWSER_REFRESH" valign="center" font="system_12" />
<RichEdit class="simple prompt" name="edit_url" width="400" height="30" padding="5,2,5,0" valign="center"
bordercolor="gray" bordersize="1" font="2" prompttextid="STRID_CEF_BROWSER_INPUT_ADDRESS" vscrollbar="false" autovscroll="false" hscrollbar="false" autohscroll="true" wantreturnmsg="true" />
bordercolor="gray" bordersize="1" font="system_14" prompttextid="STRID_CEF_BROWSER_INPUT_ADDRESS" vscrollbar="false" autovscroll="false" hscrollbar="false" autohscroll="true" wantreturnmsg="true" />
<!-- 顶部标签列表 -->
<HListBox class="list" name="tab_list" >
<Button class="btn_global_blue_80x30" name="btn_add" text="+" width="20" height="20" valign="center" font="3" />
<Button class="btn_global_blue_80x30" name="btn_add" text="+" width="20" height="20" valign="center" font="system_16" />
</HListBox>
</HBox>
<Control class="splitline_hor_level1" margin="0,0,0,0" />
Expand Down
2 changes: 1 addition & 1 deletion bin/resources/themes/default/multi_browser/tab_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Control name="tab_item_icon" width="38" height="38" borderround="38,38,38,38" margin="1,1,0,0"/>
<Control class="icon_headimage_mask_40x40"/>
</Box>
<Label name="tab_item_name" width="stretch" valign="center" font="1" mouse="false"/>
<Label name="tab_item_name" width="stretch" valign="center" font="system_12" mouse="false"/>

<Box width="auto" height="auto" float="true" halign="right" valign="center">
<Button class="btn_del_search" name="tab_item_close" width="16" height="16" halign="center" valign="center" visible="false"/>
Expand Down
2 changes: 1 addition & 1 deletion bin/resources/themes/default/richlist/richlist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Window size="400,600" caption="0,0,0,35">
<VBox bkcolor="bk_wnd_darkcolor">
<HBox width="stretch" height="35" bkcolor="bk_wnd_lightcolor">
<Label text="自定义列表示例" font="2" valign="center" margin="8"/>
<Label text="自定义列表示例" font="system_14" valign="center" margin="8"/>
<Control />
<Button class="btn_wnd_min" name="minbtn" margin="4,6,0,0"/>
<Box width="21" margin="4,6,0,0">
Expand Down
2 changes: 1 addition & 1 deletion bin/resources/themes/default/toast/toast.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Window size="340,180" caption="0,0,0,600" shadowattached="false" custom_shadow="10,10,10,10">
<Box width="340" height="auto" bkimage="file='win_bg.png' corner='15,15,15,15'">
<RichEdit name="content" width="300" minheight="30" margin="20,20,20,20" font="2" multiline="true" vscrollbar="false" autovscroll="false" enabled="false" rich="false" mouse="false" disabledtextcolor="light_gray"/>
<RichEdit name="content" width="300" minheight="30" margin="20,20,20,20" font="system_14" multiline="true" vscrollbar="false" autovscroll="false" enabled="false" rich="false" mouse="false" disabledtextcolor="light_gray"/>
<Button name="close_btn" width="25" height="24" valign="top" halign="right" visible="false" normalimage="file='close.png' source='0,0,24,24'" hotimage="file='close.png' source='25,0,49,24'" pushedimage="file='close.png' source='50,0,74,24'" disabledimage="file='close.png' source='75,0,99,24'"/>
</Box>
</Window>
2 changes: 1 addition & 1 deletion tool_kits/duilib/Control/CheckBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void CheckBoxTemplate<InheritType>::PaintText(IRenderContext* pRender)
std::wstring newTextColor = m_dwSelectedTextColor.empty() ? this->m_textColorMap[kControlStateNormal] : m_dwSelectedTextColor;
DWORD dwTextColor = GlobalManager::GetTextColor(newTextColor);
DWORD dwDisabledTextColor = GlobalManager::GetTextColor(this->m_textColorMap[kControlStateDisabled]);
pRender->DrawText(rc, this->GetText(), this->IsEnabled() ? dwTextColor : dwDisabledTextColor, this->m_iFont, this->m_uTextStyle);
pRender->DrawText(rc, this->GetText(), this->IsEnabled() ? dwTextColor : dwDisabledTextColor, this->m_sFontId, this->m_uTextStyle);
}

template<typename InheritType>
Expand Down
28 changes: 14 additions & 14 deletions tool_kits/duilib/Control/Label.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ class UILIB_API LabelTemplate : public InheritType
* @brief ��ȡ��ǰ������
* @return ���������ţ��ñ���� global.xml �б�ʶ
*/
int GetFont() const;
std::wstring GetFont() const;

/**
* @brief ���õ�ǰ����
* @param[in] index Ҫ���õ������ţ��ñ�ű����� global.xml �д���
* @return ��
*/
void SetFont(int index);
void SetFont(const std::wstring& strFontId);

/**
* @brief ��ȡ���ֱ߾�
Expand Down Expand Up @@ -105,7 +105,7 @@ class UILIB_API LabelTemplate : public InheritType
void SetLineLimit(bool bLineLimit);

protected:
int m_iFont;
std::wstring m_sFontId;
UINT m_uTextStyle;
bool m_bSingleLine;
bool m_bLineLimit;
Expand All @@ -119,7 +119,7 @@ class UILIB_API LabelTemplate : public InheritType

template<typename InheritType>
LabelTemplate<InheritType>::LabelTemplate() :
m_iFont(1),
m_sFontId(),
m_uTextStyle(DT_LEFT | DT_TOP | DT_END_ELLIPSIS | DT_NOCLIP | DT_SINGLELINE),
m_bSingleLine(true),
m_bLineLimit(false),
Expand Down Expand Up @@ -226,7 +226,7 @@ CSize LabelTemplate<InheritType>::EstimateText(CSize szAvailable, bool& bReEstim
CSize fixedSize;
if (!GetText().empty()) {
auto pRender = this->m_pWindow->GetRenderContext();
UiRect rect = pRender->MeasureText(GetText(), m_iFont, m_uTextStyle, width);
UiRect rect = pRender->MeasureText(GetText(), m_sFontId, m_uTextStyle, width);
if (this->GetFixedWidth() == DUI_LENGTH_AUTO) {
fixedSize.cx = rect.right - rect.left + m_rcTextPadding.left + m_rcTextPadding.right;
}
Expand All @@ -239,7 +239,7 @@ CSize LabelTemplate<InheritType>::EstimateText(CSize szAvailable, bool& bReEstim
int maxWidth = szAvailable.cx - m_rcTextPadding.left - m_rcTextPadding.right;
if (estimateWidth > maxWidth) {
estimateWidth = maxWidth;
UiRect newRect = pRender->MeasureText(GetText(), m_iFont, m_uTextStyle, estimateWidth);
UiRect newRect = pRender->MeasureText(GetText(), m_sFontId, m_uTextStyle, estimateWidth);
estimateHeight = newRect.bottom - newRect.top;
}
}
Expand Down Expand Up @@ -288,7 +288,7 @@ void LabelTemplate<InheritType>::SetAttribute(const std::wstring& strName, const
else if (strName == _T("singleline")) SetSingleLine(strValue == _T("true"));
else if (strName == _T("text")) SetText(strValue);
else if (strName == _T("textid")) SetTextId(strValue);
else if (strName == _T("font")) SetFont(_ttoi(strValue.c_str()));
else if (strName == _T("font")) SetFont(strValue);
else if (strName == _T("normaltextcolor")) SetStateTextColor(kControlStateNormal, strValue);
else if (strName == _T("hottextcolor")) SetStateTextColor(kControlStateHot, strValue);
else if (strName == _T("pushedtextcolor")) SetStateTextColor(kControlStatePushed, strValue);
Expand Down Expand Up @@ -339,22 +339,22 @@ void LabelTemplate<InheritType>::PaintText(IRenderContext* pRender)
std::wstring clrColor = GetStateTextColor(kControlStateNormal);
if (!clrColor.empty()) {
DWORD dwClrColor = GlobalManager::GetTextColor(clrColor);
pRender->DrawText(rc, GetText(), dwClrColor, m_iFont, m_uTextStyle, 255, m_bLineLimit);
pRender->DrawText(rc, GetText(), dwClrColor, m_sFontId, m_uTextStyle, 255, m_bLineLimit);
}

if (this->m_nHotAlpha > 0) {
std::wstring clrColor = GetStateTextColor(kControlStateHot);
if (!clrColor.empty()) {
DWORD dwClrColor = GlobalManager::GetTextColor(clrColor);
pRender->DrawText(rc, GetText(), dwClrColor, m_iFont, m_uTextStyle, (BYTE)this->m_nHotAlpha, m_bLineLimit);
pRender->DrawText(rc, GetText(), dwClrColor, m_sFontId, m_uTextStyle, (BYTE)this->m_nHotAlpha, m_bLineLimit);
}
}

return;
}
}

pRender->DrawText(rc, GetText(), dwClrColor, m_iFont, m_uTextStyle, 255, m_bLineLimit);
pRender->DrawText(rc, GetText(), dwClrColor, m_sFontId, m_uTextStyle, 255, m_bLineLimit);
}

template<typename InheritType>
Expand Down Expand Up @@ -387,15 +387,15 @@ void LabelTemplate<InheritType>::SetStateTextColor(ControlStateType stateType, c
}

template<typename InheritType>
int LabelTemplate<InheritType>::GetFont() const
std::wstring LabelTemplate<InheritType>::GetFont() const
{
return m_iFont;
return m_sFontId;
}

template<typename InheritType>
void LabelTemplate<InheritType>::SetFont(int index)
void LabelTemplate<InheritType>::SetFont(const std::wstring& strFontId)
{
m_iFont = index;
m_sFontId = strFontId;
this->Invalidate();
}

Expand Down
26 changes: 13 additions & 13 deletions tool_kits/duilib/Control/RichEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ RichEdit::RichEdit() :
m_iCaretPosY(0),
m_iCaretWidth(0),
m_iCaretHeight(0),
m_iFont(0),
m_sFontId(),
m_iLimitText(0),
m_lTwhStyle(ES_MULTILINE),
m_textVerAlignType(kVerAlignTop),
Expand Down Expand Up @@ -1274,16 +1274,16 @@ void RichEdit::SetWordWrap(bool bWordWrap)
if( m_pTwh ) m_pTwh->SetWordWrap(bWordWrap);
}

int RichEdit::GetFont()
std::wstring RichEdit::GetFont() const
{
return m_iFont;
return m_sFontId;
}

void RichEdit::SetFont(int index)
void RichEdit::SetFont(const std::wstring& strFontId)
{
m_iFont = index;
m_sFontId = strFontId;
if( m_pTwh ) {
m_pTwh->SetFont(GlobalManager::GetFont(m_iFont));
m_pTwh->SetFont(GlobalManager::GetFont(m_sFontId));
}
}

Expand Down Expand Up @@ -2745,7 +2745,7 @@ void RichEdit::SetAttribute(const std::wstring& strName, const std::wstring& str
else if (strName == _T("prompttext")) SetPromptText(strValue);
else if (strName == _T("prompttextid")) SetPromptTextId(strValue);
else if (strName == _T("focusedimage")) SetFocusedImage(strValue);
else if (strName == _T("font")) SetFont(_ttoi(strValue.c_str()));
else if (strName == _T("font")) SetFont(strValue);
else if (strName == _T("text")) SetText(strValue.c_str());
else if (strName == _T("textid")) SetTextId(strValue.c_str());
else if (strName == _T("wanttab")) SetWantTab(strValue == _T("true"));
Expand Down Expand Up @@ -2899,7 +2899,7 @@ void RichEdit::PaintPromptText(IRenderContext* pRender)

DWORD dwClrColor = GlobalManager::GetTextColor(m_sPromptColor);
UINT dwStyle = DT_NOCLIP;
pRender->DrawText(rc, strPrompt, dwClrColor, m_iFont, dwStyle);
pRender->DrawText(rc, strPrompt, dwClrColor, m_sFontId, dwStyle);
}

std::wstring RichEdit::GetFocusedImage()
Expand Down Expand Up @@ -2995,23 +2995,23 @@ void RichEdit::AddLinkColorText(const std::wstring &str, const std::wstring &col
GetDefaultCharFormat(cf);
SetSelectionCharFormat(cf);
}
void RichEdit::AddLinkColorTextEx(const std::wstring& str, const std::wstring &color, const std::wstring &linkInfo, int font)
void RichEdit::AddLinkColorTextEx(const std::wstring& str, const std::wstring &color, const std::wstring &linkInfo, const std::wstring& strFontId)
{
if (!m_bRich || str.empty() || color.empty()) {
ASSERT(FALSE);
return;
}
int ifont = font >= 0 ? font : m_iFont;

std::string link;
std::string text;
std::string font_face;
StringHelper::UnicodeToMBCS(linkInfo, link);
StringHelper::UnicodeToMBCS(str, text);
auto hFont = GlobalManager::GetFont(ifont);
auto hFont = GlobalManager::GetFont(strFontId);
if (hFont == NULL)
hFont = GlobalManager::GetFont(m_iFont);
hFont = GlobalManager::GetFont(m_sFontId);
if (hFont == NULL)
hFont = GlobalManager::GetFont(0);
hFont = GlobalManager::GetFont(L"");
LOGFONT lf;
::GetObject(hFont, sizeof(LOGFONT), &lf);
StringHelper::UnicodeToMBCS(lf.lfFaceName, font_face);
Expand Down
8 changes: 4 additions & 4 deletions tool_kits/duilib/Control/RichEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ class UILIB_API RichEdit : public ScrollableBox
* @brief ��ȡ��ǰ���õ���������
* @return ����������������Ӧ global.xml �������˳��
*/
int GetFont();
std::wstring GetFont() const;

/**
* @brief ������������
* @param[in] index Ҫ���õ�������������Ӧ global.xml �������˳��
* @return ��
*/
void SetFont(int index);
void SetFont(const std::wstring& strFontId);
void SetFont(HFONT font);
/**
* @brief ��������������������
Expand Down Expand Up @@ -875,7 +875,7 @@ class UILIB_API RichEdit : public ScrollableBox
* @param[in] font ��������
* @return ��
*/
void AddLinkColorTextEx(const std::wstring& str, const std::wstring &color, const std::wstring &linkInfo = L"", int font = -1);
void AddLinkColorTextEx(const std::wstring& str, const std::wstring &color, const std::wstring &linkInfo = L"", const std::wstring& strFontId = L"");

/**
* @brief ����һ����Χ���� hittest �ж��Ƿ���������Ϣ
Expand Down Expand Up @@ -956,7 +956,7 @@ class UILIB_API RichEdit : public ScrollableBox
int m_iCaretPosY;
int m_iCaretWidth;
int m_iCaretHeight;
int m_iFont;
std::wstring m_sFontId;
int m_iLimitText;
LONG m_lTwhStyle;
VerAlignType m_textVerAlignType;
Expand Down
Loading