Recent

Author Topic: Scrolling ScrollBox to "invisible" child control  (Read 7773 times)

zoltanleo

  • Sr. Member
  • ****
  • Posts: 488
Scrolling ScrollBox to "invisible" child control
« on: April 26, 2021, 03:51:33 pm »
Hi all.

I need a help.

If the parent of control is a scrollbar component, then the TScrollBox.ScrollInView() method for the control works correctly when it receives input focus.

If I put a panel with controls on the scrollbox, then I cannot display the control when it receives input focus by ScrollInView() .

Why?
« Last Edit: April 26, 2021, 04:23:11 pm by zoltanleo »
Win10 LTSC x64/Deb 11 amd64(gtk2/qt5)/Darwin Cocoa (Monterey):
Lazarus x32/x64 2.3(trunk); FPC 3.3.1 (trunk), FireBird 3.0.10; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Scrolling ScrollBox to "invisible" child control
« Reply #1 on: April 26, 2021, 11:12:45 pm »
You know what they call that ? They call it a bug!

 :D

Just looking at the code I can see it does not search the list of parents until it reaches the scrollbox so what you are getting is the offset start of where the EDIT control lives within the Tpanel


 You can correct this yourself of course if you wish, you will need to get the screen cords of the EDIT control, and get the screen cords of the Scrollbox.. Subtract the EDIT control from the Screen cords and that is  your offset to give the scrollbars..


 Or you could report this to the bug site and see where it goes from there ?
The only true wisdom is knowing you know nothing

zoltanleo

  • Sr. Member
  • ****
  • Posts: 488
Re: Scrolling ScrollBox to "invisible" child control
« Reply #2 on: May 01, 2021, 01:14:40 am »
Or you could report this to the bug site and see where it goes from there ?

Hi jamie.

Thank U for answer. I spent 2 days trying to correct the code myself. But I couldn't solve the problem until the end. I wrote about the problem on the mailing list.

https://lists.lazarus-ide.org/pipermail/lazarus/2021-May/239044.html

Let's hope that some of the maintainers will pay attention to this.
Win10 LTSC x64/Deb 11 amd64(gtk2/qt5)/Darwin Cocoa (Monterey):
Lazarus x32/x64 2.3(trunk); FPC 3.3.1 (trunk), FireBird 3.0.10; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Scrolling ScrollBox to "invisible" child control
« Reply #3 on: May 01, 2021, 01:51:12 am »
Ok, Please drop this in your source code and use this instead of the provided ScrollInView..

Tell us if that works any better ..

I took the existing "ScrollInView" source code and inserted a fix but for now you can try this directly in your app to see  how it works.

Code: Pascal  [Select][+][-]
  1. procedure Scroll_it_inview(AScrollWindow:TScrollingWinControl; AControl: TControl);
  2. var
  3.   xRect: TRect;
  4.   APar:TControl; //added;
  5. begin
  6. With AScrollWindow do
  7.  Begin
  8.   if AControl=nil then
  9.     Exit;
  10.   xRect := AControl.BoundsRect;
  11.  {---Added---}
  12.   APar := ACOntrol.Parent;
  13.   While APar <> AScrollWindow do
  14.    Begin
  15.     OffsetRect(xRect, Apar.BoundsRect.Left, Apar.BoundsRect.Top);
  16.     Apar := Apar.Parent;
  17.     if Apar = Nil Then Exit; //Obviously the control isn't parented
  18.    end;
  19.   {--_End of added--}
  20.   OffsetRect(xRect, -HorzScrollBar.Position, -VertScrollBar.Position);
  21.   if xRect.Left < 0 then
  22.     HorzScrollBar.Position := HorzScrollBar.Position + xRect.Left
  23.   else if xRect.Right > ClientWidth then
  24.   begin
  25.     if xRect.Right - xRect.Left > ClientWidth then
  26.       xRect.Right := xRect.Left + ClientWidth;
  27.     HorzScrollBar.Position := HorzScrollBar.Position + xRect.Right - ClientWidth;
  28.   end;
  29.   if xRect.Top < 0 then
  30.     VertScrollBar.Position := VertScrollBar.Position + xRect.Top
  31.   else if xRect.Bottom > ClientHeight then
  32.   begin
  33.     if xRect.Bottom - xRect.Top > ClientHeight then
  34.       xRect.Bottom := xRect.Top + ClientHeight;
  35.     VertScrollBar.Position := VertScrollBar.Position + xRect.Bottom - ClientHeight;
  36.   end;
  37.  end;
  38. end;
  39. procedure TForm1.Button2Click(Sender: TObject);
  40. begin
  41.   scroll_it_Inview(ScrollBox1, Button1);
  42. end;
  43.  
  44.  
The only true wisdom is knowing you know nothing

zoltanleo

  • Sr. Member
  • ****
  • Posts: 488
Re: Scrolling ScrollBox to "invisible" child control
« Reply #4 on: May 01, 2021, 02:06:41 am »
Ok, Please drop this in your source code and use this instead of the provided ScrollInView..

Tell us if that works any better ..
Oh yeah. This code works almost perfectly.

