View Issue Details

IDProjectCategoryView StatusLast Update
0038620LazarusWidgetsetpublic2021-05-13 09:21
ReporterCudaText man Assigned ToJuha Manninen  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
OSUbuntu 20.4 x64 
Product Version2.1 (SVN) 
Summary0038620: gtk3: TrackBar has problems
Descriptiondemo added.

- panel (parent of Trackbar) is stretched somehow (not fitting on form)
- on dragging the Trackbar's slider, I see not OK slider position, it's not at the mouse pos but shifted by 5-10 pixels

TagsNo tags attached.
Fixed in Revisionr65090, r65109
LazTarget-
WidgetsetGTK 3
Attached Files

Relationships

related to 0038811 closedJuha Manninen gtk3: GroupBox designed Width is broken in runtime 

Activities

CudaText man

2021-03-14 09:02

reporter  

gtk2-gtk3.png (20,128 bytes)   
gtk2-gtk3.png (20,128 bytes)   
tst-gtk3-trackbar.zip (2,676 bytes)

CudaText man

2021-03-27 21:36

reporter   ~0129926

Anton, maybe you can help here?

Anton Kavalenka

2021-05-03 13:57

reporter   ~0130740

Trackbar automatically creates marks inside. For very high amount of marks it decides to enlarge itself.
This patch bypasses marks creation for such situation.
gtk3tbar.diff (2,982 bytes)   
Index: lcl/interfaces/gtk3/gtk3widgets.pas
===================================================================
--- lcl/interfaces/gtk3/gtk3widgets.pas	(revision 65083)
+++ lcl/interfaces/gtk3/gtk3widgets.pas	(working copy)
@@ -1174,7 +1174,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:
@@ -2583,7 +2584,7 @@
 
 procedure TGtk3Widget.DestroyWidget;
 begin
-  if IsWidgetOk and FOwnWidget and Assigned(fWidget) then
+  if IsValidHandle and FOwnWidget then
     FWidget^.destroy_;
   FWidget := nil;
 end;
@@ -2663,8 +2664,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);
 
@@ -3831,11 +3834,16 @@
 function TGtk3TrackBar.CreateWidget(const Params: TCreateParams): PGtkWidget;
 var
   ATrack: TCustomTrackBar;
-  Alloc:TGtkAllocation;
 begin
   ATrack := TCustomTrackBar(LCLObject);
   FWidgetType := FWidgetType + [wtTrackBar];
-  Result := PGtkWidget(TGtkScale.new(Ord(ATrack.Orientation), nil));
+
+ { Result := TGtkHBox.new(1,0);
+  fCentralWidget:=PGtkWidget(TGtkScale.new(Ord(ATrack.Orientation), nil));
+  PgtkBox(Result)^.add(fCentralWidget);}
+
+  Result :=PGtkWidget(TGtkScale.new(Ord(ATrack.Orientation), nil));
+
   FOrientation := ATrack.Orientation;
   if ATrack.Reversed then
     PGtkScale(Result)^.set_inverted(True);
@@ -3861,7 +3869,8 @@
 
 procedure TGtk3TrackBar.SetTickMarks(AValue: TTickMark; ATickStyle: TTickStyle);
 var
-  i: Integer;
+  i,cnt: Integer;
+  Track:TCustomTrackbar;
 begin
   if IsWidgetOK then
   begin
@@ -3870,7 +3879,12 @@
       PGtkScale(FWidget)^.clear_marks
     else
     begin
-      for i := TCustomTrackbar(LCLObject).Min to TCustomTrackbar(LCLObject).Max do
+      Track:=TCustomTrackbar(LCLObject);
+      cnt:=round(abs(Track.max-Track.min)/Track.LineSize);
+      // highly-dense marks just enlarge GtkScale automatically
+      // it is up to user concent to do this
+      if cnt*4<Track.Width then
+      for i := Track.Min to Track.Max do
       begin
         if TCustomTrackbar(LCLObject).Orientation = trHorizontal then
         begin
@@ -6734,8 +6748,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);
gtk3tbar.diff (2,982 bytes)   

Juha Manninen

2021-05-07 09:08

developer   ~0130783

Applied, thanks.

CudaText man

2021-05-09 14:30

reporter   ~0130808

Excuse me, on the different demo (attached) I still see that gtk3 TrackBar is much wider than in design-time.
picture!

CudaText man

