diff options
author | 杨宇千 <crupest@outlook.com> | 2018-11-10 22:39:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-10 22:39:26 +0800 |
commit | 8b04c0dd788be75c2dd7d8f58aebc7d6bf6752df (patch) | |
tree | 2d00b4f6a7af93a13d271d78e6ef682c335c91c7 /src/ui/controls/list_item.cpp | |
parent | 7c2fb4578b6997b5ab0d98121cda253f734139c1 (diff) | |
parent | b2eced8d9719eb00796c2674fc2c23ab0c9bbdbf (diff) | |
download | cru-8b04c0dd788be75c2dd7d8f58aebc7d6bf6752df.tar.gz cru-8b04c0dd788be75c2dd7d8f58aebc7d6bf6752df.tar.bz2 cru-8b04c0dd788be75c2dd7d8f58aebc7d6bf6752df.zip |
Merge pull request #11 from crupest/listitem
Add ListItem.
Diffstat (limited to 'src/ui/controls/list_item.cpp')
-rw-r--r-- | src/ui/controls/list_item.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/ui/controls/list_item.cpp b/src/ui/controls/list_item.cpp new file mode 100644 index 00000000..bdd44273 --- /dev/null +++ b/src/ui/controls/list_item.cpp @@ -0,0 +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); + } +} |