布局语法优化
This commit is contained in:
parent
b5fc6a9a26
commit
2c794509bc
@ -68,21 +68,19 @@ int main(int argc, char* argv[]) {
|
||||
const auto& text_block2 = std::make_shared<mtext_block>();
|
||||
text_block2->set_text(U"Hello, World!");
|
||||
|
||||
auto button = std::make_shared<mbutton>();
|
||||
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<mbutton>();
|
||||
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(
|
||||
|
@ -55,28 +55,6 @@ public:
|
||||
using slot_type = SlotType;
|
||||
//-------------- 内容设置 --------------
|
||||
|
||||
/**
|
||||
* @brief 设置子组件内容
|
||||
* @param in_widget 要设置为内容的组件
|
||||
* @return 子组件插槽的引用,允许链式调用设置插槽属性
|
||||
*
|
||||
* 设置组件的子内容,并正确配置窗口和父子关系。
|
||||
*/
|
||||
auto& set_content(const std::shared_ptr<mwidget>& 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<mwidget>& in_widget) {
|
||||
return set_content(in_widget);
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief 在设置内容时的回调函数
|
||||
|
@ -28,7 +28,7 @@ struct mwidget_decl {
|
||||
|
||||
template<typename ...Args>
|
||||
auto operator[](Args&&... in_args) {
|
||||
return (*widget_)[std::forward<Args>(in_args)...];
|
||||
return std::static_pointer_cast<WidgetType>((*widget_)[std::forward<Args>(in_args)...]);
|
||||
}
|
||||
|
||||
operator std::shared_ptr<mwidget>() const { return widget_; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user