Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-03

TEditButton alignment

16 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Juha Manninen

It is a well known issue that TEditButton aligns wrong.

In the last note of issue
http://bugs.freepascal.org/view.php?id=12155
Mattias writes :
"The best solution is to redesign TEditButton as an edit and a button in a panel. I started it as proof of concept in
examples/groupedcontrols.
This will break all current workarounds, so it will not be done for 1.0. "

It was discussed at forum:
http://lazarus.freepascal.org/index.php/topic,19496.msg115847.html#msg115847

I would like to know if this "edit and button in a panel" strategy is still valid or does it have some hidden traps?
I don't see any problem with it myself.
Then it could be implemented in trunk.

The only philosophical problem might be that it doesn't use the corresponding native widgetset control even if there was one. Not all widgetsets have it.

Juha

Reply by email

Flávio Etrusco
to Juha Manninen
Juha Manninen wrote 23 lines
It is a well known issue that TEditButton aligns wrong. In the last note of issue http://bugs.freepascal.org/view.php?id=12155 Mattias writes : "The best solution is to redesign TEditButton as an edit and a button in a panel. I started it as proof of concept in examples/groupedcontrols. This will break all current workarounds, so it will not be done for 1.0. " It was discussed at forum: http://lazarus.freepascal.org/index.php/topic,19496.msg115847.html#msg115847 I would like to know if this "edit and button in a panel" strategy is still valid or does it have some hidden traps? I don't see any problem with it myself. Then it could be implemented in trunk. The only philosophical problem might be that it doesn't use the corresponding native widgetset control even if there was one. Not all widgetsets have it. Juha

I had a patch which fixed alignment problems (I know of) by making the margin calculation virtual and placing the button inside/over the edit bounds (increasing the margin accordingly). I don't think I have it around anymore but the approach was quite simple anyway.

That said, maybe using a panel is the way to go (even if it needs some work-arounds to make it behave more like a single control to the developer and incurs a little overhead).

Best regards,
Fl?vio

Reply by email

Vojtěch Čihák

