Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SolidLayer. #288

Merged
merged 7 commits into from
Oct 31, 2024
Merged

Add SolidLayer. #288

merged 7 commits into from
Oct 31, 2024

Conversation

kevingpqi123
Copy link
Collaborator

No description provided.

@@ -43,5 +43,9 @@ enum class LayerType {
* A layer displaying a simple text.
*/
Text,
/**
* A layer that fills its bounds with style.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A layer that fills its bounds with a solid color.


namespace tgfx {
/**
* A layer that fills its bounds with a solid color, gradient, or image pattern.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A layer that fills its bounds with a solid color.

* Returns the style used to fill the layer, which can be a solid color, gradient, or image
* pattern.
*/
std::shared_ptr<ShapeStyle> fillStyle() const {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只需要一个Color,复杂的用ShapeLayer实现。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

宽高属性呢?宽高要能修改。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

再添加两个圆角属性:float radiusX 和 float radiusY

/**
* Creates a new solid layer with the given dimensions and solid color.
*/
static std::shared_ptr<SolidLayer> Make(float width, float height,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我们所有Layer都不提供初始化参数,统一在layer暴露的属性上设置。改成空Make()吧

}

/**
* Returns the width of the layer.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns the width of the solid layer.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

把相关注释都更新一遍

void setHeight(float height);

/**
* Returns the axis length on x-axis of the rounded corners.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns the x-axis radius of corners.

/**
* Returns the solid color used to fill the layer.
*/
std::shared_ptr<SolidColor> solidColor() const {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用color就行,不用solidColor

float _height = 0;
float _radiusX = 0;
float _radiusY = 0;
Path _path = {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不需要这个Path

std::unique_ptr<LayerContent> onUpdateContent() override;

private:
std::shared_ptr<SolidColor> _solidColor = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

记录一个Color变量就行

Comment on lines 94 to 98
std::vector<std::unique_ptr<LayerContent>> contents = {};
auto shader = _solidColor ? _solidColor->getShader() : nullptr;
auto content = std::make_unique<ShapeContent>(_path, shader);
contents.push_back(std::move(content));
return LayerContent::Compose(std::move(contents));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你只有一个ShapeContent,为啥需要Compose,又没有描边。再写个简化的专用的,SolidContent,只记录必要的属性。一个RRect,一个Color就行。

solidLayer->setRadiusY(50);
auto bounds = Rect::MakeXYWH(0, 0, 150, 80);
auto solidLayerRect = solidLayer->getBounds();
ASSERT_TRUE(solidLayerRect == bounds);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用EXPECT_TRUE,不要用ASSERT,会导致程序整个退出


void SolidContent::draw(Canvas* canvas, const Paint& paint) const {
auto solidPaint = paint;
solidPaint.setColor(_color);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不能直接setColor,会覆盖掉原本的alpha,要把alpha取出来乘以当前的color。参考一下TextContent

public:
SolidContent(const RRect& rRect, const Color& color);

tgfx::Rect getBounds() const override {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

去掉tgfx::前缀

}

std::unique_ptr<LayerContent> SolidLayer::onUpdateContent() {
RRect rRect = {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果宽高含有0,应该返回 nullptr。

}

/**
* Returns the width of the solid layer.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value is 0. 把其他几个属性的注释也补充一下。

@domchen domchen merged commit ba6aa7d into main Oct 31, 2024
8 checks passed
@domchen domchen deleted the feature/kevingpqi_SolidLayer branch October 31, 2024 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants