完善combobox控件的功能

This commit is contained in:
zhongyang219
2026-01-28 21:24:30 +08:00
parent 8785f64c5b
commit bf60a83239
11 changed files with 254 additions and 210 deletions
+12 -2
View File
@@ -23,11 +23,17 @@ UIColors CPlayerUIHelper::GetUIColors(bool dark, bool draw_alpha)
colors.color_text_lable = theApp.m_app_setting_data.theme_color.light2;
colors.color_text_2 = theApp.m_app_setting_data.theme_color.light1;
colors.color_text_heighlight = theApp.m_app_setting_data.theme_color.light2;
colors.color_text_disabled = GRAY(180);
colors.color_text_disabled = GRAY(200);
if (draw_alpha)
{
colors.color_back = GRAY(64);
colors.color_panel_back = GRAY(72);
}
else
{
colors.color_back = GRAY(48);
colors.color_panel_back = GRAY(56);
}
colors.color_lyric_back = theApp.m_app_setting_data.theme_color.dark3;
if (draw_alpha)
@@ -62,6 +68,10 @@ UIColors CPlayerUIHelper::GetUIColors(bool dark, bool draw_alpha)
colors.color_text_heighlight = theApp.m_app_setting_data.theme_color.dark1;
colors.color_text_disabled = GRAY(160);
colors.color_back = ColorTable::WHITE;
if (draw_alpha)
colors.color_panel_back = ColorTable::WHITE;
else
colors.color_panel_back = GRAY(240);
colors.color_lyric_back = theApp.m_app_setting_data.theme_color.light3;
colors.color_control_bar_back = theApp.m_app_setting_data.theme_color.light3;
colors.color_spectrum = theApp.m_app_setting_data.theme_color.original_color;
@@ -95,7 +105,7 @@ bool CPlayerUIHelper::IsMidiLyric()
bool CPlayerUIHelper::IsDrawStatusBar()
{
return theApp.m_app_setting_data.always_show_statusbar || CPlayer::GetInstance().m_loading || (theApp.IsMeidaLibUpdating() && theApp.m_media_update_para.num_added > 0)
/*|| CPlayer::GetInstance().GetABRepeatMode() != CPlayer::AM_NONE*/;
/*|| CPlayer::GetInstance().GetABRepeatMode() != CPlayer::AM_NONE*/;
}
+16 -15
View File
@@ -1,22 +1,23 @@
#pragma once
#include "ColorConvert.h"
struct UIColors //界面颜色
struct UIColors //界面颜色
{
COLORREF color_text; //文本颜色
COLORREF color_text_lable; //标签文本的颜色
COLORREF color_text_2; //歌词未播放文本的颜色
COLORREF color_text_heighlight; //鼠标指向时文本的颜色
COLORREF color_text; //文本颜色
COLORREF color_text_lable; //标签文本的颜色
COLORREF color_text_2; //歌词未播放文本的颜色
COLORREF color_text_heighlight; //鼠标指向时文本的颜色
COLORREF color_text_disabled; //禁用时的文本颜色
COLORREF color_back; //背景颜色
COLORREF color_lyric_back; //歌词界面背景颜色
COLORREF color_control_bar_back; //控制条背景颜色
COLORREF color_spectrum; //频谱分析柱形的颜色
COLORREF color_spectrum_cover; //有专辑封面时的频谱分析柱形的颜色
COLORREF color_progress_back; //进度条的背景颜色
COLORREF color_button_checked; //按钮选中状态的背景色
COLORREF color_button_pressed; //按钮按下的颜色
COLORREF color_button_hover; //按钮指向时的颜色
COLORREF color_back; //背景颜色
COLORREF color_panel_back; //面板的背景色
COLORREF color_lyric_back; //歌词界面背景颜色
COLORREF color_control_bar_back; //控制条背景颜色
COLORREF color_spectrum; //频谱分析柱形的颜色
COLORREF color_spectrum_cover; //有专辑封面时的频谱分析柱形的颜色
COLORREF color_progress_back; //进度条的背景颜色
COLORREF color_button_checked; //按钮选中状态的背景色
COLORREF color_button_pressed; //按钮按下的颜色
COLORREF color_button_hover; //按钮指向时的颜色
COLORREF color_stack_indicator; //staticElement指示器的颜色
COLORREF color_scrollbar_handle; //滚动条把手的颜色
COLORREF color_list_selected; //列表选中项的颜色
@@ -31,7 +32,7 @@ public:
static UIColors GetUIColors(bool dark, bool draw_alpha = true);
static bool IsMidiLyric(); //是否绘制MIDI音乐的歌词
static bool IsMidiLyric(); //是否绘制MIDI音乐的歌词
static bool IsDrawStatusBar(); //是否绘制状态栏
static double GetScrollTextPixel();
@@ -54,7 +54,8 @@ void UiElement::AbstractListElement::DrawScrollArea()
bool is_selected_item = false;
if (draw_hover_row_background)
{
is_selected_item = GetDisplayedIndexByPoint(m_mouse_pos) == i;
if (rect.PtInRect(m_mouse_pos))
is_selected_item = GetDisplayedIndexByPoint(m_mouse_pos) == i;
}
else
{
@@ -493,6 +494,13 @@ bool UiElement::AbstractListElement::MouseWheel(int delta, CPoint point)
return false;
}
bool UiElement::AbstractListElement::MouseLeave()
{
bool rtn = AbstractScrollArea::MouseLeave();
m_mouse_pos = CPoint(-1, -1);
return rtn;
}
bool UiElement::AbstractListElement::DoubleClick(CPoint point)
{
if (rect.PtInRect(point) && !scrollbar_rect.PtInRect(point) && GetItemSelected() >= 0)
+3 -1
View File
@@ -20,6 +20,7 @@ namespace UiElement
virtual bool RButtonUp(CPoint point) override;
virtual bool RButtonDown(CPoint point) override;
virtual bool MouseWheel(int delta, CPoint point) override;
virtual bool MouseLeave() override;
virtual bool DoubleClick(CPoint point) override;
void ShowContextMenu(CMenu* menu, CWnd* cmd_reciver);
virtual void ClearRect() override;
@@ -86,10 +87,11 @@ namespace UiElement
virtual void FromXmlNode(tinyxml2::XMLElement* xml_node);
int GetDisplayedIndexByPoint(CPoint point); //获取一个坐标所在的行号
private:
void DisplayRowToAbsoluteRow(int& row); //将显示的行号转换为绝对行号
void AbsoluteRowToDisplayRow(int& row); //将绝对行号转换为显示的行号
int GetDisplayedIndexByPoint(CPoint point);
protected:
int GetListIndexByPoint(CPoint point);
@@ -165,8 +165,7 @@ bool UiElement::AbstractScrollArea::MouseMove(CPoint point)
}
bool rtn = false;
if (hover)
rtn = Element::MouseMove(point);
rtn = Element::MouseMove(point);
if (last_hover && !hover)
{
Element::MouseLeave();
+38 -32
View File
@@ -24,7 +24,7 @@ void UiElement::ComboBox::Draw()
text_rect.right = icon_rect.left;
text_rect.left += ui->DPI(4);
std::wstring cur_text = GetCurString();
ui->GetDrawer().DrawWindowText(text_rect, cur_text.c_str(), ui->GetUIColors().color_text);
ui->GetDrawer().DrawWindowText(text_rect, cur_text.c_str(), IsEnable() ? ui->GetUIColors().color_text : ui->GetUIColors().color_text_disabled);
Element::Draw();
}
@@ -36,19 +36,20 @@ void UiElement::ComboBox::DrawTopMost()
//计算下拉列表的位置
rect_drop_list = rect;
rect_drop_list.top = rect.bottom;
const int drop_list_margin = ui->DPI(4);
//下拉列表的高度
int list_height = drop_list->GetRowCount() * drop_list->ItemHeight() + 1;
CCommon::SetNumRange(list_height, ui->DPI(30), ui->DPI(200));
int list_height = drop_list->GetRowCount() * drop_list->ItemHeight() + 2 * drop_list_margin + ui->DPI(1);
rect_drop_list.bottom = rect_drop_list.top + list_height;
//限制下拉列表中绘图区域内
CRect draw_rect = ui->GetClientDrawRect();
rect_drop_list = draw_rect & rect_drop_list;
////限制下拉列表中绘图区域内
//CRect draw_rect = ui->GetClientDrawRect();
//rect_drop_list = draw_rect & rect_drop_list;
drop_list->SetRect(rect_drop_list);
if (theApp.m_app_setting_data.button_round_corners)
ui->GetDrawer().DrawRoundRect(rect_drop_list, ui->GetUIColors().color_back, ui->CalculateRoundRectRadius(rect_drop_list), 255);
ui->GetDrawer().DrawRoundRect(rect_drop_list, ui->GetUIColors().color_panel_back, ui->CalculateRoundRectRadius(rect_drop_list), 255);
else
ui->GetDrawer().FillRect(rect_drop_list, ui->GetUIColors().color_back);
ui->GetDrawer().FillRect(rect_drop_list, ui->GetUIColors().color_panel_back);
rect_drop_list.DeflateRect(drop_list_margin, drop_list_margin);
drop_list->SetRect(rect_drop_list);
drop_list->Draw();
}
}
@@ -57,9 +58,6 @@ void UiElement::ComboBox::InitComplete()
{
CElementFactory factory;
drop_list = std::dynamic_pointer_cast<ListElement>(factory.CreateElement("listElement", ui));
drop_list->SetSelectionChangedTrigger([&](AbstractListElement* list_element) {
selection_changed = true;
});
drop_list->SetDrawAlternateBackground(false);
drop_list->SetDrawHoverRowBackground(true);
}
@@ -77,11 +75,6 @@ bool UiElement::ComboBox::LButtonUp(CPoint point)
if (show_drop_list && rect_drop_list.PtInRect(point))
{
drop_list->LButtonUp(point);
if (selection_changed)
{
OnSelChanged();
selection_changed = false;
}
return true;
}
@@ -106,8 +99,12 @@ bool UiElement::ComboBox::LButtonDown(CPoint point)
bool UiElement::ComboBox::MouseMove(CPoint point)
{
hover = (rect.PtInRect(point));
if (show_drop_list && rect_drop_list.PtInRect(point))
hover = (rect.PtInRect(point) && IsEnable());
bool drop_list_hover = show_drop_list && rect_drop_list.PtInRect(point);
if (last_drop_list_hover && !drop_list_hover)
drop_list->MouseLeave();
last_drop_list_hover = drop_list_hover;
if (drop_list_hover)
{
drop_list->MouseMove(point);
return true;
@@ -124,6 +121,27 @@ bool UiElement::ComboBox::MouseLeave()
return false;
}
void UiElement::ComboBox::TopMostClicked(CPoint point)
{
if (!rect.PtInRect(point) && IsShown() && IsEnable())
{
if (show_drop_list && rect_drop_list.PtInRect(point))
{
int selected_row = drop_list->GetDisplayedIndexByPoint(point);
drop_list->LButtonUp(point);
int cur_sel = GetCurSel();
SetCurSel(selected_row);
if (selected_row != cur_sel)
{
if (m_selection_changed_trigger)
m_selection_changed_trigger(this);
}
}
show_drop_list = false;
}
}
void UiElement::ComboBox::AddString(const std::wstring& str)
{
drop_list->AddRow(str);
@@ -149,19 +167,7 @@ std::wstring UiElement::ComboBox::GetCurString()
return drop_list->GetItemText(selected_row, 0);
}
void UiElement::ComboBox::SetSelectionChangedTrigger(std::function<void(AbstractListElement*)> func)
void UiElement::ComboBox::SetSelectionChangedTrigger(std::function<void(ComboBox*)> func)
{
m_selection_changed_trigger = func;
}
void UiElement::ComboBox::OnSelChanged()
{
//同步选中行和Highlight行
int selected_row = drop_list->GetItemSelected();
drop_list->SetHighlightRow(selected_row);
if (m_selection_changed_trigger)
m_selection_changed_trigger(drop_list.get());
show_drop_list = false;
}
+5 -6
View File
@@ -13,26 +13,25 @@ namespace UiElement
virtual bool LButtonDown(CPoint point) override;
virtual bool MouseMove(CPoint point) override;
virtual bool MouseLeave() override;
virtual void TopMostClicked(CPoint point) override;
void AddString(const std::wstring& str);
void SetCurSel(int index);
int GetCurSel();
std::wstring GetCurString();
void SetSelectionChangedTrigger(std::function<void(AbstractListElement*)> func);
protected:
void OnSelChanged();
void SetSelectionChangedTrigger(std::function<void(ComboBox*)> func);
protected:
bool show_drop_list{ false };
std::shared_ptr<ListElement> drop_list;
std::function<void(AbstractListElement*)> m_selection_changed_trigger;
std::function<void(ComboBox*)> m_selection_changed_trigger;
private:
bool hover{};
bool pressed{};
CRect rect_drop_list;
bool selection_changed{};
//bool selection_changed{};
bool last_drop_list_hover{};
};
}
+71 -71
View File
@@ -3,106 +3,106 @@
#include "UserUi.h"
CPlayerUIPanel::CPlayerUIPanel(CPlayerUIBase* ui, UINT res_id)
: m_ui(ui)
: m_ui(ui)
{
string xml = CCommon::GetTextResourceRawData(res_id);
if (!xml.empty())
LoadUIData(xml);
string xml = CCommon::GetTextResourceRawData(res_id);
if (!xml.empty())
LoadUIData(xml);
}
CPlayerUIPanel::CPlayerUIPanel(CPlayerUIBase* ui, const std::wstring file_name)
: m_ui(ui)
: m_ui(ui)
{
std::wstring file_path = theApp.m_local_dir + L"skins\\panels\\" + file_name;
std::string xml;
if (CCommon::GetFileContent(file_path.c_str(), xml))
LoadUIData(xml);
std::wstring file_path = theApp.m_local_dir + L"skins\\panels\\" + file_name;
std::string xml;
if (CCommon::GetFileContent(file_path.c_str(), xml))
LoadUIData(xml);
}
CPlayerUIPanel::CPlayerUIPanel(CPlayerUIBase* ui, std::shared_ptr<UiElement::Panel> panel_element)
: m_ui(ui)
: m_ui(ui)
{
m_root_element = panel_element;
m_root_element = panel_element;
}
void CPlayerUIPanel::LoadUIData(const std::string& xml_contents)
{
//读取xml
tinyxml2::XMLDocument doc;
auto rtn = doc.Parse(xml_contents.c_str(), xml_contents.size());
if (rtn == tinyxml2::XML_SUCCESS)
{
tinyxml2::XMLElement* root = doc.RootElement();
CTinyXml2Helper::IterateChildNode(root, [&](tinyxml2::XMLElement* xml_child) {
std::string item_name = CTinyXml2Helper::ElementName(xml_child);
//查找panel元素
if (item_name == "panel")
{
if (m_root_element == nullptr)
m_root_element = std::dynamic_pointer_cast<UiElement::Panel>(CUserUi::BuildUiElementFromXmlNode(xml_child, m_ui));
}
});
}
//读取xml
tinyxml2::XMLDocument doc;
auto rtn = doc.Parse(xml_contents.c_str(), xml_contents.size());
if (rtn == tinyxml2::XML_SUCCESS)
{
tinyxml2::XMLElement* root = doc.RootElement();
CTinyXml2Helper::IterateChildNode(root, [&](tinyxml2::XMLElement* xml_child) {
std::string item_name = CTinyXml2Helper::ElementName(xml_child);
//查找panel元素
if (item_name == "panel")
{
if (m_root_element == nullptr)
m_root_element = std::dynamic_pointer_cast<UiElement::Panel>(CUserUi::BuildUiElementFromXmlNode(xml_child, m_ui));
}
});
}
}
void CPlayerUIPanel::Draw()
{
if (m_root_element != nullptr)
{
CRect draw_rect = m_ui->GetClientDrawRect();
if (m_root_element != nullptr)
{
CRect draw_rect = m_ui->GetClientDrawRect();
//计算面板矩形区域
m_panel_rect = CalculatePanelRect();
//如果未通过代码获取面板的矩形区域,则根据ui计算面板区域
if (m_panel_rect.IsRectEmpty())
{
m_root_element->CalculateRect(draw_rect);
m_panel_rect = m_root_element->GetRect();
}
else
{
m_panel_rect &= draw_rect;
m_root_element->SetRect(m_panel_rect);
}
//计算面板矩形区域
m_panel_rect = CalculatePanelRect();
//如果未通过代码获取面板的矩形区域,则根据ui计算面板区域
if (m_panel_rect.IsRectEmpty())
{
m_root_element->CalculateRect(draw_rect);
m_panel_rect = m_root_element->GetRect();
}
else
{
m_panel_rect &= draw_rect;
m_root_element->SetRect(m_panel_rect);
}
//判断面板是否占满整个窗口
m_is_full_fill = (m_panel_rect.left == draw_rect.left) && (m_panel_rect.top == draw_rect.top) && (m_panel_rect.right == draw_rect.right) && (m_panel_rect.bottom == draw_rect.bottom);
//判断面板是否占满整个窗口
m_is_full_fill = (m_panel_rect.left == draw_rect.left) && (m_panel_rect.top == draw_rect.top) && (m_panel_rect.right == draw_rect.right) && (m_panel_rect.bottom == draw_rect.bottom);
//绘制一层半透明的黑色背景
if (!m_is_full_fill)
{
BYTE alpha = ALPHA_CHG(theApp.m_app_setting_data.background_transparency);
m_ui->GetDrawer().FillAlphaRect(draw_rect, m_ui->GetUIColors().color_back, alpha);
}
//绘制一层半透明的黑色背景
if (!m_is_full_fill)
{
BYTE alpha = ALPHA_CHG(theApp.m_app_setting_data.background_transparency);
m_ui->GetDrawer().FillAlphaRect(draw_rect, m_ui->GetUIColors().color_back, alpha);
}
//绘制面板背景
if (!IsFullFill())
{
BYTE alpha = 255;
if (m_ui->IsDrawBackgroundAlpha())
alpha = 255 - (255 - alpha) / 2;
//绘制面板背景
if (!IsFullFill())
{
BYTE alpha = 255;
if (m_ui->IsDrawBackgroundAlpha())
alpha = 255 - (255 - alpha) / 2;
CRect draw_rect = m_ui->GetClientDrawRect();
//当面板的四个边都没有帖靠UI绘图矩形区域时,才绘制圆角矩形
bool draw_round_background = m_panel_rect.left != draw_rect.left && m_panel_rect.top != draw_rect.top && m_panel_rect.right != draw_rect.right && m_panel_rect.bottom != draw_rect.bottom;
if (theApp.m_app_setting_data.button_round_corners && draw_round_background)
m_ui->GetDrawer().DrawRoundRect(m_panel_rect, m_ui->GetUIColors().color_back, m_ui->CalculateRoundRectRadius(m_panel_rect), alpha);
else
m_ui->GetDrawer().FillAlphaRect(m_panel_rect, m_ui->GetUIColors().color_back, alpha, true);
}
CRect draw_rect = m_ui->GetClientDrawRect();
//当面板的四个边都没有帖靠UI绘图矩形区域时,才绘制圆角矩形
bool draw_round_background = m_panel_rect.left != draw_rect.left && m_panel_rect.top != draw_rect.top && m_panel_rect.right != draw_rect.right && m_panel_rect.bottom != draw_rect.bottom;
if (theApp.m_app_setting_data.button_round_corners && draw_round_background)
m_ui->GetDrawer().DrawRoundRect(m_panel_rect, m_ui->GetUIColors().color_panel_back, m_ui->CalculateRoundRectRadius(m_panel_rect), alpha);
else
m_ui->GetDrawer().FillAlphaRect(m_panel_rect, m_ui->GetUIColors().color_panel_back, alpha, true);
}
//绘制面板
m_root_element->Draw();
m_root_element->DrawTopMost();
}
//绘制面板
m_root_element->Draw();
m_root_element->DrawTopMost();
}
}
std::shared_ptr<UiElement::Panel> CPlayerUIPanel::GetRootElement() const
{
return m_root_element;
return m_root_element;
}
bool CPlayerUIPanel::IsFullFill() const
{
return m_is_full_fill;
return m_is_full_fill;
}
+77 -57
View File
@@ -3,95 +3,115 @@
#include "UserUi.h"
CTestPanel::CTestPanel(CPlayerUIBase* ui)
: CPlayerUIPanel(ui, IDR_TEST_PANEL)
: CPlayerUIPanel(ui, IDR_TEST_PANEL)
{
m_ok_btn = m_root_element->FindElement<UiElement::Button>("okBtn");
if (m_ok_btn != nullptr)
m_ok_btn->SetClickedTrigger([&](UiElement::Button* sender) { OnOkClicked(sender); });
m_ok_btn = m_root_element->FindElement<UiElement::Button>("okBtn");
if (m_ok_btn != nullptr)
m_ok_btn->SetClickedTrigger([&](UiElement::Button* sender) { OnOkClicked(sender); });
m_cancel_btn = m_root_element->FindElement<UiElement::Button>("cancelBtn");
if (m_cancel_btn != nullptr)
m_cancel_btn->SetClickedTrigger([&](UiElement::Button* sender) { OnCancelClicked(sender); });
m_cancel_btn = m_root_element->FindElement<UiElement::Button>("cancelBtn");
if (m_cancel_btn != nullptr)
m_cancel_btn->SetClickedTrigger([&](UiElement::Button* sender) { OnCancelClicked(sender); });
m_check_box1 = m_root_element->FindElement<UiElement::CheckBox>("checkbox1");
if (m_check_box1 != nullptr)
m_check_box1->SetClickedTrigger([&](UiElement::AbstractToggleButton* sender) { OnCheckBox1Clicked(sender); });
m_check_box1 = m_root_element->FindElement<UiElement::CheckBox>("checkbox1");
if (m_check_box1 != nullptr)
m_check_box1->SetClickedTrigger([&](UiElement::AbstractToggleButton* sender) { OnCheckBox1Clicked(sender); });
m_toggle_btn = m_root_element->FindElement<UiElement::ToggleSettingGroup>("toggleBtn1")->GetToggleBtn();
if (m_toggle_btn != nullptr)
m_toggle_btn->SetClickedTrigger([&](UiElement::AbstractToggleButton* sender) { OnToggleBtnClicked(sender); });
m_toggle_btn->SetChecked(true);
m_toggle_btn = m_root_element->FindElement<UiElement::ToggleSettingGroup>("toggleBtn1")->GetToggleBtn();
if (m_toggle_btn != nullptr)
m_toggle_btn->SetClickedTrigger([&](UiElement::AbstractToggleButton* sender) { OnToggleBtnClicked(sender); });
m_toggle_btn->SetChecked(true);
m_radio1 = m_root_element->FindElement<UiElement::RadioButton>("radio1");
m_radio2 = m_root_element->FindElement<UiElement::RadioButton>("radio2");
m_toggle_group2 = m_root_element->FindElement<UiElement::ToggleSettingGroup>("toggleBtn2");
m_radio1 = m_root_element->FindElement<UiElement::RadioButton>("radio1");
m_radio2 = m_root_element->FindElement<UiElement::RadioButton>("radio2");
m_toggle_group2 = m_root_element->FindElement<UiElement::ToggleSettingGroup>("toggleBtn2");
m_combobox1 = m_root_element->FindElement<UiElement::ComboBox>("combobox1");
m_combobox1->AddString(L"测试下拉项1");
m_combobox1->AddString(L"测试下拉项2");
m_combobox1->AddString(L"测试下拉项3");
m_combobox1->SetCurSel(0);
m_combobox1 = m_root_element->FindElement<UiElement::ComboBox>("combobox1");
m_combobox1->SetSelectionChangedTrigger([&](UiElement::ComboBox* sender) {
OnComboboxSelChanged(sender);
});
m_combobox1->AddString(L"测试下拉项1");
m_combobox1->AddString(L"测试下拉项2");
m_combobox1->AddString(L"测试下拉项3");
m_combobox1->SetCurSel(0);
m_text1 = m_root_element->FindElement<UiElement::Text>("text1");
m_text2 = m_root_element->FindElement<UiElement::Text>("text2");
m_list1 = m_root_element->FindElement<UiElement::ListElement>("list1");
m_list1->SetColumnCount(2);
m_list1->SetColumnWidth(0, ui->DPI(80));
m_tip_info_text = m_root_element->FindElement<UiElement::Text>("tipInfoText");
if (m_list1 != nullptr)
{
m_list1 = m_root_element->FindElement<UiElement::ListElement>("list1");
m_list1->SetColumnCount(2);
m_list1->SetColumnWidth(0, ui->DPI(80));
}
auto* add_btn = m_root_element->FindElement<UiElement::Button>("addBtn");
add_btn->SetClickedTrigger([&](UiElement::Button* sender) { OnAddClicked(sender); });
auto* del_btn = m_root_element->FindElement<UiElement::Button>("deleteBtn");
del_btn->SetClickedTrigger([&](UiElement::Button* sender) { OnDeleteClicked(sender); });
auto* add_btn = m_root_element->FindElement<UiElement::Button>("addBtn");
if (add_btn != nullptr)
add_btn->SetClickedTrigger([&](UiElement::Button* sender) { OnAddClicked(sender); });
auto* del_btn = m_root_element->FindElement<UiElement::Button>("deleteBtn");
if (del_btn != nullptr)
del_btn->SetClickedTrigger([&](UiElement::Button* sender) { OnDeleteClicked(sender); });
}
void CTestPanel::OnOkClicked(UiElement::Button* sender)
{
m_ui->ShowUiTipInfo(L"点击了应用按钮。");
m_ui->ShowUiTipInfo(L"点击了应用按钮。");
}
void CTestPanel::OnCancelClicked(UiElement::Button* sender)
{
CUserUi* user_ui = dynamic_cast<CUserUi*>(m_ui);
user_ui->ClosePanel();
CUserUi* user_ui = dynamic_cast<CUserUi*>(m_ui);
user_ui->ClosePanel();
}
void CTestPanel::OnCheckBox1Clicked(UiElement::AbstractToggleButton* sender)
{
bool checked = m_check_box1->Checked();
if (checked)
m_text1->SetText(_T("复选框已勾选。"));
else
m_text1->SetText(_T("复选框取消勾选。"));
bool checked = m_check_box1->Checked();
if (checked)
m_tip_info_text->SetText(_T("复选框已勾选。"));
else
m_tip_info_text->SetText(_T("复选框取消勾选。"));
}
void CTestPanel::OnToggleBtnClicked(UiElement::AbstractToggleButton* sender)
{
bool checked = sender->Checked();
if (checked)
m_text2->SetText(_T("控件已启用"));
else
m_text2->SetText(_T("控件已禁用"));
bool checked = sender->Checked();
if (checked)
m_tip_info_text->SetText(_T("控件已启用"));
else
m_tip_info_text->SetText(_T("控件已禁用"));
//设置控件启用禁用状态
m_check_box1->SetEnable(checked);
m_radio1->SetEnable(checked);
m_radio2->SetEnable(checked);
m_toggle_group2->SetEnable(checked);
//设置控件启用禁用状态
m_check_box1->SetEnable(checked);
m_radio1->SetEnable(checked);
m_radio2->SetEnable(checked);
m_toggle_group2->SetEnable(checked);
m_combobox1->SetEnable(checked);
}
void CTestPanel::OnAddClicked(UiElement::Button* sender)
{
std::map<int, std::wstring> row_data;
int row = m_list1->GetRowCount();
row_data[0] = std::to_wstring(row + 1);
row_data[1] = L"第" + std::to_wstring(row + 1) + L"行";
m_list1->AddRow(row_data);
if (m_list1 != nullptr)
{
std::map<int, std::wstring> row_data;
int row = m_list1->GetRowCount();
row_data[0] = std::to_wstring(row + 1);
row_data[1] = L"第" + std::to_wstring(row + 1) + L"行";
m_list1->AddRow(row_data);
}
}
void CTestPanel::OnDeleteClicked(UiElement::Button* sender)
{
int row = m_list1->GetItemSelected();
if (row >= 0 && row < m_list1->GetRowCount())
m_list1->DeleteRow(row);
if (m_list1 != nullptr)
{
int row = m_list1->GetItemSelected();
if (row >= 0 && row < m_list1->GetRowCount())
m_list1->DeleteRow(row);
}
}
void CTestPanel::OnComboboxSelChanged(UiElement::ComboBox* sender)
{
std::wstring str_combo = m_combobox1->GetCurString();
m_tip_info_text->SetText(L"下拉框当前选择:" + str_combo);
}
+18 -18
View File
@@ -12,28 +12,28 @@
class CTestPanel : public CPlayerUIPanel
{
public:
CTestPanel(CPlayerUIBase* ui);
CTestPanel(CPlayerUIBase* ui);
private:
void OnOkClicked(UiElement::Button* sender);
void OnCancelClicked(UiElement::Button* sender);
void OnCheckBox1Clicked(UiElement::AbstractToggleButton* sender);
void OnToggleBtnClicked(UiElement::AbstractToggleButton* sender);
void OnAddClicked(UiElement::Button* sender);
void OnDeleteClicked(UiElement::Button* sender);
void OnOkClicked(UiElement::Button* sender);
void OnCancelClicked(UiElement::Button* sender);
void OnCheckBox1Clicked(UiElement::AbstractToggleButton* sender);
void OnToggleBtnClicked(UiElement::AbstractToggleButton* sender);
void OnAddClicked(UiElement::Button* sender);
void OnDeleteClicked(UiElement::Button* sender);
void OnComboboxSelChanged(UiElement::ComboBox* sender);
private:
UiElement::Button* m_ok_btn{};
UiElement::Button* m_cancel_btn{};
UiElement::ToggleButton* m_toggle_btn{};
UiElement::CheckBox* m_check_box1{};
UiElement::RadioButton* m_radio1{};
UiElement::RadioButton* m_radio2{};
UiElement::ToggleSettingGroup* m_toggle_group2{};
UiElement::Text* m_text1{};
UiElement::Text* m_text2{};
UiElement::ComboBox* m_combobox1{};
UiElement::Button* m_ok_btn{};
UiElement::Button* m_cancel_btn{};
UiElement::ToggleButton* m_toggle_btn{};
UiElement::CheckBox* m_check_box1{};
UiElement::RadioButton* m_radio1{};
UiElement::RadioButton* m_radio2{};
UiElement::ToggleSettingGroup* m_toggle_group2{};
UiElement::Text* m_tip_info_text{};
UiElement::ComboBox* m_combobox1{};
UiElement::ListElement* m_list1{};
UiElement::ListElement* m_list1{};
};
+4 -5
View File
@@ -4,8 +4,10 @@
<scrollArea>
<verticalLayout>
<toggleSettingGroup id="toggleBtn1" height="60" icon="setting" mainText="启用控件" subText="测试文本" />
<comboBox id="combobox1" margin-top="4" height="28"/>
<horizontalLayout height="24">
<horizontalLayout height="24" margin-top="4">
<checkBox id="checkbox1" text="测试复选框"/>
<placeHolder/>
</horizontalLayout>
@@ -17,7 +19,6 @@
<toggleSettingGroup id="toggleBtn2" margin-top="4" height="60" icon="setting" mainText="主要文本" subText="次要文本" />
<comboBox id="combobox1" margin-top="4" height="28"/>
<horizontalLayout margin-top="4" height="100">
<rectangle theme_color="false">
@@ -31,12 +32,10 @@
</horizontalLayout>
<placeHolder/>
<text id="text1" type="userDefine" height="20"/>
<text id="text2" type="userDefine" height="20"/>
</verticalLayout>
</scrollArea>
<horizontalLayout height="28" margin-top="8">
<placeHolder/>
<text id="tipInfoText" type="userDefine" height="20"/>
<button id="okBtn" icon="ok" text="%(TXT_APPLY)" height="28" show_text="true"/>
<button id="cancelBtn" icon="cancel" text="%(TXT_CLOSE)" show_text="true"/>
</horizontalLayout>