diff options
author | crupest <crupest@outlook.com> | 2018-11-10 21:53:33 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-11-10 21:53:33 +0800 |
commit | e5513daa53cb958b0c83d575c440f40aaf40f562 (patch) | |
tree | c6782f0cbfe4eca466f13ef571338e6b55342860 /src/ui/controls/list_item.cpp | |
parent | cfcd03f564e82419345a7a6900fdc17c5b8c2631 (diff) | |
download | cru-e5513daa53cb958b0c83d575c440f40aaf40f562.tar.gz cru-e5513daa53cb958b0c83d575c440f40aaf40f562.tar.bz2 cru-e5513daa53cb958b0c83d575c440f40aaf40f562.zip |
...
Diffstat (limited to 'src/ui/controls/list_item.cpp')
-rw-r--r-- | src/ui/controls/list_item.cpp | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/src/ui/controls/list_item.cpp b/src/ui/controls/list_item.cpp index 25dd49a8..bdd44273 100644 --- a/src/ui/controls/list_item.cpp +++ b/src/ui/controls/list_item.cpp @@ -1,6 +1,62 @@ #include "list_item.hpp" +#include "ui/ui_manager.hpp" +#include "ui/convert_util.hpp" + namespace cru::ui::controls { - + ListItem::ListItem() : Control(true) + { + const auto predefine_resources = UiManager::GetInstance()->GetPredefineResources(); + + brushes_[State::Normal].border_brush = predefine_resources->list_item_normal_border_brush; + brushes_[State::Normal].fill_brush = predefine_resources->list_item_normal_fill_brush; + brushes_[State::Hover] .border_brush = predefine_resources->list_item_hover_border_brush; + 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; + } + + StringView ListItem::GetControlType() const + { + return control_type; + } + + void ListItem::SetState(const State state) + { + state_ = state; + Repaint(); + } + + 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); + } } |