2021-05-09 14:30

reporter   ~0130809

tst-gtk3-black-bg.zip (7,608 bytes)
gtk2-gtk3-2.png (105,514 bytes)   
gtk2-gtk3-2.png (105,514 bytes)   

Anton Kavalenka

2021-05-12 14:13

reporter   ~0130830

Patch with minor housekeeping.
Marks are created when specified width is enough to fit cnt marks

cnt*TrackBar.LineSize<Track.Width (or Height)
gtk3trackbar.diff (4,003 bytes)   
Index: lcl/interfaces/gtk3/gtk3bindings/lazgtk3.pas
===================================================================
--- lcl/interfaces/gtk3/gtk3bindings/lazgtk3.pas	(revision 65106)
+++ lcl/interfaces/gtk3/gtk3bindings/lazgtk3.pas	(working copy)
@@ -539,13 +539,13 @@
   GTK_BUILDER_ERROR_DUPLICATE_ID: TGtkBuilderError = 8;
 
 type
-  TGtkPositionType = Integer;
-const
+  TGtkPositionType = (
   { GtkPositionType }
-  GTK_POS_LEFT: TGtkPositionType = 0;
-  GTK_POS_RIGHT: TGtkPositionType = 1;
-  GTK_POS_TOP: TGtkPositionType = 2;
-  GTK_POS_BOTTOM: TGtkPositionType = 3;
+  GTK_POS_LEFT = 0,
+  GTK_POS_RIGHT = 1,
+  GTK_POS_TOP = 2,
+  GTK_POS_BOTTOM = 3
+  );
 
 type
   TGtkReliefStyle = Integer;
Index: lcl/interfaces/gtk3/gtk3widgets.pas
===================================================================
--- lcl/interfaces/gtk3/gtk3widgets.pas	(revision 65106)
+++ lcl/interfaces/gtk3/gtk3widgets.pas	(working copy)
@@ -3866,13 +3866,18 @@
 procedure TGtk3TrackBar.SetScalePos(AValue: TTrackBarScalePos);
 begin
   if IsWidgetOK then
-    PGtkScale(FWidget)^.set_value_pos(Ord(AValue));
+    PGtkScale(FWidget)^.set_value_pos(TGtkPositionType(AValue));
 end;
 
 procedure TGtk3TrackBar.SetTickMarks(AValue: TTickMark; ATickStyle: TTickStyle);
 var
-  i,cnt: Integer;
+  i,cnt,fldw: Integer;
   Track:TCustomTrackbar;
+const
+  tick_map:array[TTrackBarOrientation,0..1] of TGtkPositionType =
+    ((GTK_POS_TOP,GTK_POS_BOTTOM), // trHorizontal
+     (GTK_POS_LEFT,GTK_POS_RIGHT) // trVertical
+    );
 begin
   if IsWidgetOK then
   begin
@@ -3881,26 +3886,22 @@
       PGtkScale(FWidget)^.clear_marks
     else
     begin
+      PGtkScale(FWidget)^.clear_marks;
       Track:=TCustomTrackbar(LCLObject);
       cnt:=round(abs(Track.max-Track.min)/Track.LineSize);
       // highly-dense marks just enlarge GtkScale automatically
       // it is up to user concent to do this
-      if cnt*4<Track.Width then
+      if Track.Orientation=trHorizontal then
+        fldw:=Track.Width
+      else
+        fldw:=Track.Height;
+      if cnt*Track.LineSize<fldw then
       for i := Track.Min to Track.Max do
       begin
-        if TCustomTrackbar(LCLObject).Orientation = trHorizontal then
-        begin
-          if AValue in [tmBoth, tmTopLeft] then
-            PGtkScale(FWidget)^.add_mark(gDouble(i), GTK_POS_TOP, nil);
-          if AValue in [tmBoth, tmBottomRight] then
-            PGtkScale(FWidget)^.add_mark(gDouble(i), GTK_POS_BOTTOM, nil);
-        end else
-        begin
-          if AValue in [tmBoth, tmTopLeft] then
-            PGtkScale(FWidget)^.add_mark(gDouble(i), GTK_POS_LEFT, nil);
-          if AValue in [tmBoth, tmBottomRight] then
-            PGtkScale(FWidget)^.add_mark(gDouble(i), GTK_POS_RIGHT, nil);
-        end;
+        if AValue in [tmBoth, tmTopLeft] then
+          PGtkScale(FWidget)^.add_mark(gDouble(i), tick_map[Track.Orientation,0], nil);
+        if AValue in [tmBoth, tmBottomRight] then
+          PGtkScale(FWidget)^.add_mark(gDouble(i), tick_map[Track.Orientation,1], nil);
       end;
     end;
   end;
