diff --git a/example/src/main.cpp b/example/src/main.cpp index 8b114eb..f1abcda 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -68,21 +68,19 @@ int main(int argc, char* argv[]) { const auto& text_block2 = std::make_shared(); text_block2->set_text(U"Hello, World!"); - auto button = std::make_shared(); - button->push_slot( + auto button = mnew(mbutton) + [ mslot(mbutton) - .margin({10}) - .visibility(visibility_t::visible) - (text_block) - ); + .margin({ 10 }) + .visibility(visibility_t::visible)(text_block) + ]; - const auto button2 = std::make_shared(); - button2->push_slot( + auto button2 = mnew(mbutton) + [ mslot(mbutton) - .margin({10}) - .visibility(visibility_t::visible) - (text_block2) - ); + .margin({ 10 }) + .visibility(visibility_t::visible)(text_block2) + ]; const auto& window = mwindow::create({ 800, 600 }, L"Hello, World!"); window->set_content( diff --git a/src/mirage_widget/src/widget/mcompound_widget.h b/src/mirage_widget/src/widget/mcompound_widget.h index b2fd289..937432f 100644 --- a/src/mirage_widget/src/widget/mcompound_widget.h +++ b/src/mirage_widget/src/widget/mcompound_widget.h @@ -55,28 +55,6 @@ public: using slot_type = SlotType; //-------------- 内容设置 -------------- - /** - * @brief 设置子组件内容 - * @param in_widget 要设置为内容的组件 - * @return 子组件插槽的引用,允许链式调用设置插槽属性 - * - * 设置组件的子内容,并正确配置窗口和父子关系。 - */ - auto& set_content(const std::shared_ptr& in_widget) { - on_set_content(in_widget); - invalidate(invalidate_reason::layout); - auto shared_this = shared_from_this(); - - auto& slot = get_child_slot(); - slot.slot_owner = shared_this; - slot.set(in_widget); - in_widget->init(); - in_widget->set_parent(shared_this); - if (slot_.has_visibility()) { - in_widget->set_visibility(slot_.visibility()); - } - return slot; - } auto& push_slot(const SlotType& in_slot) { const auto& child_widget = in_slot.get(); on_set_content(child_widget); @@ -130,11 +108,6 @@ public: SlotType& get_child_slot() { return slot_; } const SlotType& get_child_slot() const { return slot_; } - - auto& operator[](const std::shared_ptr& in_widget) { - return set_content(in_widget); - } - protected: /** * @brief 在设置内容时的回调函数 diff --git a/src/mirage_widget/src/widget/widget_new.h b/src/mirage_widget/src/widget/widget_new.h index 3ff2259..338516c 100644 --- a/src/mirage_widget/src/widget/widget_new.h +++ b/src/mirage_widget/src/widget/widget_new.h @@ -28,7 +28,7 @@ struct mwidget_decl { template auto operator[](Args&&... in_args) { - return (*widget_)[std::forward(in_args)...]; + return std::static_pointer_cast((*widget_)[std::forward(in_args)...]); } operator std::shared_ptr() const { return widget_; }