diff options
author | crupest <crupest@outlook.com> | 2022-03-02 22:07:33 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-03-02 22:07:33 +0800 |
commit | 57353bd3acd97957cb5f970016fec52977cc6e95 (patch) | |
tree | 6e47a50f33466f7bcdce7c7aa9bf15b82fe4a58a /src/ui/controls | |
parent | 7adfe813c23d20abe936aa0624fd68e0112717b3 (diff) | |
download | cru-57353bd3acd97957cb5f970016fec52977cc6e95.tar.gz cru-57353bd3acd97957cb5f970016fec52977cc6e95.tar.bz2 cru-57353bd3acd97957cb5f970016fec52977cc6e95.zip |
...
Diffstat (limited to 'src/ui/controls')
-rw-r--r-- | src/ui/controls/IconButton.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/ui/controls/IconButton.cpp b/src/ui/controls/IconButton.cpp new file mode 100644 index 00000000..01ecabdd --- /dev/null +++ b/src/ui/controls/IconButton.cpp @@ -0,0 +1,50 @@ +#include "cru/ui/controls/IconButton.h" + +#include "../Helper.h" +#include "cru/platform/graphics/Factory.h" +#include "cru/platform/graphics/Geometry.h" +#include "cru/ui/ThemeManager.h" + +namespace cru::ui::controls { +IconButton::IconButton() + : container_render_object_(new render::BorderRenderObject()), + geometry_render_object_(new render::GeometryRenderObject()), + click_detector_(this) { + container_render_object_->SetChild(geometry_render_object_.get()); + container_render_object_->SetAttachedControl(this); + geometry_render_object_->SetAttachedControl(this); + + container_render_object_->SetBorderEnabled(true); + GetStyleRuleSet()->SetParent( + ThemeManager::GetInstance()->GetResourceStyleRuleSet( + u"icon-button.style")); +} + +IconButton::IconButton(StringView icon_svg_path_data_string, + const Rect& view_port) + : IconButton() { + SetIconWithSvgPathDataString(icon_svg_path_data_string, view_port); +} + +IconButton::~IconButton() {} + +void IconButton::SetIconFillColor(const Color& color) { + SetIconFillBrush(GetGraphicsFactory()->CreateSolidColorBrush(color)); +} + +void IconButton::SetIconWithSvgPathDataString( + StringView icon_svg_path_data_string, const Rect& view_port) { + SetIconGeometry(platform::graphics::CreateGeometryFromSvgPathData( + GetGraphicsFactory(), icon_svg_path_data_string), + view_port); +} + +void IconButton::SetIconWithSvgPathDataStringResourceKey( + StringView icon_svg_path_data_string_resource_key, const Rect& view_port) { + SetIconWithSvgPathDataString( + ThemeManager::GetInstance()->GetResourceString( + icon_svg_path_data_string_resource_key.ToString()), + view_port); +} + +} // namespace cru::ui::controls |