Recent

Author Topic: Guide Lines Behavior  (Read 817 times)

GerholdtSchnaps

  • Newbie
  • Posts: 1
Guide Lines Behavior
« on: January 24, 2025, 01:35:16 pm »
hi. I'm new here. I came from delphi. And I have a lot of questions...

please consider this situation. The blue line is the guide line. the red line is mine to show the offset. and purple to show how the text is aligned. is it possible to fix this using options, or should I disable recommendations?

majolika

  • New Member
  • *
  • Posts: 41
Re: Guide Lines Behavior
« Reply #1 on: January 25, 2025, 05:54:51 am »
Hi! I'm new here too. :)
I don't know if I'm right but I think this happens because of different client areas of TButton and TEdit.
If you uncheck AutoSize property of TEdit1 and anchor its bottom to TButton1 bottom you'll see situation like this (1st picture in attach): tops and bottoms aligned but...
Check ClientHieght of both controls in a manner like this and you'll see something like this (2nd picture in attach).

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   ShowMessage('Button1.ClinetHeight = ' + Button1.ClientHeight.ToString + ', Edit1.ClinetHeght = ' + Edit1.ClientHeight.ToString);
  4. end;
  5.  

But I have no idea how to fix this.

majolika

  • New Member
  • *
  • Posts: 41
Re: Guide Lines Behavior
« Reply #2 on: January 25, 2025, 06:11:12 am »
You can dive into a source of TEdit to see why the text inside is aligned like that but it might be a too long journey.

n7800

  • Full Member
  • ***
  • Posts: 229
Re: Guide Lines Behavior
« Reply #3 on: January 26, 2025, 09:37:00 am »
I don't quite understand your question. I take it this is a screenshot from Delphi? Lazarus doesn't show guidelines for the text (purple in the screenshot).

If you want the text inside the button and edit to be on the same level, it's unlikely to be possible, since Lazarus is cross-platform. It usually uses native widgets, which depend on the OS, its theme, widget set... They can be anything, and the text position in them cannot be guaranteed.

wp

  • Hero Member
  • *****
  • Posts: 12572
Re: Guide Lines Behavior
« Reply #4 on: January 26, 2025, 12:15:34 pm »
In many cases you can achieve almost perfect alignment of the text baseline (within 1 pixel) by anchoring the vertical center of controls using the anchor editor. This is because the text within TLabel, TEdit, TCombobox, TButton, is centered already and because usually all controls have the same font size (i.e. text height).

Suppose you want to have a button, a label and a edit (in this order) in a row and you want to place them vertically such that their caption/text is at the same baseline:
  • Drop the three controls on the form (or panel, or whatever...) and position them roughly
  • Open the Anchor Editor
  • Select the label in the form designer
  • In the anchor editor, go to the "Top anchoring" group and select the button control from the combobox. Then click the middle alignment button in the group to center the label with respect to the button. Note that the icon of this button tries to express just this (the other buttons in this group are for vertical anchoring at the top and bottom sides, respectively)
  • Repeat with the edit control
  • Now all three controls are anchored vertically and centered with respect to the button. If you drag the button vertically to another place, the label and the edit will follow (but this also means that you cannot drag the label and edit vertically any more)
  • You can go a step further and anchor also the controls horizontally
« Last Edit: January 26, 2025, 04:44:48 pm by wp »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5846
  • Compiler Developer
Re: Guide Lines Behavior
« Reply #5 on: January 26, 2025, 03:11:51 pm »
please consider this situation. The blue line is the guide line. the red line is mine to show the offset. and purple to show how the text is aligned. is it possible to fix this using options, or should I disable recommendations?

The problem is that it's not generally possible to determine the alignment of the text, because it depends on both the widget set and the theme and thus it matching for one would result in a mismatch for another. Delphi has it simpler here, because the VCL only supports Windows.

 

TinyPortal © 2005-2018