ENH:add "text to image" function in TextInput

jira: none
Change-Id: Ibdb57b74511432e81faa0c556bb6e639d5a174f5
(cherry picked from commit 09323aeed34f29f105b95d3d6a2c7a151e17e42a)
This commit is contained in:
zhou.xu
2025-01-15 12:18:58 +08:00
committed by Noisyfox
parent 2e8a5ecd87
commit 200a811dca
9 changed files with 78 additions and 11 deletions

View File

@@ -111,6 +111,17 @@ void TextInput::SetIcon(const wxString &icon)
Rescale();
}
void TextInput::SetIcon_1(const wxString &icon) {
if (this->icon_1.name() == icon.ToStdString())
return;
if (icon.empty()) {
this->icon_1 = ScalableBitmap();
return;
}
this->icon_1 = ScalableBitmap(this, icon.ToStdString(), 16);
Rescale();
}
void TextInput::SetLabelColor(StateColor const &color)
{
label_color = color;
@@ -127,6 +138,8 @@ void TextInput::Rescale()
{
if (!this->icon.name().empty())
this->icon.msw_rescale();
if (!this->icon_1.name().empty())
this->icon_1.msw_rescale();
messureSize();
Refresh();
}
@@ -166,6 +179,10 @@ void TextInput::DoSetSize(int x, int y, int width, int height, int sizeFlags)
wxSize szIcon = this->icon.GetBmpSize();
textPos.x += szIcon.x;
}
if (this->icon_1.bmp().IsOk()) {
wxSize szIcon = this->icon_1.GetBmpSize();
textPos.x += (szIcon.x);
}
bool align_right = GetWindowStyle() & wxALIGN_RIGHT;
if (align_right)
textPos.x += labelSize.x;
@@ -214,6 +231,16 @@ void TextInput::render(wxDC& dc)
dc.DrawBitmap(icon.bmp(), pt);
pt.x += szIcon.x + 0;
}
if (icon_1.bmp().IsOk()) {
wxSize szIcon = icon_1.GetBmpSize();
pt.y = (size.y - szIcon.y) / 2;
if (align_center) {
if (pt.x * 2 + szIcon.x + 0 + labelSize.x < size.x)
pt.x = (size.x - (szIcon.x + 0 + labelSize.x)) / 2;
}
dc.DrawBitmap(icon_1.bmp(), pt);
pt.x += szIcon.x + 0;
}
auto text = wxWindow::GetLabel();
if (!text.IsEmpty()) {
wxSize textSize = text_ctrl->GetSize();