Lazarus

Programming => LCL => Topic started by: knuckles on March 27, 2017, 10:31:53 pm

Title: [SOLVED] TScrollBox Horizontal Scrollbar Bug?
Post by: knuckles on March 27, 2017, 10:31:53 pm
I have been in the process of making a custom control and noticed something strange which I could not fix and it relates to the horizontal scrollbar range of the TScrollBox and TScrollingWinControl (which I derive my control from).

I can recreate the problem with a simple new project so maybe someone can try this to see if they experience it too and whether or not it is in fact a bug:

Quote
- Create a new project

- Set the form height and width to something like 500.

- Drop a Scrollbox on the form and align to client.

- Drop a control into the scrollbox say a panel or a memo and make the control say 250 in width and height.

Now here is where things get interesting.

Quote
- Set the top value of the control you added to the scrollbox as say 50.

- Run the project and resize the form window from the right to left (make the window smaller) until the horizontal scrollbar appears, now slowly resize the window from left to right (make the window bigger) and notice the scrollbar still visible when it should not be.

- Stop the project and change the top value of the control you added to the scrollbox to 0 and repeat the above, the scrollbar range seems normal.

Im using Lazarus 1.6.4 Win64, FPC 3.0.2 and tested on Windows 10 x64

Ive added some images to help show the problem, can anyone else recreate this and is it a bug?

Thanks
Title: Re: TScrollBox Horizontal Scrollbar Bug?
Post by: howardpc on March 27, 2017, 10:58:51 pm
A TScrollBox will never work properly if you set its Align to alClient.
If you resize its containing form, you set up conflicting changes affecting the size of the scrollbox itself, and the positioning of its contained controls.
The idea of a scrollbox is that it knows how big it is, and if its contained controls are resized relative to that known size, it can provide internal scrollbars for the user to reposition the resized control.
But if the scrollbox does not know how big it is... how can it determine if scrollbars are needed or not?
Title: Re: TScrollBox Horizontal Scrollbar Bug?
Post by: knuckles on March 27, 2017, 11:11:07 pm
Well I have tested on the latest version of CodeTyphon and Delphi XE7 and they work as expected, but Lazarus is giving incorrect range for some reason.
Title: Re: TScrollBox Horizontal Scrollbar Bug?
Post by: wp on March 27, 2017, 11:32:28 pm
Attached project is working correctly with both Laz trunk and Laz 1.6.4 (Win 10). knuckles, you should upload a demo project.

@howardpc: I don't think that this is correct, I've used client-aligned scrollboxes many times. The one thing which must not be done is to client-align the scrollbox content, e.g. the panel within the scrollbox.
Title: Re: TScrollBox Horizontal Scrollbar Bug?
Post by: knuckles on March 27, 2017, 11:47:02 pm
Attached project is working correctly with both Laz trunk and Laz 1.6.4 (Win 10). knuckles, you should upload a demo project.

@howardpc: I don't think that this is correct, I've used client-aligned scrollboxes many times. The one thing which must not be done is to client-align the scrollbox content, e.g. the panel within the scrollbox.

Yes this is true, aligning the scrollbox is perfectly normal, just dont align child controls to the scrollbox client.

Ok I downloaded your project, only changed the memo to left := 0 and the problem still shows for me, I then changed the memo top=0 and the scrollbar works as expected.

Maybe try these changes again and let me know what happens.

Thanks
Title: Re: TScrollBox Horizontal Scrollbar Bug?
Post by: howardpc on March 28, 2017, 12:03:22 am
@wp You're right as usual! Thanks for the correction.
Title: Re: TScrollBox Horizontal Scrollbar Bug?
Post by: wp on March 28, 2017, 12:13:01 am
The demo with Laz trunk is fine: In the second phase of the test when the window width increases, the scrollbar disappears when the right edge of the memo becomes visible.

Laz 1.6.4 behaves a little bit differently. Now the horizontal scrollbar is still visible after the right edge of the memo appears. But it disappears when the form width and memo width differ by the width of the (invisible) vertical scrollbar.

If you decrese the height of the window such that the vertical scrollbar is visible and repeat the experiment the horizontal scrollbar behaves correctly.

