Fix for incorrect text fitting on gtk comboboxes.

fixes #4584
This commit is contained in:
tamasmeszaros 2021-01-07 13:38:16 +01:00
parent a5882a1a1c
commit 2505c0a82d
3 changed files with 74 additions and 21 deletions

View file

@ -32,9 +32,13 @@
#include "PhysicalPrinterDialog.hpp"
#include "SavePresetDialog.hpp"
#include <glib-2.0/glib-object.h>
#include <pango-1.0/pango/pango-layout.h>
#include <gtk/gtk.h>
// 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__)
#include <glib-2.0/glib-object.h>
#include <pango-1.0/pango/pango-layout.h>
#include <gtk/gtk.h>
#endif
using Slic3r::GUI::format_wxstr;
@ -134,8 +138,6 @@ PresetComboBox::PresetComboBox(wxWindow* parent, Preset::Type preset_type, const
}
evt.Skip();
});
// g_object_set( G_OBJECT( this ), "ellipsize", PANGO_ELLIPSIZE_END, nullptr);
}
PresetComboBox::~PresetComboBox()
@ -186,19 +188,24 @@ void PresetComboBox::update_selection()
SetSelection(m_last_selected);
SetToolTip(GetString(m_last_selected));
GList* cells = gtk_cell_layout_get_cells( GTK_CELL_LAYOUT( m_widget ) );
if( !cells )
return;
// 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));
GtkCellRendererText* cell = (GtkCellRendererText *) cells->next->data;
// 'cells' contains the GtkCellRendererPixBuf for the icon,
// 'cells->next' contains GtkCellRendererText for the text we need to ellipsize
if (!cells || !cells->next) return;
if( !cell )
return;
auto cell = static_cast<GtkCellRendererText *>(cells->next->data);
g_object_set( G_OBJECT( cell ), "ellipsize", PANGO_ELLIPSIZE_END, NULL );
if (!cell) return;
g_object_set(G_OBJECT(cell), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
// Only the list of cells must be freed, the renderer isn't ours to free
g_list_free( cells );
g_list_free(cells);
#endif
}
void PresetComboBox::update(std::string select_preset_name)