Recent

Author Topic: Component with horizontal scroll buttons  (Read 2103 times)

n7800

  • Full Member
  • ***
  • Posts: 175
Re: Component with horizontal scroll buttons
« Reply #15 on: October 19, 2024, 04:37:17 pm »
I haven't looked at the code yet, but does it support line wrapping? IDECoolBar wraps icons to a new line when "IDE Options > Environment > Window > Show complete component palette" is checked (by default): screenshot.

The idea of this component is to scroll rather than wrap, to avoid reducing the working space available.

I was responding to the idea of ​​using this component as a CoolBar in the IDE. Otherwise, we would have to use different components for it, depending on whether the wrap option is on or off.

wp

  • Hero Member
  • *****
  • Posts: 12459
Re: Component with horizontal scroll buttons
« Reply #16 on: October 19, 2024, 05:39:06 pm »
does it support line wrapping?
In order to wrap the buttons inside the PageScroller you just client-align the toolbar within the PageScroller. Since now the toolbar fits exactly into the PageScroller, the scroll buttons will be hidden. And when the PageScroller is auto-sized it will also adjust its height accordingly. On the other hand, if you want the scrolling capabilities of the PageScroller set the Align of the toolbar to alNone - the toolbar will "unwrap" to a single row which eventually will exceed the width of the PageScroller and make the scroll button reappear.

Look at the attached demo project.
« Last Edit: October 19, 2024, 07:27:18 pm by wp »

rvk

  • Hero Member
  • *****
  • Posts: 6584
Re: Component with horizontal scroll buttons
« Reply #17 on: October 19, 2024, 05:57:56 pm »
Very small example.
The only problem was that TScrollBox really needs the horizontal scrollbar to keep track of the subwindow.
I fixed this by just setting it to invisible in TScrollBox.Paint.
(I think this should work cross-platform)
The scrollpanels gets hidden automatically when not needed.

Code below could of course be turned into one component.

Code: Pascal  [Select][+][-]
  1. // on form a TPanel with
  2. // left aligned TPanel (2) and right aligned TPanel (2) for 'buttons'
  3. // + TScrollBox client aligned
  4. // below the events
  5.  
  6. uses LCLIntf;
  7.  
  8. procedure TForm1.Panel2Click(Sender: TObject);
  9. var
  10.   i: Integer;
  11. begin
  12.   for i := 1 to 100 do // this is for smooth scrolling
  13.   begin
  14.     ScrollBox1.HorzScrollBar.Position := ScrollBox1.HorzScrollBar.Position - 1;
  15.     ScrollBox1.Repaint;
  16.   end;
  17. end;
  18.  
  19. procedure TForm1.Panel3Click(Sender: TObject);
  20. var
  21.   i: Integer;
  22. begin
  23.   for i := 1 to 100 do
  24.   begin
  25.     ScrollBox1.HorzScrollBar.Position := ScrollBox1.HorzScrollBar.Position + 1;
  26.     ScrollBox1.Repaint;
  27.   end;
  28. end;
  29.  
  30. type
  31.   THackMyScrollBar = class(TControlScrollBar);
  32.  
  33. procedure TForm1.ScrollBox1Paint(Sender: TObject);
  34. begin
  35.   // hide, bot not disable the scrollbar
  36.   ShowScrollBar(THackMyScrollBar(ScrollBox1.HorzScrollBar).FControl.Handle, 0, false);
  37.  
  38.   // turn button/panels off when not needed
  39.   Panel2.Visible := ScrollBox1.HorzScrollBar.Position > 0;
  40.   Panel3.Visible := (ScrollBox1.Width + ScrollBox1.HorzScrollBar.Position) < ScrollBox1.HorzScrollBar.Range;
  41.  
  42. end;

« Last Edit: October 19, 2024, 06:10:31 pm by rvk »

wp

  • Hero Member
  • *****
  • Posts: 12459