Would you like to makethe patch this code for the basic lazarus code?  :-X
Win10 LTSC x64/Deb 11 amd64(gtk2/qt5)/Darwin Cocoa (Monterey):
Lazarus x32/x64 2.3(trunk); FPC 3.3.1 (trunk), FireBird 3.0.10; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Scrolling ScrollBox to "invisible" child control
« Reply #5 on: May 01, 2021, 02:18:50 am »
LOL,

 I was hoping someone else would look at the code and maybe improve on it a bit.

 That was just a quick test.

 I suppose I could report the problem and point to here for a reference.

The only true wisdom is knowing you know nothing

zoltanleo

  • Sr. Member
  • ****
  • Posts: 488
Re: Scrolling ScrollBox to "invisible" child control
« Reply #6 on: May 01, 2021, 02:21:46 am »
I suppose I could report the problem and point to here for a reference.
OK. I agree. It would be a good idea
Win10 LTSC x64/Deb 11 amd64(gtk2/qt5)/Darwin Cocoa (Monterey):
Lazarus x32/x64 2.3(trunk); FPC 3.3.1 (trunk), FireBird 3.0.10; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Scrolling ScrollBox to "invisible" child control
« Reply #7 on: May 01, 2021, 03:12:18 am »
ok, I left something there for the DEVS to read

issue :
0038838: ScrollInView for TscrollingWinControl or scrollbox does not calculate stacked controls
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Scrolling ScrollBox to "invisible" child control
« Reply #8 on: May 01, 2021, 08:21:57 pm »
It was applied to the trunk.

so if you run the trunk you should be ok.

maybe it will be merged to the next release.

The DEV's on are on the ball this weekend  :D
The only true wisdom is knowing you know nothing

zoltanleo

  • Sr. Member
  • ****
  • Posts: 488
Re: Scrolling ScrollBox to "invisible" child control
« Reply #9 on: May 01, 2021, 08:25:27 pm »
Good news. Good job. Thank a lot!
Win10 LTSC x64/Deb 11 amd64(gtk2/qt5)/Darwin Cocoa (Monterey):
Lazarus x32/x64 2.3(trunk); FPC 3.3.1 (trunk), FireBird 3.0.10; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

zoltanleo

  • Sr. Member
  • ****
  • Posts: 488
Re: Scrolling ScrollBox to "invisible" child control
« Reply #10 on: May 02, 2021, 09:48:50 pm »
Hi jamie.

I tried applying the patch on a more complex project. I'm sorry, but the code doesn't work correctly. See attachment
Win10 LTSC x64/Deb 11 amd64(gtk2/qt5)/Darwin Cocoa (Monterey):
Lazarus x32/x64 2.3(trunk); FPC 3.3.1 (trunk), FireBird 3.0.10; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

Michl

  • Full Member
  • ***
  • Posts: 226
Re: Scrolling ScrollBox to "invisible" child control
« Reply #11 on: May 02, 2021, 10:28:16 pm »
Thank you for the project!

Fixed in Lazarus Trunk, revision 65083.

At least the two projects here and a other testing project are working for me. Please test.
« Last Edit: May 02, 2021, 10:30:44 pm by Michl »
Code: [Select]
type
  TLiveSelection = (lsMoney, lsChilds, lsTime);
  TLive = Array[0..1] of TLiveSelection;

zoltanleo

  • Sr. Member
  • ****
  • Posts: 488
Re: Scrolling ScrollBox to "invisible" child control
« Reply #12 on: May 02, 2021, 11:32:43 pm »
Please test.

Perfectly. It works flawlessly now! Thank a lot!
Win10 LTSC x64/Deb 11 amd64(gtk2/qt5)/Darwin Cocoa (Monterey):
Lazarus x32/x64 2.3(trunk); FPC 3.3.1 (trunk), FireBird 3.0.10; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Scrolling ScrollBox to "invisible" child control
« Reply #13 on: May 03, 2021, 12:27:42 am »
Thank you for the project!

Fixed in Lazarus Trunk, revision 65083.

At least the two projects here and a other testing project are working for me. Please test.

with no scrollbars enabled or visible the controls now permanently slide up the screen..

That should not happen...

Just drop some controls on a form with no scroll bar and hide the controls a little and force them in view. you keep doing it and it moves the control permanently, you can see this when you enlarge the form on the screen.

 These controls should not move at all using that function if no scroll bars are visible in the direction of choice.



The only true wisdom is knowing you know nothing

Michl

  • Full Member
  • ***
  • Posts: 226
Re: Scrolling ScrollBox to "invisible" child control
« Reply #14 on: May 03, 2021, 08:04:14 am »
Can you please add a minimal example and describe, what was working before revision 65078 and isn't working after revision 65083?

If I do something like this:
Code: Pascal  [Select][+][-]
  1. type
  2.   TForm1 = class(TForm)
  3.     Edit1: TEdit;
  4.     procedure FormResize(Sender: TObject);
  5.   end;
  6. ...
  7. procedure TForm1.FormResize(Sender: TObject);
  8. begin
  9.   ScrollInView(Edit1);
  10. end;
, it is working fine here. So maybe I miss the point.

Also it is a decision of a programmer to enable/disable it, like:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormResize(Sender: TObject);
  2. begin
  3.   if HorzScrollBar.IsScrollBarVisible or VertScrollBar.IsScrollBarVisible then
  4.     ScrollInView(Edit1);
  5. end;  

Simple test added.
Code: [Select]
type
  TLiveSelection = (lsMoney, lsChilds, lsTime);
  TLive = Array[0..1] of TLiveSelection;

 

TinyPortal © 2005-2018