Therefore, I'd say that Laz 1.6.4 does not correctly consider the width of the vertical scrollbar. Evidently, this has been fixed in the meantime.
Title: Re: TScrollBox Horizontal Scrollbar Bug?
Post by: knuckles on March 28, 2017, 12:20:53 am
@wp Glad you can see it and yeah I actually thought it was somehow using the invisible vertical scrollbar in some way, very strange behavior. It would be interesting to see if there are any patch notes or something to see what changed or what fixed it out of curiosity.

Anyway I will now download and test with a Lazarus trunk version too.

Thanks
Title: Re: TScrollBox Horizontal Scrollbar Bug?
Post by: knuckles on March 28, 2017, 12:40:16 am
The bug also seems present in 1.6.2, never downloaded from the trunk before so will try and work out how to do that now...
Title: Re: TScrollBox Horizontal Scrollbar Bug?
Post by: wp on March 28, 2017, 12:40:35 am
I checked other Lazarus versions, even 1.4.4 has it (I did not go back any further).

I scanned the svn commit notes, and found this one: r51640 "lcl: fix wrong scrollbar height calculation". It adds a method TControlScrollbar.ControlSize (in forms.pp):

Code: Pascal  [Select][+][-]
  1. function TControlScrollBar.ControlSize: integer;
  2. begin
  3.   if Kind = sbVertical then
  4.     Result := FControl.Width
  5.   else
  6.     Result := FControl.Height;
  7. end;

And this is called in
Code: Pascal  [Select][+][-]
  1. function TControlScrollBar.ClientSizeWithoutBar: integer;
  2. begin
  3.   Result:=ClientSize;
  4.   if IsScrollBarVisible then
  5.     Result := Min(ControlSize, Result+GetSize+GetSystemMetrics(SM_SWSCROLLBARSPACING));
  6. end;

If you apply these modification to 1.6.4 there's a good chance that it will fix the issue (I did not do it myself).
Title: Re: TScrollBox Horizontal Scrollbar Bug?
Post by: knuckles on March 28, 2017, 12:43:12 am
Good spotting @wp, I will try and patch 1.6.4 first rather than download from svn trunk...
Title: Re: TScrollBox Horizontal Scrollbar Bug?
Post by: knuckles on March 28, 2017, 05:53:08 pm
Dam I spent too much time trying to install trunk from svn (not easy for beginners like me who never use svn etc).

Anyway I got Lazarus 1.7 and FPC 3.1.1 working by installing from https://www.getlazarus.org/setup/ but this also does not include the fix, so to patch it you need to edit controlscrollbar.inc and change function TControlScrollBar.ClientSizeWithoutBar like so:

Quote
function TControlScrollBar.ClientSizeWithoutBar: integer;
var
   ControlSize: Integer;
begin
   if Kind = sbVertical then
    ControlSize := FControl.Width
  else
    ControlSize := FControl.Height;

  Result:=ClientSize;
  if IsScrollBarVisible then
    Result := Min(ControlSize, Result+GetSize+GetSystemMetrics(SM_SWSCROLLBARSPACING));
end;

Done a few quick tests and this seems to be working ok.

Many thanks @wp  :)
Title: Re: TScrollBox Horizontal Scrollbar Bug?
Post by: wp on March 28, 2017, 08:02:26 pm
Dam I spent too much time trying to install trunk from svn (not easy for beginners like me who never use svn etc).
I think you are on Windows:
Title: Re: [SOLVED] TScrollBox Horizontal Scrollbar Bug?
Post by: knuckles on March 28, 2017, 11:32:23 pm
Great thanks wp,

I was trying to follow the wiki help pages and got as far as able to download the lazarus and fpc sources through the svn but couldnt figure out how to build anything and generate the exe's, this might prove helpful in future if I want to try again.
Title: Re: [SOLVED] TScrollBox Horizontal Scrollbar Bug?
Post by: shuklasa on April 04, 2017, 01:59:07 pm
Thank you very much. I applied this patch to 1.6 and Issues was solved.
TinyPortal © 2005-2018