ENH:add "text to image" function in TextInput

jira: none
Change-Id: Ibdb57b74511432e81faa0c556bb6e639d5a174f5
This commit is contained in:
zhou.xu 2025-01-15 12:18:58 +08:00 committed by lane.wei
parent 45c8e7b0ce
commit 09323aeed3
9 changed files with 78 additions and 11 deletions

View File

@ -0,0 +1,13 @@
<svg width="10" height="12" viewBox="0 0 10 12" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_20951_60249)">
<path d="M5.33289 4.479V12.0001H9.61044V6.16426L5.33289 4.479Z" fill="#262E30"/>
<path d="M5.33289 0V3.76054L9.61044 5.4458V0H5.33289Z" fill="#262E30"/>
<path d="M0.389526 7.52109V0H4.66708V5.83583L0.389526 7.52109Z" fill="#262E30"/>
<path d="M0.389526 12V8.23946L4.66708 6.5542V12H0.389526Z" fill="#262E30"/>
</g>
<defs>
<clipPath id="clip0_20951_60249">
<rect width="10" height="12" fill="white"/>
</clipPath>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 563 B

View File

@ -554,7 +554,7 @@ void AmsMapingPopup::update(MachineObject* obj)
m_left_extra_slot->Hide();
//m_left_marea_panel->Show();
m_right_marea_panel->Show();
set_sizer_title(m_right_split_ams_sizer, _L("Ams"));
set_sizer_title(m_right_split_ams_sizer, _L("AMS"));
m_right_extra_slot->Show();
}
else if (nozzle_nums > 1) {

View File

@ -2747,8 +2747,10 @@ void Sidebar::load_ams_list(std::string const &device, MachineObject* obj)
return;
wxGetApp().preset_bundle->filament_ams_list = filament_ams_list;
for (auto c : p->combos_filament)
for (auto c : p->combos_filament){
c->update();
c->ShowBadge(false);//change printer,then clear badge
}
p->combo_printer->update();
}
@ -2859,9 +2861,8 @@ void Sidebar::sync_ams_list()
}
}
auto badge_combox_filament = [](PlaterPresetComboBox *c) {
auto cur_tip = c->GetToolTip()->GetTip();
auto tip = _L("\nMaterial and color information have been synchronized, but slot information is not included.");
c->SetToolTip(cur_tip + tip);
c->SetToolTip(tip);
c->ShowBadge(true);
};
{ // badge ams filament

View File

@ -1204,8 +1204,10 @@ void PlaterPresetComboBox::update()
if (m_type == Preset::TYPE_PRINTER)
add_connected_printers("", true);
if (m_type == Preset::TYPE_FILAMENT)
if (m_type == Preset::TYPE_FILAMENT) {
set_replace_text("Bambu", "BambuStudioBlack");
add_ams_filaments(into_u8(selected_user_preset.empty() ? selected_system_preset : selected_user_preset), true);
}
std::vector<std::string> filament_orders = {"Bambu PLA Basic", "Bambu PLA Matte", "Bambu PETG HF", "Bambu ABS", "Bambu PLA Silk", "Bambu PLA-CF",
"Bambu PLA Galaxy", "Bambu PLA Metal", "Bambu PLA Marble", "Bambu PETG-CF", "Bambu PETG Translucent", "Bambu ABS-GF"};

View File

@ -134,8 +134,6 @@ void SyncAmsInfoDialog::updata_ui_data_after_connected_printer() {
if (!m_input_info.connected_printer) { return; }
if (is_dirty_filament()) { return; }
show_sizer(m_plate_combox_sizer, true);
update_printer_name();//m_printer_is_map_title is in m_plate_combox_sizer
show_sizer(m_sizer_line, true);
show_sizer(m_sizer_two_image, true);
@ -1163,9 +1161,8 @@ SyncAmsInfoDialog::SyncAmsInfoDialog(wxWindow *parent, SyncInfo &info) :
tip_sizer->Add(m_attention_text, 0, wxALIGN_LEFT | wxTOP, FromDIP(2));
m_tip_text = new wxStaticText(this, wxID_ANY, _L("Only synchronize filament type and color, not including AMS slot information."));
m_tip_text->SetForegroundColour(wxColour(107, 107, 107, 100));
tip_sizer->AddSpacer(FromDIP(25));
tip_sizer->Add(m_tip_text, 0, wxALIGN_LEFT | wxTOP, FromDIP(2));
tip_sizer->AddSpacer(FromDIP(25));
bSizer->Add(tip_sizer, 0, wxEXPAND | wxLEFT, FromDIP(25));
add_two_image_control();
@ -3207,6 +3204,9 @@ void SyncAmsInfoDialog::on_timer(wxTimerEvent &event)
update_select_layout(obj_);
update_ams_check(obj_);
m_check_flag = true;
show_sizer(m_plate_combox_sizer, true);
update_printer_name(); // m_printer_is_map_title is in m_plate_combox_sizer
}
if (!obj_ || obj_->amsList.empty() || obj_->ams_exist_bits == 0 || !obj_->is_support_filament_backup || !obj_->is_support_show_filament_backup ||

View File

@ -119,8 +119,18 @@ void ComboBox::SetLabel(const wxString &value)
{
if (GetTextCtrl()->IsShown() || text_off)
GetTextCtrl()->SetValue(value);
else
TextInput::SetLabel(value);
else {
if (is_replace_text_to_image) {
auto new_value = value;
new_value.Replace(replace_text, "", false);//replace first text
TextInput::SetIcon_1(image_for_text);
TextInput::SetLabel(new_value);
}
else {
TextInput::SetIcon_1("");
TextInput::SetLabel(value);
}
}
}
wxString ComboBox::GetLabel() const
@ -199,6 +209,13 @@ void ComboBox::DoDeleteOneItem(unsigned int pos)
unsigned int ComboBox::GetCount() const { return items.size(); }
void ComboBox::set_replace_text(wxString text, wxString image_name)
{
replace_text = text;
image_for_text = image_name;
is_replace_text_to_image = true;
}
wxString ComboBox::GetString(unsigned int n) const
{ return n < items.size() ? items[n].text : wxString{}; }

View File

@ -15,6 +15,9 @@ class ComboBox : public wxWindowWithItems<TextInput, wxItemContainer>
DropDown drop;
bool drop_down = false;
bool text_off = false;
bool is_replace_text_to_image = false;
wxString replace_text;
wxString image_for_text;
public:
ComboBox(wxWindow * parent,
@ -37,6 +40,7 @@ public:
int Append(const wxString &item, const wxBitmap &bitmap, const wxString &group, void *clientData = nullptr);
void set_replace_text(wxString text, wxString image_name);
unsigned int GetCount() const override;
int GetSelection() const override;

View File

@ -110,6 +110,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;
@ -126,6 +137,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();
}
@ -165,6 +178,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;
@ -213,6 +230,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();

View File

@ -9,6 +9,7 @@ class TextInput : public wxNavigationEnabled<StaticBox>
wxSize labelSize;
ScalableBitmap icon;
ScalableBitmap icon_1;
StateColor label_color;
StateColor text_color;
wxTextCtrl * text_ctrl;
@ -44,6 +45,8 @@ public:
void SetIcon(const wxString & icon);
void SetIcon_1(const wxString &icon);
void SetLabelColor(StateColor const &color);
void SetTextColor(StateColor const &color);