change: update text size while updating layout
This commit is contained in:
parent
9221b46e1b
commit
5875f0d2b1
|
|
@ -126,7 +126,7 @@ namespace easy2d
|
||||||
float radius_y
|
float radius_y
|
||||||
);
|
);
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
float stroke_width_;
|
float stroke_width_;
|
||||||
StrokeStyle stroke_;
|
StrokeStyle stroke_;
|
||||||
ID2D1RenderTarget* render_target_;
|
ID2D1RenderTarget* render_target_;
|
||||||
|
|
|
||||||
|
|
@ -574,6 +574,11 @@ namespace easy2d
|
||||||
return parent_;
|
return parent_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rect Node::GetBounds()
|
||||||
|
{
|
||||||
|
return Rect(Point{}, transform_.size);
|
||||||
|
}
|
||||||
|
|
||||||
Node::Nodes Node::GetChildren(const String& name) const
|
Node::Nodes Node::GetChildren(const String& name) const
|
||||||
{
|
{
|
||||||
Nodes children;
|
Nodes children;
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ namespace easy2d
|
||||||
virtual ~Node();
|
virtual ~Node();
|
||||||
|
|
||||||
// 渲染节点
|
// 渲染节点
|
||||||
virtual void OnDraw() const {}
|
virtual void OnDraw() {}
|
||||||
|
|
||||||
// 更新节点
|
// 更新节点
|
||||||
virtual void OnUpdate(Duration const& dt) {}
|
virtual void OnUpdate(Duration const& dt) {}
|
||||||
|
|
@ -124,6 +124,9 @@ namespace easy2d
|
||||||
// 获取父节点
|
// 获取父节点
|
||||||
spNode GetParent() const;
|
spNode GetParent() const;
|
||||||
|
|
||||||
|
// 삿혤관鍋분
|
||||||
|
virtual Rect GetBounds();
|
||||||
|
|
||||||
// 设置节点是否显示
|
// 设置节点是否显示
|
||||||
void SetVisible(
|
void SetVisible(
|
||||||
bool val
|
bool val
|
||||||
|
|
@ -358,14 +361,14 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void DrawBorder();
|
virtual void Update(Duration const& dt);
|
||||||
|
|
||||||
void Update(Duration const& dt);
|
|
||||||
|
|
||||||
void UpdateTransform();
|
void UpdateTransform();
|
||||||
|
|
||||||
void UpdateOpacity();
|
void UpdateOpacity();
|
||||||
|
|
||||||
|
void DrawBorder();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
String name_;
|
String name_;
|
||||||
size_t hash_name_;
|
size_t hash_name_;
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ namespace easy2d
|
||||||
return image_;
|
return image_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite::OnDraw() const
|
void Sprite::OnDraw()
|
||||||
{
|
{
|
||||||
if (image_ && image_->GetBitmap())
|
if (image_ && image_->GetBitmap())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -81,9 +81,9 @@ namespace easy2d
|
||||||
spImage const& GetImage() const;
|
spImage const& GetImage() const;
|
||||||
|
|
||||||
// äÖȾ¾«Áé
|
// äÖȾ¾«Áé
|
||||||
virtual void OnDraw() const override;
|
virtual void OnDraw() override;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
spImage image_;
|
spImage image_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ namespace easy2d
|
||||||
|
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
bool running_;
|
bool running_;
|
||||||
bool stopped_;
|
bool stopped_;
|
||||||
int run_times_;
|
int run_times_;
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ namespace easy2d
|
||||||
return style_.outline_stroke;
|
return style_.outline_stroke;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Text::GetLineCount() const
|
int Text::GetLineCount()
|
||||||
{
|
{
|
||||||
UpdateLayout();
|
UpdateLayout();
|
||||||
if (text_layout_)
|
if (text_layout_)
|
||||||
|
|
@ -145,18 +145,10 @@ namespace easy2d
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect Text::GetContentBounds() const
|
Rect Text::GetBounds()
|
||||||
{
|
{
|
||||||
UpdateLayout();
|
UpdateLayout();
|
||||||
if (text_layout_)
|
return Node::GetBounds();
|
||||||
{
|
|
||||||
DWRITE_TEXT_METRICS metrics;
|
|
||||||
if (SUCCEEDED(text_layout_->GetMetrics(&metrics)))
|
|
||||||
{
|
|
||||||
return Rect(0.f, 0.f, metrics.layoutWidth, metrics.height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Rect{};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Text::IsItalic() const
|
bool Text::IsItalic() const
|
||||||
|
|
@ -312,10 +304,8 @@ namespace easy2d
|
||||||
style_.outline_stroke = outline_stroke;
|
style_.outline_stroke = outline_stroke;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::OnDraw() const
|
void Text::OnDraw()
|
||||||
{
|
{
|
||||||
UpdateLayout();
|
|
||||||
|
|
||||||
if (text_layout_)
|
if (text_layout_)
|
||||||
{
|
{
|
||||||
auto graphics = devices::Graphics::Instance();
|
auto graphics = devices::Graphics::Instance();
|
||||||
|
|
@ -331,7 +321,13 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Text::UpdateLayout() const
|
void Text::Update(Duration const & dt)
|
||||||
|
{
|
||||||
|
UpdateLayout();
|
||||||
|
Node::Update(dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Text::UpdateLayout()
|
||||||
{
|
{
|
||||||
if (!dirty_layout_)
|
if (!dirty_layout_)
|
||||||
return;
|
return;
|
||||||
|
|
@ -376,6 +372,10 @@ namespace easy2d
|
||||||
style_.wrap_width
|
style_.wrap_width
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
DWRITE_TEXT_METRICS metrics;
|
||||||
|
text_layout_->GetMetrics(&metrics);
|
||||||
|
this->SetSize(metrics.layoutWidth, metrics.height);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -390,6 +390,7 @@ namespace easy2d
|
||||||
|
|
||||||
DWRITE_TEXT_METRICS metrics;
|
DWRITE_TEXT_METRICS metrics;
|
||||||
text_layout_->GetMetrics(&metrics);
|
text_layout_->GetMetrics(&metrics);
|
||||||
|
this->SetSize(metrics.width, metrics.height);
|
||||||
|
|
||||||
SafeRelease(text_layout_);
|
SafeRelease(text_layout_);
|
||||||
ThrowIfFailed(
|
ThrowIfFailed(
|
||||||
|
|
|
||||||
|
|
@ -87,10 +87,10 @@ namespace easy2d
|
||||||
StrokeStyle GetOutlineStroke() const;
|
StrokeStyle GetOutlineStroke() const;
|
||||||
|
|
||||||
// 获取文本显示行数
|
// 获取文本显示行数
|
||||||
int GetLineCount() const;
|
int GetLineCount();
|
||||||
|
|
||||||
// 삿혤匡俚관鍋분
|
// »ñÈ¡°üΧºÐ
|
||||||
Rect GetContentBounds() const;
|
virtual Rect GetBounds() override;
|
||||||
|
|
||||||
// 是否是斜体
|
// 是否是斜体
|
||||||
bool IsItalic() const;
|
bool IsItalic() const;
|
||||||
|
|
@ -205,17 +205,19 @@ namespace easy2d
|
||||||
);
|
);
|
||||||
|
|
||||||
// 渲染文字
|
// 渲染文字
|
||||||
virtual void OnDraw() const override;
|
virtual void OnDraw() override;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
void UpdateLayout() const;
|
virtual void Update(Duration const& dt) override;
|
||||||
|
|
||||||
private:
|
void UpdateLayout();
|
||||||
String text_;
|
|
||||||
Font font_;
|
protected:
|
||||||
TextStyle style_;
|
String text_;
|
||||||
mutable bool dirty_layout_;
|
Font font_;
|
||||||
mutable IDWriteTextFormat* text_format_;
|
TextStyle style_;
|
||||||
mutable IDWriteTextLayout* text_layout_;
|
bool dirty_layout_;
|
||||||
|
IDWriteTextFormat* text_format_;
|
||||||
|
IDWriteTextLayout* text_layout_;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -177,19 +177,19 @@ namespace easy2d
|
||||||
{
|
{
|
||||||
return static_cast<bool>(rhs);
|
return static_cast<bool>(rhs);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline SmartPointer<T> make_intrusive(T* ptr)
|
inline intrusive::SmartPointer<T> make_intrusive(T* ptr)
|
||||||
{
|
{
|
||||||
return SmartPointer<T>(ptr);
|
return intrusive::SmartPointer<T>(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// template class cannot support std::swap,
|
// template class cannot specialize std::swap,
|
||||||
// so implement a swap function in easy2d namespace
|
// so implement a swap function in easy2d namespace
|
||||||
template<class T>
|
template<class T>
|
||||||
inline void swap(SmartPointer<T>& lhs, SmartPointer<T>& rhs)
|
inline void swap(intrusive::SmartPointer<T>& lhs, intrusive::SmartPointer<T>& rhs)
|
||||||
{
|
{
|
||||||
lhs.Swap(rhs);
|
lhs.Swap(rhs);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue