Recent

Author Topic: How can Lazarus implement Left and Top properties in GTK2  (Read 537 times)

Tommi

  • Sr. Member
  • ****
  • Posts: 256
How can Lazarus implement Left and Top properties in GTK2
« on: January 12, 2026, 10:00:57 am »
Using pure GTK2 API (but GTK3 also) I cannot find any direct way to use a lot of properties that I can find in Lazarus.

For example: Left property of TLabel, how is implemented?
It's not easy to find it into Lazarus source code.

Thank you.

Zvoni

  • Hero Member
  • *****
  • Posts: 3252
Re: How can Lazarus implement Left and Top properties in GTK2
« Reply #1 on: January 12, 2026, 11:01:49 am »
Left/Top are implemented in TControl, from which TLabel inherits,
Specifically SetLeft/SetTop, which both branch to SetBounds, which branches to ChangeBounds.
Though there is nothing Widgetset-specific there
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Tommi

  • Sr. Member
  • ****
  • Posts: 256
Re: How can Lazarus implement Left and Top properties in GTK2
« Reply #2 on: January 12, 2026, 11:31:42 am »
Left/Top are implemented in TControl, from which TLabel inherits,
Specifically SetLeft/SetTop, which both branch to SetBounds, which branches to ChangeBounds.
Though there is nothing Widgetset-specific there

So, if I understand correctly, TLabel has nothing to do with GTKLabel, but it is completely redesigned?

Zvoni

  • Hero Member
  • *****
  • Posts: 3252
Re: How can Lazarus implement Left and Top properties in GTK2
« Reply #3 on: January 12, 2026, 11:52:04 am »
Left/Top are implemented in TControl, from which TLabel inherits,
Specifically SetLeft/SetTop, which both branch to SetBounds, which branches to ChangeBounds.
Though there is nothing Widgetset-specific there

So, if I understand correctly, TLabel has nothing to do with GTKLabel, but it is completely redesigned?
I wouldn't say that, since i'm not very knowledgable in that.
I'd hazard a guess, that "TControl"/"TLabel" still branches out to Widgetset-specific code (and there would be the API-calls), but i've no idea how to find that here.

Your best bet would likely be: "../lcl/interfaces/gtk2"
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12645
  • FPC developer.
Re: How can Lazarus implement Left and Top properties in GTK2
« Reply #4 on: January 12, 2026, 12:06:48 pm »
Left/Top are implemented in TControl, from which TLabel inherits,
Specifically SetLeft/SetTop, which both branch to SetBounds, which branches to ChangeBounds.
Though there is nothing Widgetset-specific there

So, if I understand correctly, TLabel has nothing to do with GTKLabel, but it is completely redesigned?

See lcl/interfaces/gtk2, that is the GTK2 specific part.   It is complicated though, since many other widgets are composite and also use labels (like, obviously tlabelededit). Grepping this folder for pgtklabel might be useful

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12109
  • Debugger - SynEdit - and more
    • wiki
Re: How can Lazarus implement Left and Top properties in GTK2
« Reply #5 on: January 12, 2026, 12:54:35 pm »
It really depends what you look for, and may be indeed complex (as it needs to work for all target WS).

I don't know if the LCL gtk2 uses a gtk2 label widget. Since TLabel is a GraphicControl and that means it paints directly onto the canvas of its parent.  But if you take a checkbox, that would (afaik) use some gtk2 checkbox widget of the gtk2 libs.

Then you have to follow the trail through the LCL, left goes to SetBounds and so forth.

Each LCL Control has
Code: Pascal  [Select][+][-]
  1.    class procedure WSRegisterClass; override;

For TCheckbox that goes to WSRegisterCustomCheckBox
Code: Pascal  [Select][+][-]
  1. function WSRegisterCustomCheckBox: Boolean;    external name 'WSRegisterCustomCheckBox';
Which is like a virtual method, just without class... And at compile (actually link-) time. The linker connects this to
Code: Pascal  [Select][+][-]
  1. unit Gtk2WSFactory; // lcl/interfaces/gtk2/gtk2wsfactory.pas
  2. ...
  3. function RegisterCustomCheckBox: Boolean; alias : 'WSRegisterCustomCheckBox';
  4. begin
  5. //  RegisterWSComponent(TCustomCheckBox, TGtk2WSCustomCheckBox);
  6.   RegisterWSComponent(TCustomCheckBox, TGtk2WSCustomCheckBox);
  7.   Result := True;
  8. end;

And then TGtk2WSCustomCheckBox is where everything for the checkbox connects to the gtk2 libs.

And then you have code like
Code: Pascal  [Select][+][-]
  1. TWSWinControlClass(WidgetSetClass).FooBar // class cast and method may vary
which is where the LCL call that connection.

And so, when you change Left, then it will eventually be forwarded into the gtk2 ws code, and then be given to the gtk2 libs.

Of course, for Left that is only if a control has a widget in the gtk2 libs. Otherwise its drawn internally.

Tommi

  • Sr. Member
  • ****
  • Posts: 256
Re: How can Lazarus implement Left and Top properties in GTK2
« Reply #6 on: January 12, 2026, 03:46:47 pm »
Studying the contento of .../lcl/interfaces/gtk and .../lcl/interfaces/gtk2 I understand that the vast majority of widgets are redesigned and just few native elements of gtk are used. Properties like left, top, width, height are changed using gtk_widget_size_allocate.

 

TinyPortal © 2005-2018