From e855ab5d46143c61100e197e75340f3ba0f14644 Mon Sep 17 00:00:00 2001 From: themanyone Date: Sun, 14 Jul 2024 01:06:45 -0800 Subject: [PATCH] #4584 revisited. Gtk-CRITICAL fix + resizing --- src/slic3r/GUI/PresetComboBoxes.cpp | 36 +++++++++++++++++----------- src/slic3r/GUI/Widgets/TextInput.cpp | 1 + 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 733a2c6907..5759f9c768 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -216,20 +216,28 @@ void PresetComboBox::update_selection() // A workaround for a set of issues related to text fitting into gtk widgets: // See e.g.: https://github.com/prusa3d/PrusaSlicer/issues/4584 #if defined(__WXGTK20__) || defined(__WXGTK3__) - GList* cells = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(m_widget)); - - // 'cells' contains the GtkCellRendererPixBuf for the icon, - // 'cells->next' contains GtkCellRendererText for the text we need to ellipsize - if (!cells || !cells->next) return; - - auto cell = static_cast(cells->next->data); - - if (!cell) return; - - g_object_set(G_OBJECT(cell), "ellipsize", PANGO_ELLIPSIZE_END, (char*)NULL); - - // Only the list of cells must be freed, the renderer isn't ours to free - g_list_free(cells); + GtkWidget* widget = m_widget; + if (GTK_IS_CONTAINER(widget)) { + GList* children = gtk_container_get_children(GTK_CONTAINER(widget)); + if (children) { + widget = GTK_WIDGET(children->data); + g_list_free(children); + } + } + if (GTK_IS_ENTRY(widget)) { + // Set ellipsization for the entry + gtk_entry_set_width_chars(GTK_ENTRY(widget), 20); // Adjust this value as needed + gtk_entry_set_max_width_chars(GTK_ENTRY(widget), 20); // Adjust this value as needed + // Create a PangoLayout for the entry and set ellipsization + PangoLayout* layout = gtk_entry_get_layout(GTK_ENTRY(widget)); + if (layout) { + pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); + } else { + g_warning("Unable to get PangoLayout from GtkEntry"); + } + } else { + g_warning("Expected GtkEntry, but got %s", G_OBJECT_TYPE_NAME(widget)); + } #endif } diff --git a/src/slic3r/GUI/Widgets/TextInput.cpp b/src/slic3r/GUI/Widgets/TextInput.cpp index 26a1397b0b..8b2437af43 100644 --- a/src/slic3r/GUI/Widgets/TextInput.cpp +++ b/src/slic3r/GUI/Widgets/TextInput.cpp @@ -257,6 +257,7 @@ void TextInput::DoSetSize(int x, int y, int width, int height, int sizeFlags) wxClientDC dc(this); const int r_shift = int(dd_icon_size.x == 0 ? (3. * dc.GetContentScaleFactor()) : ((size.y - dd_icon_size.y) / 2)); textSize.x = size.x - textPos.x - labelSize.x - dd_icon_size.x - r_shift; + if (textSize.x < -1) textSize.x = -1; text_ctrl->SetSize(textSize); text_ctrl->SetPosition({textPos.x, (size.y - textSize.y) / 2}); }