View Issue Details

IDProjectCategoryView StatusLast Update
0038808LazarusWidgetsetpublic2021-04-30 19:29
ReporterCudaText man Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
OSUbuntu 20.4 
Product Version2.1 (SVN) 
Summary0038808: gtk3: GroupBox title is painted on the very left edge
DescriptionIn the added demo, GroupBox titles are at the very left. While when I see at non-pascal apps, I see titles are painted with some indent. for ex, see this screenshot--
https://www.lffl.org/2016/05/gtk-3-20-toolkit-si-aggiorna-migliora-wayland.html
TagsNo tags attached.
Fixed in Revision
LazTarget
WidgetsetGTK 3
Attached Files

Activities

CudaText man

2021-04-27 10:30

reporter  

rnd-box.png (2,073 bytes)   
rnd-box.png (2,073 bytes)   
tst-gtk3-black-bg.zip (8,578 bytes)

Anton Kavalenka

2021-04-27 13:24

reporter   ~0130615

I fixed left indent at 0.1 - i.e 10%
gtk3groupbox.diff (705 bytes)   
Index: lcl/interfaces/gtk3/gtk3widgets.pas
===================================================================
--- lcl/interfaces/gtk3/gtk3widgets.pas	(revision 65064)
+++ lcl/interfaces/gtk3/gtk3widgets.pas	(working copy)
@@ -3318,12 +3318,7 @@
   FCentralWidget := TGtkFixed.new;
   PGtkBin(Result)^.add(FCentralWidget);
   FCentralWidget^.set_has_window(True);
-
-  {fWidgetRGBA[0].R:=0.8;
-  fWidgetRGBA[0].Alpha:=0.7;
-  PgtkFrame(Result)^.override_color(GTK_STATE_NORMAL,@Self.FWidgetRGBA[0]);}
-  // nil resets color to gtk default
-  //FWidget^.override_background_color(GTK_STATE_FLAG_NORMAL, nil);
+  PgtkFrame(result)^.set_label_align(0.1,0.5);
 end;
 
 function TGtk3GroupBox.getText: String;
gtk3groupbox.diff (705 bytes)   

CudaText man

2021-04-27 15:09

reporter   ~0130622

Anton,
not quite good. now groupbox with big width shows 'left indent' about 60px, while 2nd groupsbox with small width shows 'indent' 2px. My demo shows it!

CudaText man

2021-04-27 15:10

reporter   ~0130623

Anton Kavalenka

2021-04-27 15:45

reporter   ~0130625

So some math has to be done on changing width

CudaText man

2021-04-29 12:04

reporter   ~0130652

What math, what are you talking about.

Anton Kavalenka

2021-04-29 12:14

reporter   ~0130653

Last edited: 2021-04-29 12:15

View 2 revisions

PgtkFrame(fWidget)^.set_label_align(prc,0.5);

Given:
w - Groupbox width
tw - text width
propose the formula for prc, knowing 0 - is leftmost pos, 0.5 - exact center, 1.0 - rightmost pos.

There is no way to specify absolute align except loading your own CSS file.

CudaText man

2021-04-29 22:46

reporter   ~0130664

prc = TextWidth('0')/w

Anton Kavalenka

2021-04-30 17:47

reporter   ~0130680

You are mistaken, enjoy playing with the formula.
gtk3widgets:3359
procedure TGtk3GroupBox.UpdateLabelPos;
gtk3widgets.diff (4,760 bytes)   
Index: lcl/interfaces/gtk3/gtk3widgets.pas
===================================================================
--- lcl/interfaces/gtk3/gtk3widgets.pas	(revision 65072)
+++ lcl/interfaces/gtk3/gtk3widgets.pas	(working copy)
@@ -383,6 +383,7 @@
   protected
     function CreateWidget(const Params: TCreateParams):PGtkWidget; override;
   public
+    procedure InitializeWidget;override;
     function getClientRect: TRect; override;
     function getPagesCount: integer;
     procedure InsertPage(ACustomPage: TCustomPage; AIndex: Integer);
@@ -639,7 +640,9 @@
     function CreateWidget(const Params: TCreateParams):PGtkWidget; override;
     function getText: String; override;
     procedure setText(const AValue: String); override;
+    procedure UpdateLabelPos;
   public
+    procedure SetBounds(ALeft,ATop,AWidth,AHeight:integer);override;
   end;
 
   { TGtk3ComboBox }
@@ -1173,7 +1176,8 @@
     end;
   GDK_BUTTON_RELEASE:
     begin
-      //if not (csClickEvents in TGtk3Widget(Data).LCLObject.ControlStyle) then
+      if not ((csClickEvents in TGtk3Widget(Data).LCLObject.ControlStyle) and
+         (csClicked in TGtk3Widget(Data).LCLObject.ControlState)) then
         Result := TGtk3Widget(Data).GtkEventMouse(Widget , Event);
     end;
   GDK_KEY_PRESS:
@@ -2582,7 +2586,7 @@
 
 procedure TGtk3Widget.DestroyWidget;
 begin
-  if IsWidgetOk and FOwnWidget and Assigned(fWidget) then
+  if IsValidHandle and FOwnWidget then
     FWidget^.destroy_;
   FWidget := nil;
 end;
@@ -2662,8 +2666,10 @@
     fWidget^.get_preferred_height(@mh,@nh);
     fWidget^.get_preferred_width(@mw,@nw);
 
-    LCLObject.Constraints.MinHeight:=mh;
-    LCLObject.Constraints.MinWidth:=mw;
+    if mh>LCLObject.Constraints.MinHeight then
+      LCLObject.Constraints.MinHeight:=mh;
+    if mw>LCLObject.Constraints.MinWidth then
+      LCLObject.Constraints.MinWidth:=mw;
   end;
   LCLIntf.SetProp(HWND(Self),'lclwidget',Self);
 
