Recent

Author Topic: GTK3: BitBtn+glyph patch  (Read 262 times)

d4eva

  • New Member
  • *
  • Posts: 33
GTK3: BitBtn+glyph patch
« on: March 22, 2026, 09:23:47 am »
Hi,
Here's the patch for GTK3 BitBtn, which makes attached Glyph to behave the same as on GTK2/QT5.
I have zero experience with GTK2/GTK3 so I asked copilot to fix the code and it did :)
Tested on Ubuntu 25.10 (wayland) and BitBtn with a glyph and spacing property looks exactly as I expected it to look.

Code: Pascal  [Select][+][-]
  1. diff --git a/lcl/interfaces/gtk3/gtk3widgets.pas b/lcl/interfaces/gtk3/gtk3widgets.pas
  2. index bec6a95b4f..6bda7e7aad 100644
  3. --- a/lcl/interfaces/gtk3/gtk3widgets.pas
  4. +++ b/lcl/interfaces/gtk3/gtk3widgets.pas
  5. @@ -10847,26 +10847,50 @@ end;
  6.  
  7.  procedure TGtk3Button.SetSpacing(AValue: Integer);
  8.  var
  9. -  ATGValue: TGValue;
  10. -  AImage: PGtkWidget;
  11. +  Img: PGtkWidget;
  12. +  Pos: TGtkPositionType;
  13. +  MarginTop, MarginBottom, MarginLeft, MarginRight: Integer;
  14.  begin
  15. -  // if FSpacing=AValue then Exit;
  16. -  FSpacing:=AValue;
  17. +  // Normalize spacing
  18.    if AValue < 0 then
  19. -    FSpacing := 2;
  20. -  ATGValue.g_type := G_TYPE_INT;
  21. -  ATGValue.set_int(AValue);
  22. +    AValue := 0;
  23.  
  24. -  // no way under gtk3 ... we cannot set style property image-spacing
  25. -  // so we are using cheat
  26. -  AImage := PGtkButton(FWidget)^.get_image;
  27. -  if AImage <> nil then
  28. -  begin
  29. -    if AValue < 0 then
  30. -      AVAlue := 0;
  31. -    //TODO: margin depends on layout ! This is ok for left (default) layout
  32. -    PGtkImage(AImage)^.set_margin_right(AValue);
  33. +  FSpacing := AValue;
  34. +
  35. +  // Get the image widget
  36. +  Img := PGtkButton(FWidget)^.get_image;
  37. +  if Img = nil then
  38. +    Exit;
  39. +
  40. +  // Get current image position
  41. +  Pos := PGtkButton(FWidget)^.get_image_position;
  42. +
  43. +  // Reset all margins first
  44. +  MarginTop := 0;
  45. +  MarginBottom := 0;
  46. +  MarginLeft := 0;
  47. +  MarginRight := 0;
  48. +
  49. +  // Apply spacing depending on position
  50. +  case Pos of
  51. +    GTK_POS_LEFT:
  52. +      MarginRight := AValue;
  53. +
  54. +    GTK_POS_RIGHT:
  55. +      MarginLeft := AValue;
  56. +
  57. +    GTK_POS_TOP:
  58. +      MarginBottom := AValue;
  59. +
  60. +    GTK_POS_BOTTOM:
  61. +      MarginTop := AValue;
  62.    end;
  63. +
  64. +  // Apply margins
  65. +  PGtkWidget(Img)^.set_margin_top(MarginTop);
  66. +  PGtkWidget(Img)^.set_margin_bottom(MarginBottom);
  67. +  PGtkWidget(Img)^.set_margin_left(MarginLeft);
  68. +  PGtkWidget(Img)^.set_margin_right(MarginRight);
  69.  end;
  70.  
  71.  procedure TGtk3Button.SetImage(AImage: TBitmap);
  72.  

 

TinyPortal © 2005-2018