Hello,
?
I already tried to extend?"examples/groupedcontrols" make it 100% compatible with current implementation. Note that instead of TTransparentPanel I used a pure TWinControl. AFAIR the difference is that?TTransparentPanel has Canvas (which we don't need here) + some flags of TComponentState. It works well as a grid cell editor and also all descendant components works (TDirectoryEdit, TFileNameEdit, ...). The only remaining problem is property ButtonOnlyWhenFocus. This property was probably NOT implemented for Delphi compatibility. It is difficult to reach the same behaviour with the new approach. Let's say Edit is 100px wide and Button 20px (i.e. 120px total). Currently only Button visibility changes.
New grouped approach requires enlarge on SetFocus and shrink on KillFocus. I tried several hacks and reached ~90% success but the code is not very staightforward and KISS. It should be better to change behaviour: focused: 80 + 20 px; not focused: 100px Edit. This is more native since LCL anchoring automatically skips invisible components. Or leave this property (mark it as "deprecated").
?
So I would like to know if there were some special reason to use TransparentPanel and what to do with property ButtonOnlyWhenFocus. ?
Thanks.
?
Vojtech Cihak a.k.a. Blaazen
?

Reply by email

Juha Manninen
to Flávio Etrusco: On Mon, Mar 18, 2013 at 5:48 PM, Juha Manninen I had a patch which fixed alignment…
Fl?vio Etrusco wrote
I had a patch which fixed alignment problems (I know of) by making the margin calculation virtual and placing the button inside/over the edit bounds (increasing the margin accordingly). I don't think I have it around anymore but the approach was quite simple anyway.

Making margin calculation virtual where? In TCustomEdit?

Does it require code in the widgetset level?

Juha

Reply by email

Juha Manninen
to Juha Manninen
Juha Manninen wrote
Does it require code in the widgetset level?

Ok, my question was stupid.
This obviously needs widgetset code to prevent the text going under the button. That's why it is not implemented yet. The Panel solution from Mattias does not require widgetset code .

Juha

Reply by email

Graeme Geldenhuys
to Juha Manninen: On Mon, Mar 18, 2013 at 11:51 PM, Juha Manninen Ok, my question was stupid. This…
Juha Manninen wrote
The Panel solution from Mattias does not require widgetset code .

Correct, but you might find problems with the Lazarus Forms Designer.

tiOPF's custom components are all "composite components" (panel holding other components in place), but Lazarus IDE had a nightmare with them, and it was easy to crash the IDE. Things like the embedded components could be moved and resized when they shouldn't, embedded components could be deleted etc. Those same tiOPF components worked perfectly under the Delphi Forms Designer. To be fair, I last looked at those composite components under Lazarus Form Designer in the 0.9.30 days (and gave up due to all the Form Designer bugs), so don't know if the designer has improved since then.

Regards,
- Graeme -

Reply by email

Mattias Gaertner
to Graeme Geldenhuys
Show quoted text 12 lines
On 2013-03-18 21:59, Juha Manninen wrote: > The Panel solution from Mattias > does not require widgetset code . Correct, but you might find problems with the Lazarus Forms Designer. tiOPF's custom components are all "composite components" (panel holding other components in place), but Lazarus IDE had a nightmare with them, and it was easy to crash the IDE. Things like the embedded components could be moved and resized when they shouldn't, embedded components could be deleted etc. Those same tiOPF components worked perfectly under the Delphi Forms Designer.

Is there a bug report?

To be fair, I last looked at those composite components under Lazarus Form Designer in the 0.9.30 days (and gave up due to all the Form Designer bugs), so don't know if the designer has improved since then.

Mattias

Reply by email

Mattias Gaertner
to Juha Manninen: It is a well known issue that TEditButton aligns wrong. In the last note of issue…
Show quoted text 15 lines
It is a well known issue that TEditButton aligns wrong. In the last note of issue http://bugs.freepascal.org/view.php?id=12155 Mattias writes : "The best solution is to redesign TEditButton as an edit and a button in a panel. I started it as proof of concept in examples/groupedcontrols. This will break all current workarounds, so it will not be done for 1.0. " It was discussed at forum: http://lazarus.freepascal.org/index.php/topic,19496.msg115847.html#msg115847 I would like to know if this "edit and button in a panel" strategy is still valid or does it have some hidden traps?

There might be some transparency problems with a TPanel and of course a TPanel is not a TCustomEdit (inheritance).

Mattias

Reply by email

Flávio Etrusco
to Juha Manninen: On Mon, Mar 18, 2013 at 11:41 PM, Fl?vio Etrusco Making margin calculation virtual where?…
Juha Manninen wrote 12 lines
On Mon, Mar 18, 2013 at 11:41 PM, Fl?vio Etrusco wrote: > I had a patch which fixed alignment problems (I know of) by making the > margin calculation virtual and placing the button inside/over the edit > bounds (increasing the margin accordingly). I don't think I have it > around anymore but the approach was quite simple anyway. Making margin calculation virtual where? In TCustomEdit? Does it require code in the widgetset level? Juha

It was something like this (patch attached).

Best regards,
Fl?vio
-------------- next part --------------
A non-text attachment was scrubbed...
Name: buttonedit.patch
Type: application/octet-stream
Size: 12080 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130319/dee660a0/attachment.obj>

Reply by email

Mattias Gaertner
to Flávio Etrusco

On Tue, 19 Mar 2013 03:22:51 -0300
Fl?vio Etrusco wrote:

Nice idea. This is the important part:

+  { TEditButtonSpacing }
+
+  TEditButtonSpacing = class(TControlBorderSpacing)
+  public
+    constructor Create(OwnerControl: TCustomEditButton);
+    procedure GetSpaceAround(out SpaceAround: TRect); override;
+    function GetSideSpace(Kind: TAnchorKind): Integer; override;
+  end;
+
+function
  TCustomEditButton.CreateControlBorderSpacing:TControlBorderSpacing;
+begin
+  Result := TEditButtonSpacing.Create(Self);
+end;
+
+{ TEditButtonSpacing }
+
+constructor TEditButtonSpacing.Create(OwnerControl: TCustomEditButton);
+begin
+  inherited Create(OwnerControl);
+end;
+
+procedure TEditButtonSpacing.GetSpaceAround(out SpaceAround: TRect);
+begin
+  inherited GetSpaceAround(SpaceAround);
+  if BiDiMode = bdLeftToRight then
+    Inc(SpaceAround.Right, TCustomEditButton(Control).ButtonWidth)
+  else
+    Inc(SpaceAround.Left, TCustomEditButton(Control).ButtonWidth)
+end;
+
+function TEditButtonSpacing.GetSideSpace(Kind: TAnchorKind): Integer;
+begin
+  Result := inherited GetSideSpace(Kind);
+  if Kind = akRight and then
+  begin
+    if BiDiMode = bdLeftToRight then
+      Inc(Result, TCustomEditButton(Control).ButtonWidth);
+  end
+  else if Kind = akLeft and BiDiMode  bdLeftToRight then
+    Inc(Result, TCustomEditButton(Control).ButtonWidth);
+end;

Mattias

Reply by email

Juha Manninen
to Juha Manninen: On Tue, Mar 19, 2013 at 8:22 AM, Fl?vio Etrusco It does not compile here. It complains…
Juha Manninen wrote
It does not compile here. It complains about BiDiMode in TEditButtonSpacing.GetSpaceAround.

Ok, I changed it as below and it works. I don't know how you tested the broken code but it looks very nice.
No widgetset code and the component inherits from TCustomEdit. The code is also clean, no ugly hacks. Why didn't you show it earlier?

Regards
Juha

-------------------

procedure TEditButtonSpacing.GetSpaceAround(out SpaceAround: TRect);
begin
  inherited GetSpaceAround(SpaceAround);
  if Control.BiDiMode = bdLeftToRight then
    Inc(SpaceAround.Right, TCustomEditButton(Control).ButtonWidth)
  else
    Inc(SpaceAround.Left, TCustomEditButton(Control).ButtonWidth)
end;
function TEditButtonSpacing.GetSideSpace(Kind: TAnchorKind): Integer;
begin
  Result := inherited GetSideSpace(Kind);
  if Kind = akRight then
  begin
    if Control.BiDiMode = bdLeftToRight then
      Inc(Result, TCustomEditButton(Control).ButtonWidth);
  end
  else if (Kind = akLeft) and (Control.BiDiMode  bdLeftToRight) then
    Inc(Result, TCustomEditButton(Control).ButtonWidth);
end;

Reply by email

Vojtěch Čihák
to Juha Manninen

Hello,
?
I tested the patch from Fl?vio + correction from Juha in Linux+Qt. Anchoring now works well (especially right anchoring). ?
I tested it also as a grid cell editor:
?
procedure TForm1.StringGrid1SelectEditor(Sender: TObject; aCol, aRow: Integer; var Editor: TWinControl); var aRect: TRect;
begin
EditButton1.Parent:=StringGrid1;
aRect:=StringGrid1.CellRect(aCol, aRow);
dec(aRect.Right, EditButton1.ButtonWidth); //correction that it will fit to a cell EditButton1.BoundsRect:=aRect;
Editor:=EditButton1;
end; ?
?
There only one issue:
If I click button of stand-alone EditButton then the Edit part keeps focus. If I click button of cell-editor EditButton then the Edit part losts focus. ?
Thanks
?
Vojtech aka Blaazen?

Reply by email

Juha Manninen
to Vojtěch Čihák
Vojt?ch ?ih?k wrote
There only one issue: If I click button of stand-alone EditButton then the Edit part keeps focus. If I click button of cell-editor EditButton then the Edit part losts focus.

There remains another problem. The button is still outside the component bounds, isn't it.
That is why you must do this:

dec(aRect.Right, EditButton1.ButtonWidth); //correction that it will fit to a cell

The Edit+Button on a Panel (or something) would solve that problem. All parts of a component should be inside its bounds obviously,

I will test more later when I get home.

Juha

Reply by email