代码拉取完成,页面将自动刷新
#pragma once
#include "ControlBase.h"
class Label : public Control
{
public:
float last_width = 0.0f;
virtual UIClass Type() { return UIClass::UI_Label; }
bool IsContainer() override
{
return false;
}
Label(std::wstring text, int x, int y)
{
this->Text = text;
this->Location = POINT{x, y};
this->BackColor = D2D1_COLOR_F{.0f, .0f, .0f, .0f};
}
SIZE ActualSize() override
{
auto d2d = this->Render;
auto font = this->Font ? this->Font : d2d->DefaultFontObject;
auto text_size = font->GetTextSize(this->Text);
return SIZE{(int)text_size.width, (int)text_size.height};
}
void Update() override
{
if (this->IsVisual == false)
return;
auto d2d = this->Render;
auto abslocation = this->AbsLocation;
auto size = this->ActualSize();
auto absRect = this->AbsRect;
if (last_width > size.cx)
{
absRect.right += last_width - size.cx;
size.cx = last_width;
}
d2d->PushDrawRect(absRect.left, absRect.top, absRect.right - absRect.left, absRect.bottom - absRect.top);
{
d2d->FillRect(abslocation.x, abslocation.y, size.cx, size.cy, this->Parent->BackColor);
if (this->Parent->Image)
{
this->Parent->RenderImage();
}
if (this->Image)
{
this->RenderImage();
}
d2d->DrawString(this->Text, abslocation.x, abslocation.y, this->ForeColor, this->Font);
}
d2d->PopDrawRect();
last_width = size.cx;
}
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。