@@ -3318,12 +3324,7 @@
   FCentralWidget := TGtkFixed.new;
   PGtkBin(Result)^.add(FCentralWidget);
   FCentralWidget^.set_has_window(True);
-
-  {fWidgetRGBA[0].R:=0.8;
-  fWidgetRGBA[0].Alpha:=0.7;
-  PgtkFrame(Result)^.override_color(GTK_STATE_NORMAL,@Self.FWidgetRGBA[0]);}
-  // nil resets color to gtk default
-  //FWidget^.override_background_color(GTK_STATE_FLAG_NORMAL, nil);
+  PgtkFrame(result)^.set_label_align(0.1,0.5);
 end;
 
 function TGtk3GroupBox.getText: String;
@@ -3349,11 +3350,43 @@
       if PGtkFrame(Widget)^.get_label_widget = nil then
         PGtkFrame(Widget)^.set_label_widget(TGtkLabel.new(''));
       PGtkFrame(Widget)^.set_label(PgChar(AValue));
+      UpdateLabelPos;
     end;
   end;
 end;
 
+procedure TGtk3GroupBox.UpdateLabelPos;
+var
+  prc:single;
+  tw,w:integer;
+  dc:hdc;
+  sz:TSize;
+  bs:string;
+begin
+  if IsValidHandle then
+  begin
+    w:=fWidget^.get_allocated_width;
+    dc:=GetDc(HWND(Self));
+    bs:=PgtkFrame(fWidget)^.get_label;
+    GetTextExtentPoint(dc,Pchar(bs),length(bs),sz);
+    releasedc(HWND(Self),dc);
+    tw:=sz.cx;
+    // here to go more sophisticated proportion
+    if tw>w/2 then
+      prc:=0.1
+    else
+      prc:=(tw/2)/w;
+    PgtkFrame(fWidget)^.set_label_align(prc,0.5);
+  end;
+end;
 
+procedure TGtk3GroupBox.SetBounds(ALeft,ATop,AWidth,AHeight:integer);
+begin
+  inherited SetBounds(ALeft,ATop,AWidth,AHeight);
+  UpdateLabelPos;
+
+end;
+
 { TGtk3Editable }
 
 function gtk3EditableDelayedSelStart(AData: Pointer): gboolean; cdecl;
@@ -4578,6 +4611,12 @@
   // g_signal_connect_data(FCentralWidget,'select-page', TGCallback(@GtkNotebookSelectPage), Self, nil, 0);
 end;
 
+procedure TGtk3NoteBook.InitializeWidget;
+begin
+  inherited;
+  SetTabPosition(TCustomTabControl(LCLObject).TabPosition);
+end;
+
 function TGtk3NoteBook.getClientRect: TRect;
 var
   AAlloc: TGtkAllocation;
@@ -6732,8 +6771,8 @@
 
 procedure TGtk3Button.ButtonClicked(pData: pointer); cdecl;
 begin
-  if TObject(pdata) is TButton then
-  TButton(pdata).Click;
+  if TObject(pdata) is TCustomButton then
+  TCustomButton(pdata).Click;
 end;
 
 procedure TGtk3Button.SetImage(AImage: TBitmap);
Index: lcl/interfaces/gtk3/gtk3wsbuttons.pp
===================================================================
--- lcl/interfaces/gtk3/gtk3wsbuttons.pp	(revision 65072)
+++ lcl/interfaces/gtk3/gtk3wsbuttons.pp	(working copy)
@@ -87,7 +87,7 @@
   DebugLn('TGtk3WSBitBtn.CreateHandle');
   {$ENDIF}
   ABitBtn := TGtk3Button.Create(AWinControl, AParams);
-  with ARect do
+{  with ARect do
   begin
     x := AWinControl.Left;
     y := AWinControl.Top;
@@ -95,7 +95,7 @@
     height := AWinControl.Height;
   end;
 
-  ABitBtn.Widget^.set_allocation(@ARect);
+  ABitBtn.Widget^.set_allocation(@ARect);}
 
   Result := TLCLIntfHandle(ABitBtn);
   {$IFDEF GTK3DEBUGCORE}
gtk3widgets.diff (4,760 bytes)   

CudaText man

2021-04-30 19:29

reporter   ~0130685

Last edited: 2021-04-30 19:29

View 2 revisions

well, now it looks even worse (than w/o patch at all).

Issue History

Date Modified Username Field Change
2021-04-27 10:30 CudaText man New Issue
2021-04-27 10:30 CudaText man File Added: rnd-box.png
2021-04-27 10:30 CudaText man File Added: tst-gtk3-black-bg.zip
2021-04-27 13:24 Anton Kavalenka Note Added: 0130615
2021-04-27 13:24 Anton Kavalenka File Added: gtk3groupbox.diff
2021-04-27 15:09 CudaText man Note Added: 0130622
2021-04-27 15:10 CudaText man Note Added: 0130623
2021-04-27 15:10 CudaText man File Added: Screenshot from 2021-04-27 16-10-33.png
2021-04-27 15:45 Anton Kavalenka Note Added: 0130625
2021-04-29 12:04 CudaText man Note Added: 0130652
2021-04-29 12:14 Anton Kavalenka Note Added: 0130653
2021-04-29 12:15 Anton Kavalenka Note Edited: 0130653 View Revisions
2021-04-29 22:46 CudaText man Note Added: 0130664
2021-04-30 17:47 Anton Kavalenka Note Added: 0130680
2021-04-30 17:47 Anton Kavalenka File Added: gtk3widgets.diff
2021-04-30 19:29 CudaText man Note Added: 0130685
2021-04-30 19:29 CudaText man Note Edited: 0130685 View Revisions