From 900db6dd70a09c840649cef4966ee620ca1e445e Mon Sep 17 00:00:00 2001 From: Nanako <469449812@qq.com> Date: Mon, 21 Apr 2025 10:39:32 +0800 Subject: [PATCH] =?UTF-8?q?TODO=20=E4=BC=98=E5=8C=96=E6=8E=A7=E4=BB=B6?= =?UTF-8?q?=E5=B8=83=E5=B1=80=E8=AF=AD=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/src/main.cpp | 10 ++++----- .../src/widget/leaf_widget/mtext_block.h | 21 ++++++++++++++----- src/mirage_widget/src/widget/mwidget.h | 4 +--- src/mirage_widget/src/widget/widget_new.h | 3 +++ 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/example/src/main.cpp b/example/src/main.cpp index d31474f..63624f6 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -65,9 +65,6 @@ int main(int argc, char* argv[]) { text_block->set_text(config_info_str); // text_block->set_text(U"Hello, World! 你好,世界!\n换行测试1111,测试测试测试测试,测试测试😀🐵🙏 😃🐵🙏"); - const auto& text_block2 = std::make_shared(); - text_block2->set_text(U"Hello, World!"); - const auto& window = mwindow::create({ 800, 600 }, L"Hello, World!"); window->set_content( mnew(mv_box) @@ -78,7 +75,8 @@ int main(int argc, char* argv[]) { [ mslot(mbutton) .margin({ 10 }) - .visibility(visibility_t::visible)(text_block) + .visibility(visibility_t::visible) + +text_block ], mslot(mv_box) @@ -88,7 +86,9 @@ int main(int argc, char* argv[]) { mslot(mbutton) .margin({ 10 }) .visibility(visibility_t::visible) - (text_block2) + +mnew(mtext_block) + ->set_text(U"Hello, World!") + ->set_font_size(24) ] ] ); diff --git a/src/mirage_widget/src/widget/leaf_widget/mtext_block.h b/src/mirage_widget/src/widget/leaf_widget/mtext_block.h index f702941..4b85045 100644 --- a/src/mirage_widget/src/widget/leaf_widget/mtext_block.h +++ b/src/mirage_widget/src/widget/leaf_widget/mtext_block.h @@ -6,31 +6,42 @@ class font_face_interface; class mtext_block : public mleaf_widget { public: + void on_paint(mirage_paint_context& in_context) override; - void set_text(const std::u32string& in_text) { + auto set_text(const std::u32string& in_text) { text_ = in_text; update_layout(); + using this_type = std::remove_reference_t; + return std::static_pointer_cast(shared_from_this()); } - void set_font(const std::shared_ptr& in_font) { + auto set_font(const std::shared_ptr& in_font) { font_ = in_font; update_layout(); + using this_type = std::remove_reference_t; + return std::static_pointer_cast(shared_from_this()); } - void set_font_size(float in_font_size) { + auto set_font_size(float in_font_size) { font_size_ = in_font_size; update_layout(); + using this_type = std::remove_reference_t; + return std::static_pointer_cast(shared_from_this()); } - void set_line_spacing(float in_line_spacing) { + auto set_line_spacing(float in_line_spacing) { line_spacing_ = in_line_spacing; update_layout(); + using this_type = std::remove_reference_t; + return std::static_pointer_cast(shared_from_this()); } - void set_max_width(float in_max_width) { + auto set_max_width(float in_max_width) { max_width_ = in_max_width; update_layout(); + using this_type = std::remove_reference_t; + return std::static_pointer_cast(shared_from_this()); } const auto& get_text() const { return text_; } diff --git a/src/mirage_widget/src/widget/mwidget.h b/src/mirage_widget/src/widget/mwidget.h index 492fff0..b285864 100644 --- a/src/mirage_widget/src/widget/mwidget.h +++ b/src/mirage_widget/src/widget/mwidget.h @@ -8,9 +8,7 @@ class mwindow; /** * @class mwidget - * @brief UI组件包装器 - * - * 对widget entity的封装,提供了组件的基本功能。 + * @brief UI组件的基类 */ class mwidget : public std::enable_shared_from_this { public: diff --git a/src/mirage_widget/src/widget/widget_new.h b/src/mirage_widget/src/widget/widget_new.h index 338516c..ad809ac 100644 --- a/src/mirage_widget/src/widget/widget_new.h +++ b/src/mirage_widget/src/widget/widget_new.h @@ -30,6 +30,9 @@ struct mwidget_decl { auto operator[](Args&&... in_args) { return std::static_pointer_cast((*widget_)[std::forward(in_args)...]); } + auto operator->() { + return widget_.get(); + } operator std::shared_ptr() const { return widget_; } std::shared_ptr widget_;