Skip to content

Commit 3566233

Browse files
committed
[Gtk4] Fix Text SINGLE initial size
It should use pango layout with the real content to query size and not just a new empty one.
1 parent a589ee9 commit 3566233

File tree

1 file changed

+15
-8
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets

1 file changed

+15
-8
lines changed

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -633,15 +633,16 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
633633
if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
634634
int[] w = new int[1], h = new int[1];
635635
if ((style & SWT.SINGLE) != 0) {
636-
long layout;
637636
if (GTK.GTK4) {
638-
long context = GTK.gtk_widget_get_pango_context(handle);
639-
layout = OS.pango_layout_new(context);
637+
long ptr = GTK.gtk_entry_buffer_get_text(bufferHandle);
638+
long layout = GTK.gtk_widget_create_pango_layout(handle, ptr);
639+
OS.pango_layout_get_pixel_size(layout, w, h);
640+
OS.g_object_unref(layout);
640641
} else {
641642
GTK.gtk_widget_realize(handle);
642-
layout = GTK3.gtk_entry_get_layout(handle);
643+
long layout = GTK3.gtk_entry_get_layout(handle);
644+
OS.pango_layout_get_pixel_size(layout, w, h);
643645
}
644-
OS.pango_layout_get_pixel_size(layout, w, h);
645646
} else {
646647
byte [] start = new byte [ITER_SIZEOF], end = new byte [ITER_SIZEOF];
647648
GTK.gtk_text_buffer_get_bounds (bufferHandle, start, end);
@@ -691,7 +692,7 @@ Rectangle computeTrimInPixels (int x, int y, int width, int height) {
691692
trim.x -= tmp.left;
692693
trim.y -= tmp.top;
693694
trim.width += tmp.left + tmp.right;
694-
if (tmp.bottom == 0 && tmp.top == 0) {
695+
if (GTK.GTK4 || tmp.bottom == 0 && tmp.top == 0) {
695696
Point widthNative = computeNativeSize(handle, trim.width, SWT.DEFAULT, true);
696697
trim.height = widthNative.y;
697698
} else {
@@ -702,8 +703,14 @@ Rectangle computeTrimInPixels (int x, int y, int width, int height) {
702703
gtk_style_context_get_border(context, state, tmp);
703704
trim.x -= tmp.left;
704705
trim.y -= tmp.top;
705-
trim.width += tmp.left + tmp.right;
706-
trim.height += tmp.top + tmp.bottom;
706+
/*
707+
* In GTK4, computeNativeSize already returns the full natural height and width
708+
* including border, so avoid double-counting it here.
709+
*/
710+
if (!GTK.GTK4) {
711+
trim.width += tmp.left + tmp.right;
712+
trim.height += tmp.top + tmp.bottom;
713+
}
707714
}
708715
if (!GTK.GTK4 || ((style & SWT.SEARCH) == 0) ) {
709716
GdkRectangle icon_area = new GdkRectangle();

0 commit comments

Comments
 (0)