From ad29543fe081d2a0a5e6737f9073399e4e91383f Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 19 Mar 2020 19:11:04 +0800 Subject: ... --- include/cru/ui/controls/base.hpp | 24 ++++++++++++++++++++++++ include/cru/ui/controls/button.hpp | 20 +------------------- include/cru/ui/controls/text_block.hpp | 2 +- include/cru/ui/controls/text_box.hpp | 15 +++++++++++++++ 4 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 include/cru/ui/controls/base.hpp (limited to 'include/cru/ui/controls') diff --git a/include/cru/ui/controls/base.hpp b/include/cru/ui/controls/base.hpp new file mode 100644 index 00000000..ebe9cdda --- /dev/null +++ b/include/cru/ui/controls/base.hpp @@ -0,0 +1,24 @@ +#pragma once +#include "../base.hpp" + +namespace cru::ui::controls { +using ButtonStateStyle = BorderStyle; + +struct ButtonStyle { + // corresponds to ClickState::None + ButtonStateStyle normal; + // corresponds to ClickState::Hover + ButtonStateStyle hover; + // corresponds to ClickState::Press + ButtonStateStyle press; + // corresponds to ClickState::PressInactive + ButtonStateStyle press_cancel; +}; + +struct TextBoxBorderStyle { + BorderStyle normal; + BorderStyle hover; + BorderStyle focus; + BorderStyle focus_hover; +}; +} // namespace cru::ui::controls diff --git a/include/cru/ui/controls/button.hpp b/include/cru/ui/controls/button.hpp index a95b75ce..fb636a33 100644 --- a/include/cru/ui/controls/button.hpp +++ b/include/cru/ui/controls/button.hpp @@ -1,28 +1,10 @@ #pragma once #include "../content_control.hpp" +#include "base.hpp" #include "../click_detector.hpp" namespace cru::ui::controls { -struct ButtonStateStyle { - std::shared_ptr border_brush; - Thickness border_thickness; - CornerRadius border_radius; - std::shared_ptr foreground_brush; - std::shared_ptr background_brush; -}; - -struct ButtonStyle { - // corresponds to ClickState::None - ButtonStateStyle normal; - // corresponds to ClickState::Hover - ButtonStateStyle hover; - // corresponds to ClickState::Press - ButtonStateStyle press; - // corresponds to ClickState::PressInactive - ButtonStateStyle press_cancel; -}; - class Button : public ContentControl { public: static constexpr std::string_view control_type = "Button"; diff --git a/include/cru/ui/controls/text_block.hpp b/include/cru/ui/controls/text_block.hpp index 701f946f..ec61a08c 100644 --- a/include/cru/ui/controls/text_block.hpp +++ b/include/cru/ui/controls/text_block.hpp @@ -30,7 +30,7 @@ class TextBlock : public NoChildControl { render::TextRenderObject* GetTextRenderObject(); render::CanvasRenderObject* GetCaretRenderObject(); - platform::graph::IBrush* GetCaretBrush(); + std::shared_ptr GetCaretBrush(); private: std::unique_ptr root_render_object_; diff --git a/include/cru/ui/controls/text_box.hpp b/include/cru/ui/controls/text_box.hpp index 58179a57..4a4ed6e7 100644 --- a/include/cru/ui/controls/text_box.hpp +++ b/include/cru/ui/controls/text_box.hpp @@ -1,7 +1,11 @@ #pragma once #include "../no_child_control.hpp" +#include "base.hpp" namespace cru::ui::controls { +template +class TextControlService; + class TextBox : public NoChildControl { public: static constexpr std::string_view control_type = "TextBox"; @@ -17,11 +21,22 @@ class TextBox : public NoChildControl { std::string_view GetControlType() const final { return control_type; } + render::TextRenderObject* GetTextRenderObject(); + render::CanvasRenderObject* GetCaretRenderObject(); + std::shared_ptr GetCaretBrush(); + + const TextBoxBorderStyle& GetBorderStyle(); + void SetBorderStyle(TextBoxBorderStyle border_style); + private: std::unique_ptr border_render_object_; std::unique_ptr stack_layout_render_object_; std::unique_ptr text_render_object_; std::unique_ptr caret_render_object_; + std::shared_ptr caret_brush_; + TextBoxBorderStyle border_style_; + + std::unique_ptr> service_; }; } // namespace cru::ui::controls -- cgit v1.2.3