@@ -4712,10 +4713,10 @@
 const
   GtkPositionTypeMap: array[TTabPosition] of TGtkPositionType =
   (
-    2, // { tpTop    } GTK_POS_TOP,
-    3, // { tpBottom } GTK_POS_BOTTOM,
-    0, // { tpLeft   } GTK_POS_LEFT,
-    1 // { tpRight  } GTK_POS_RIGHT
+    { tpTop    } GTK_POS_TOP,
+    { tpBottom } GTK_POS_BOTTOM,
+    { tpLeft   } GTK_POS_LEFT,
+    { tpRight  } GTK_POS_RIGHT
   );
 begin
   if IsWidgetOK then
@@ -6705,7 +6706,7 @@
   FLayout := AValue;
   if IsWidgetOk then
   begin
-    PGtkButton(FWidget)^.set_image_position(AValue);
+    PGtkButton(FWidget)^.set_image_position(TGtkPositionType(AValue));
     // set margin and spacing when layout is changed
     SetMargin(FMargin);
   end;
@@ -6796,7 +6797,7 @@
   LCLObject.ControlStyle:=LCLObject.ControlStyle+[csClickEvents];
 
   FMargin := -1;
-  FLayout := GTK_POS_LEFT;
+  FLayout := ord(GTK_POS_LEFT);
   FSpacing := 2; // default gtk3 spacing is 2
 end;
 
gtk3trackbar.diff (4,003 bytes)   

CudaText man

2021-05-12 18:50

reporter   ~0130839

good job,now solved! Let's fix more gtk3 bugs.

Juha Manninen

2021-05-13 07:28

developer   ~0130845

Applied, thanks.

Issue History

Date Modified Username Field Change
2021-03-14 09:02 CudaText man New Issue
2021-03-14 09:02 CudaText man File Added: gtk2-gtk3.png
2021-03-14 09:02 CudaText man File Added: tst-gtk3-trackbar.zip
2021-03-27 21:36 CudaText man Note Added: 0129926
2021-05-03 13:57 Anton Kavalenka Note Added: 0130740
2021-05-03 13:57 Anton Kavalenka File Added: gtk3tbar.diff
2021-05-07 08:37 Juha Manninen Assigned To => Juha Manninen
2021-05-07 08:37 Juha Manninen Status new => assigned
2021-05-07 08:39 Juha Manninen Relationship added related to 0038811
2021-05-07 09:08 Juha Manninen Status assigned => resolved
2021-05-07 09:08 Juha Manninen Resolution open => fixed
2021-05-07 09:08 Juha Manninen Fixed in Revision => r65090
2021-05-07 09:08 Juha Manninen LazTarget => -
2021-05-07 09:08 Juha Manninen Widgetset GTK 3 => GTK 3
2021-05-07 09:08 Juha Manninen Note Added: 0130783
2021-05-07 11:35 CudaText man Status resolved => closed
2021-05-09 14:30 CudaText man Status closed => assigned
2021-05-09 14:30 CudaText man Resolution fixed => open
2021-05-09 14:30 CudaText man Note Added: 0130808
2021-05-09 14:30 CudaText man Note Added: 0130809
2021-05-09 14:30 CudaText man File Added: tst-gtk3-black-bg.zip
2021-05-09 14:30 CudaText man File Added: gtk2-gtk3-2.png
2021-05-12 14:13 Anton Kavalenka Note Added: 0130830
2021-05-12 14:13 Anton Kavalenka File Added: gtk3trackbar.diff
2021-05-12 18:50 CudaText man Note Added: 0130839
2021-05-13 07:28 Juha Manninen Status assigned => resolved
2021-05-13 07:28 Juha Manninen Resolution open => fixed
2021-05-13 07:28 Juha Manninen Fixed in Revision r65090 => r65090, r65109
2021-05-13 07:28 Juha Manninen Widgetset GTK 3 => GTK 3
2021-05-13 07:28 Juha Manninen Note Added: 0130845
2021-05-13 09:21 CudaText man Status resolved => closed