mirror of
https://github.com/zhongyang219/MusicPlayer2.git
synced 2026-10-17 05:20:33 +08:00
ComboBox下拉列表限制在窗口客户区域,修正当ComboBox下拉列表出现滚动条时拖动滚动条的行为不正常的问题
This commit is contained in:
@@ -64,7 +64,7 @@ void UiElement::AbstractListElement::DrawScrollArea()
|
||||
bool is_selected_item = false;
|
||||
if (draw_hover_row_background)
|
||||
{
|
||||
if (rect.PtInRect(m_mouse_pos))
|
||||
if (m_client_area_rect.PtInRect(m_mouse_pos))
|
||||
is_selected_item = GetDisplayedIndexByPoint(m_mouse_pos) == i;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -14,6 +14,7 @@ void UiElement::AbstractScrollArea::Draw()
|
||||
RestrictOffset();
|
||||
m_scroll_area_rect = rect;
|
||||
m_scroll_area_rect.right -= SCROLLBAR_WIDTH;
|
||||
m_client_area_rect = m_scroll_area_rect;
|
||||
m_scroll_area_rect.bottom = m_scroll_area_rect.top + GetScrollAreaHeight();
|
||||
m_scroll_area_rect.MoveToY(m_scroll_area_rect.top - scroll_offset);
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace UiElement
|
||||
|
||||
protected:
|
||||
CRect m_scroll_area_rect; //滚动区域的矩形区域
|
||||
CRect m_client_area_rect; //获取客户区域的矩形(不包含滚动条,不包含控件外区域)
|
||||
|
||||
bool mouse_pressed{ }; //鼠标左键是否按下
|
||||
bool hover{}; //指标指向播放列表区域
|
||||
|
||||
@@ -40,9 +40,9 @@ void UiElement::ComboBox::DrawTopMost()
|
||||
//下拉列表的高度
|
||||
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;
|
||||
|
||||
if (theApp.m_app_setting_data.button_round_corners)
|
||||
ui->GetDrawer().DrawRoundRect(rect_drop_list, ui->GetUIColors().color_panel_back, ui->CalculateRoundRectRadius(rect_drop_list), 255);
|
||||
@@ -94,16 +94,6 @@ bool UiElement::ComboBox::LButtonDown(CPoint point)
|
||||
|
||||
bool UiElement::ComboBox::MouseMove(CPoint 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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -123,18 +113,25 @@ bool UiElement::ComboBox::GlobalLButtonUp(CPoint point)
|
||||
{
|
||||
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 (drop_list->GetScrollAreaRect().PtInRect(point))
|
||||
{
|
||||
if (m_selection_changed_trigger)
|
||||
m_selection_changed_trigger(this);
|
||||
int selected_row = drop_list->GetDisplayedIndexByPoint(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;
|
||||
}
|
||||
rtn = true;
|
||||
}
|
||||
show_drop_list = false;
|
||||
else
|
||||
{
|
||||
show_drop_list = false;
|
||||
}
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
@@ -149,6 +146,21 @@ bool UiElement::ComboBox::GlobalLButtonDown(CPoint point)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UiElement::ComboBox::GlobalMouseMove(CPoint 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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void UiElement::ComboBox::AddString(const std::wstring& str)
|
||||
{
|
||||
drop_list->AddRow(str);
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace UiElement
|
||||
virtual bool MouseLeave() override;
|
||||
virtual bool GlobalLButtonUp(CPoint point) override;
|
||||
virtual bool GlobalLButtonDown(CPoint point) override;
|
||||
virtual bool GlobalMouseMove(CPoint point) override;
|
||||
|
||||
void AddString(const std::wstring& str);
|
||||
void SetCurSel(int index);
|
||||
|
||||
@@ -158,6 +158,16 @@ bool UiElement::Element::GlobalLButtonDown(CPoint point)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UiElement::Element::GlobalMouseMove(CPoint point)
|
||||
{
|
||||
for (auto& child : childLst)
|
||||
{
|
||||
if (child->GlobalMouseMove(point))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
UiElement::Element* UiElement::Element::RootElement()
|
||||
{
|
||||
Element* ele{ this };
|
||||
|
||||
@@ -70,6 +70,7 @@ namespace UiElement
|
||||
virtual void ClearRect();
|
||||
virtual bool GlobalLButtonUp(CPoint point); //响应全局鼠标左键抬起事件
|
||||
virtual bool GlobalLButtonDown(CPoint point); //响应全局鼠标左键按下事件
|
||||
virtual bool GlobalMouseMove(CPoint point); //响应全局鼠标移动事件
|
||||
|
||||
//遍历所有界面元素
|
||||
//visible_only为true时,遇到stackElement时,只遍历stackElement下面可见的子节点
|
||||
|
||||
@@ -33,6 +33,9 @@ CTestPanel::CTestPanel(CPlayerUIBase* ui)
|
||||
m_combobox1->AddString(L"测试下拉项1");
|
||||
m_combobox1->AddString(L"测试下拉项2");
|
||||
m_combobox1->AddString(L"测试下拉项3");
|
||||
m_combobox1->AddString(L"测试下拉项4");
|
||||
m_combobox1->AddString(L"测试下拉项5");
|
||||
m_combobox1->AddString(L"测试下拉项6");
|
||||
m_combobox1->SetCurSel(0);
|
||||
|
||||
m_tip_info_text = m_root_element->FindElement<UiElement::Text>("tipInfoText");
|
||||
|
||||
@@ -380,6 +380,8 @@ bool CUserUi::MouseMove(CPoint point)
|
||||
{
|
||||
bool mouse_leave = false;
|
||||
auto root_element = GetMouseEventResponseElement();
|
||||
if (root_element->GlobalMouseMove(point))
|
||||
return true;
|
||||
if (!CPlayerUIBase::MouseMove(point))
|
||||
{
|
||||
bool mouse_in_draw_area{ !CPlayerUIBase::PointInMenubarArea(point) && !CPlayerUIBase::PointInTitlebarArea(point) };
|
||||
|
||||
Reference in New Issue
Block a user