aboutsummaryrefslogtreecommitdiff
path: root/src/ui/controls/list_item.cpp
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2018-11-28 19:32:58 +0800
committerGitHub <noreply@github.com>2018-11-28 19:32:58 +0800
commitdd75868a05cfc9d71b26f1197022c03ba481fe33 (patch)
tree6f50579da8be5b6be8792b0d832b76ba822c2760 /src/ui/controls/list_item.cpp
parentee22597122612cd75fe62f5d808cb51478373fad (diff)
parentd98e9ef82be277190c883e4ee7547516dbd620b6 (diff)
downloadcru-dd75868a05cfc9d71b26f1197022c03ba481fe33.tar.gz
cru-dd75868a05cfc9d71b26f1197022c03ba481fe33.tar.bz2
cru-dd75868a05cfc9d71b26f1197022c03ba481fe33.zip
Merge pull request #30 from crupest/routed-event
Develop routed events.
Diffstat (limited to 'src/ui/controls/list_item.cpp')
-rw-r--r--src/ui/controls/list_item.cpp65
1 files changed, 33 insertions, 32 deletions
diff --git a/src/ui/controls/list_item.cpp b/src/ui/controls/list_item.cpp
index bf61010d..8234da30 100644
--- a/src/ui/controls/list_item.cpp
+++ b/src/ui/controls/list_item.cpp
@@ -15,6 +15,39 @@ namespace cru::ui::controls
brushes_[State::Hover] .fill_brush = predefine_resources->list_item_hover_fill_brush;
brushes_[State::Select].border_brush = predefine_resources->list_item_select_border_brush;
brushes_[State::Select].fill_brush = predefine_resources->list_item_select_fill_brush;
+
+ draw_foreground_event.AddHandler([this](events::DrawEventArgs& args)
+ {
+ const auto device_context = args.GetDeviceContext();
+ const auto rect = Rect(Point::Zero(), GetRect(RectRange::Padding).GetSize());
+ device_context->FillRectangle(Convert(rect), brushes_[state_].fill_brush.Get());
+ device_context->DrawRectangle(Convert(rect.Shrink(Thickness(0.5))), brushes_[state_].border_brush.Get(), 1);
+ });
+
+ mouse_enter_event.direct.AddHandler([this](events::MouseEventArgs& args)
+ {
+ if (GetState() == State::Select)
+ return;
+
+ if (IsAnyMouseButtonDown())
+ return;
+
+ SetState(State::Hover);
+ });
+
+ mouse_leave_event.direct.AddHandler([this](events::MouseEventArgs& args)
+ {
+ if (GetState() == State::Select)
+ return;
+
+ SetState(State::Normal);
+ });
+
+ mouse_click_event.direct.AddHandler([this](events::MouseButtonEventArgs& args)
+ {
+ if (args.GetMouseButton() == MouseButton::Left)
+ SetState(State::Select);
+ });
}
StringView ListItem::GetControlType() const
@@ -27,36 +60,4 @@ namespace cru::ui::controls
state_ = state;
InvalidateDraw();
}
-
- void ListItem::OnDrawForeground(ID2D1DeviceContext* device_context)
- {
- const auto rect = Rect(Point::Zero(), GetRect(RectRange::Padding).GetSize());
- device_context->FillRectangle(Convert(rect), brushes_[state_].fill_brush.Get());
- device_context->DrawRectangle(Convert(rect.Shrink(Thickness(0.5))), brushes_[state_].border_brush.Get(), 1);
- }
-
- void ListItem::OnMouseEnterCore(events::MouseEventArgs& args)
- {
- if (GetState() == State::Select)
- return;
-
- if (IsAnyMouseButtonDown())
- return;
-
- SetState(State::Hover);
- }
-
- void ListItem::OnMouseLeaveCore(events::MouseEventArgs& args)
- {
- if (GetState() == State::Select)
- return;
-
- SetState(State::Normal);
- }
-
- void ListItem::OnMouseClickCore(events::MouseButtonEventArgs& args)
- {
- if (args.GetMouseButton() == MouseButton::Left)
- SetState(State::Select);
- }
}