Skip to content

Commit

Permalink
add wrap_content feature to layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ashercai committed Jun 12, 2024
1 parent 219fe3c commit e32dc87
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions dom/include/dom/layout_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class LayoutNode {

virtual void SetWidth(float width) = 0;
virtual void SetHeight(float height) = 0;
virtual void SetMaxWidth(float width) = 0;
virtual void SetMaxHeight(float height) = 0;
virtual void SetPosition(Edge edge, float position) = 0;
virtual void SetScaleFactor(float scale_factor) = 0;
virtual bool HasNewLayout() = 0;
Expand Down
5 changes: 5 additions & 0 deletions dom/include/dom/root_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class RootNode : public DomNode {
void SetRootOrigin(float x, float y);
void Traverse(const std::function<void(const std::shared_ptr<DomNode>&)>& on_traverse);
void AddInterceptor(const std::shared_ptr<DomActionInterceptor>& interceptor);
void SetDisableSetRootSize(bool disable) {
disable_set_root_size_ = disable;
}

static footstone::utils::PersistentObjectMap<uint32_t, std::shared_ptr<RootNode>>& PersistentMap() {
return persistent_map_;
Expand Down Expand Up @@ -128,6 +131,8 @@ class RootNode : public DomNode {
std::shared_ptr<AnimationManager> animation_manager_;
std::unique_ptr<DomNodeStyleDiffer> style_differ_;

bool disable_set_root_size_ { false };

static footstone::utils::PersistentObjectMap<uint32_t, std::shared_ptr<RootNode>> persistent_map_;
};

Expand Down
4 changes: 2 additions & 2 deletions dom/include/dom/taitank_layout_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,13 @@ class TaitankLayoutNode : public LayoutNode, public std::enable_shared_from_this
* @brief 设置 max width 属性
* @param max_width 最大宽度
*/
void SetMaxWidth(float max_width);
void SetMaxWidth(float max_width) override;

/**
* @brief 设置 max height 属性
* @param max_height 最大高度
*/
void SetMaxHeight(float max_height);
void SetMaxHeight(float max_height) override;

/**
* @brief 设置 min width 属性
Expand Down
4 changes: 4 additions & 0 deletions dom/include/dom/yoga_layout_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class YogaLayoutNode : public LayoutNode, public std::enable_shared_from_this<Yo
void SetWidth(float width) override;

void SetHeight(float height) override;

void SetMaxWidth(float width) override;

void SetMaxHeight(float height) override;

void SetScaleFactor(float sacle_factor) override;

Expand Down
6 changes: 5 additions & 1 deletion dom/src/dom/root_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,11 @@ std::shared_ptr<DomNode> RootNode::GetNode(uint32_t id) {

std::tuple<float, float> RootNode::GetRootSize() { return GetLayoutSize(); }

void RootNode::SetRootSize(float width, float height) { SetLayoutSize(width, height); }
void RootNode::SetRootSize(float width, float height) {
if (!disable_set_root_size_) {
SetLayoutSize(width, height);
}
}

void RootNode::SetRootOrigin(float x, float y) { SetLayoutOrigin(x, y); }

Expand Down
4 changes: 4 additions & 0 deletions dom/src/dom/yoga_layout_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ void YogaLayoutNode::SetWidth(float width) { YGNodeStyleSetWidth(yoga_node_, wid

void YogaLayoutNode::SetHeight(float height) { YGNodeStyleSetHeight(yoga_node_, height); }

void YogaLayoutNode::SetMaxWidth(float width) { YGNodeStyleSetMaxWidth(yoga_node_, width); }

void YogaLayoutNode::SetMaxHeight(float height) { YGNodeStyleSetMaxHeight(yoga_node_, height); }

void YogaLayoutNode::SetScaleFactor(float scale_factor) { YGConfigSetPointScaleFactor(yoga_config_, scale_factor); }

static LayoutMeasureMode ToLayoutMeasureMode(YGMeasureMode measure_mode) {
Expand Down

0 comments on commit e32dc87

Please sign in to comment.