-
Notifications
You must be signed in to change notification settings - Fork 67
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
Add SolidLayer. #288
Conversation
include/tgfx/layers/LayerType.h
Outdated
@@ -43,5 +43,9 @@ enum class LayerType { | |||
* A layer displaying a simple text. | |||
*/ | |||
Text, | |||
/** | |||
* A layer that fills its bounds with style. |
There was a problem hiding this comment.
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.
include/tgfx/layers/SolidLayer.h
Outdated
|
||
namespace tgfx { | ||
/** | ||
* A layer that fills its bounds with a solid color, gradient, or image pattern. |
There was a problem hiding this comment.
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.
include/tgfx/layers/SolidLayer.h
Outdated
* Returns the style used to fill the layer, which can be a solid color, gradient, or image | ||
* pattern. | ||
*/ | ||
std::shared_ptr<ShapeStyle> fillStyle() const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
只需要一个Color,复杂的用ShapeLayer实现。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
宽高属性呢?宽高要能修改。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
再添加两个圆角属性:float radiusX 和 float radiusY
include/tgfx/layers/SolidLayer.h
Outdated
/** | ||
* Creates a new solid layer with the given dimensions and solid color. | ||
*/ | ||
static std::shared_ptr<SolidLayer> Make(float width, float height, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们所有Layer都不提供初始化参数,统一在layer暴露的属性上设置。改成空Make()吧
include/tgfx/layers/SolidLayer.h
Outdated
} | ||
|
||
/** | ||
* Returns the width of the layer. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
把相关注释都更新一遍
include/tgfx/layers/SolidLayer.h
Outdated
void setHeight(float height); | ||
|
||
/** | ||
* Returns the axis length on x-axis of the rounded corners. |
There was a problem hiding this comment.
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.
include/tgfx/layers/SolidLayer.h
Outdated
/** | ||
* Returns the solid color used to fill the layer. | ||
*/ | ||
std::shared_ptr<SolidColor> solidColor() const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用color就行,不用solidColor
include/tgfx/layers/SolidLayer.h
Outdated
float _height = 0; | ||
float _radiusX = 0; | ||
float _radiusY = 0; | ||
Path _path = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要这个Path
include/tgfx/layers/SolidLayer.h
Outdated
std::unique_ptr<LayerContent> onUpdateContent() override; | ||
|
||
private: | ||
std::shared_ptr<SolidColor> _solidColor = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
记录一个Color变量就行
src/core/SolidLayer.cpp
Outdated
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)); |
There was a problem hiding this comment.
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就行。
test/src/LayerTest.cpp
Outdated
solidLayer->setRadiusY(50); | ||
auto bounds = Rect::MakeXYWH(0, 0, 150, 80); | ||
auto solidLayerRect = solidLayer->getBounds(); | ||
ASSERT_TRUE(solidLayerRect == bounds); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用EXPECT_TRUE,不要用ASSERT,会导致程序整个退出
src/layers/contents/SolidContent.cpp
Outdated
|
||
void SolidContent::draw(Canvas* canvas, const Paint& paint) const { | ||
auto solidPaint = paint; | ||
solidPaint.setColor(_color); |
There was a problem hiding this comment.
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
src/layers/contents/SolidContent.h
Outdated
public: | ||
SolidContent(const RRect& rRect, const Color& color); | ||
|
||
tgfx::Rect getBounds() const override { |
There was a problem hiding this comment.
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 = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果宽高含有0,应该返回 nullptr。
include/tgfx/layers/SolidLayer.h
Outdated
} | ||
|
||
/** | ||
* Returns the width of the solid layer. |
There was a problem hiding this comment.
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. 把其他几个属性的注释也补充一下。
No description provided.