修复内边距不正确
This commit is contained in:
parent
3a426b8b99
commit
759f482afe
@ -25,6 +25,7 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
const auto button = mnew(mbutton)
|
const auto button = mnew(mbutton)
|
||||||
mslot(mbutton)
|
mslot(mbutton)
|
||||||
|
.margin({10})
|
||||||
[
|
[
|
||||||
text_block
|
text_block
|
||||||
];
|
];
|
||||||
|
@ -29,7 +29,7 @@ struct mborder_slot : mcompound_widget_slot<mborder_slot> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 定义margin属性,用于控制子组件周围的边距
|
* 定义margin属性,内边距,用于设置子组件与边框之间的距离(会导致最终大小变大)
|
||||||
*/
|
*/
|
||||||
SLOT_ATTRIBUTE(margin_t, margin)
|
SLOT_ATTRIBUTE(margin_t, margin)
|
||||||
};
|
};
|
||||||
@ -59,4 +59,18 @@ public:
|
|||||||
slot.v_alignment(),
|
slot.v_alignment(),
|
||||||
slot.margin());
|
slot.margin());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Eigen::Vector2f compute_desired_size(float in_layout_scale_multiplier) const override {
|
||||||
|
if (const auto& child = get_child_slot().get()) {
|
||||||
|
// 获取子部件的期望大小
|
||||||
|
const auto& child_size = child->compute_desired_size(in_layout_scale_multiplier);
|
||||||
|
const auto& margin = slot_.margin();
|
||||||
|
|
||||||
|
// 添加边距的贡献
|
||||||
|
// return child_size + Eigen::Vector2f(margin.horizontal(), margin.vertical());
|
||||||
|
// 或使用现有的 margin.get_total_spacing() 方法
|
||||||
|
return child_size + margin.get_total_spacing();
|
||||||
|
}
|
||||||
|
return Eigen::Vector2f(10, 10);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -27,17 +27,6 @@ void mbutton::on_paint(mirage_paint_context& in_context) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector2f mbutton::compute_desired_size(float in_layout_scale_multiplier) const {
|
|
||||||
const margin_t button_padding = { 10, 10, 10, 10 }; // TODO 临时值, 以后会从主题中获取
|
|
||||||
Eigen::Vector2f desired_size = button_padding.get_total_spacing();
|
|
||||||
|
|
||||||
if (const auto& child = get_child_slot().get()) {
|
|
||||||
desired_size += child->compute_desired_size(in_layout_scale_multiplier);
|
|
||||||
}
|
|
||||||
|
|
||||||
return desired_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void mbutton::on_click(const Eigen::Vector2f& in_position, mouse_button in_button) {
|
void mbutton::on_click(const Eigen::Vector2f& in_position, mouse_button in_button) {
|
||||||
mborder::on_click(in_position, in_button);
|
mborder::on_click(in_position, in_button);
|
||||||
std::cout << this << ": Button clicked!" << in_position.x() << ", " << in_position.y() << std::endl;
|
std::cout << this << ": Button clicked!" << in_position.x() << ", " << in_position.y() << std::endl;
|
||||||
|
@ -7,7 +7,6 @@ public:
|
|||||||
virtual void init() override;
|
virtual void init() override;
|
||||||
|
|
||||||
virtual void on_paint(mirage_paint_context& in_context) override;
|
virtual void on_paint(mirage_paint_context& in_context) override;
|
||||||
virtual Eigen::Vector2f compute_desired_size(float in_layout_scale_multiplier) const override;
|
|
||||||
|
|
||||||
virtual void on_click(const Eigen::Vector2f& in_position, mouse_button in_button) override;
|
virtual void on_click(const Eigen::Vector2f& in_position, mouse_button in_button) override;
|
||||||
virtual void on_double_click(const Eigen::Vector2f& in_position, mouse_button in_button) override;
|
virtual void on_double_click(const Eigen::Vector2f& in_position, mouse_button in_button) override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user