1 Star 0 Fork 0

Janisa/GUI

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Label.h 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
Janisa 提交于 2024-07-09 19:24 +08:00 . 添加编译工程脚本
#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;
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/Janisa/gui.git
git@gitee.com:Janisa/gui.git
Janisa
gui
GUI
master

搜索帮助