Re: Component with horizontal scroll buttons
« Reply #18 on: October 20, 2024, 12:41:55 am »
Maybe it would work equally well with a Panel + SpeedButtons, replacing the PageControl + SpeedButtons used by the Component palette now.
It does. See the attached demo. The LazPageScroller here contains some new features compared with my previous post:
  • Property Orientation to rotate the scroller from horizontal to vertical direction and vice versa. Note that the scroller does not "know" anything about the embedded control. Therefore, there must be a handler for the OnChangeOrientation event which rotates the embedded control in the same way. This can be done quite easily with a panel and speedbuttons (by means of the ChildSizing mechanism), but so far I did not find an easy way to rotate a ToolBar having Align = alNone (which is required for the LazPageScroller to work).
  • Mousewheel support: Rotate the mousewheel over the panel/speedbuttons (or toolbar/toolbuttons) to quickly scroll the buttons. Effect can be turned off, or reversed.
Actually the Delphi's component also has a property "Control". Does it use the same design idea? I don't have Delphi myself now to test it.
Yes, of course. Any TControl can be inserted into the LazPageScroller.

A Delphi compatible TPageScroller would be nice of course.
Regarding properties we're pretty close now, some events missing. Regarding public methods, there's also a missing function GetButtonState(Button: TPageScrollerButton): TPageScrollerButtonState which can be added easily. But in the protected part there are lots of differences which I do not intend to handle. So, when it's finished I guess it will be rather Delphi-compliant for application writers, but not for component writers.

Isn't this doable with TScrollBox?

Something like a TPanel, with a narrow vertical button at the left and right aligned and a TSCrollBox in the middle (Client-aligned).
Yes, you showed that this is possible. But I think a panel is more light-weight than a TScrollBox for the simple task of moving the inserted control. I just need a few lines for this purpose (method Scroll) which the ScrollBox already has, but the ScrollBox also carries all the scrollbar stuff which is not needed.

Soner

  • Sr. Member
  • ****
  • Posts: 311
Re: Component with horizontal scroll buttons
« Reply #19 on: October 22, 2024, 12:08:35 am »
@wp
Your control is good. I would name it TPageScroller and put it as default lazarus control to commmon controls.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4541
  • I like bugs.
Re: Component with horizontal scroll buttons
« Reply #20 on: October 22, 2024, 01:46:07 am »
Sorry for the delay.
I agree with Soner. The component looks good.
Correction to my earlier comment: This would not replace PageControl in Lazarus IDE Component Palette, but would be inside each page of the PageControl.
Let's see if I have time next weekend to experiment more with this.

I was responding to the idea of ​​using this component as a CoolBar in the IDE. Otherwise, we would have to use different components for it, depending on whether the wrap option is on or off.
No, the idea was not to replace the CoolBar but to improve the Component Palette. The CoolBar has a bug of its own. It adjusts its height like it wanted to wrap its buttons but it doesn't.

Please see the 2 bug reports I linked in the first post. In my opinion the option 'Automatically adjust IDE main window height' is quite useless. The height should always be adjusted when either the CoolBar or the Component Palette wrap their view and change their height.
But, maybe some people have different preferences and resize the main window manually. Thus the options can stay there.
Both the CoolBar and the Component Palette must have an option to not wrap and thus not change their height.

When 'Show complete component palette' is off, the small vertical ScrollBar provided by the PageControl is unusable at least in my system. A TPageScroller would improve that.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

n7800

  • Full Member
  • ***
  • Posts: 175
Re: Component with horizontal scroll buttons
« Reply #21 on: October 22, 2024, 02:36:44 am »
I was responding to the idea of ​​using this component as a CoolBar in the IDE. Otherwise, we would have to use different components for it, depending on whether the wrap option is on or off.
No, the idea was not to replace the CoolBar but to improve the Component Palette. The CoolBar has a bug of its own. It adjusts its height like it wanted to wrap its buttons but it doesn't.

Sorry, of course I meant the palette... In my first message I even gave a link to a screenshot, and thought that I was understood ))

 

TinyPortal © 2005-2018