Recent

Author Topic: TPairSplitter: Detecting move of middle separator  (Read 881 times)

Milsa

  • Full Member
  • ***
  • Posts: 232
TPairSplitter: Detecting move of middle separator
« on: October 04, 2020, 04:30:26 pm »
How can I detect change property "Position" by user event?
I work with Lazarus 2.0.10, FPC 3.2.0, SVN 63526
This information is actual to: 1st Aug 2020

Blaazen

  • Hero Member
  • *****
  • Posts: 2994
  • POKE 54296,15
    • Eye-Candy Controls
Re: TPairSplitter: Detecting move of middle separator
« Reply #1 on: October 04, 2020, 04:41:50 pm »
Event PairSplitterSide1.Resize; (or ...Side2)
Lazarus 2.1.0 r64115 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Milsa

  • Full Member
  • ***
  • Posts: 232
Re: TPairSplitter: Detecting move of middle separator
« Reply #2 on: October 04, 2020, 05:11:45 pm »
Thank you. I looked at main TPairSplitter. It is all problem.
I work with Lazarus 2.0.10, FPC 3.2.0, SVN 63526
This information is actual to: 1st Aug 2020

Handoko

  • Hero Member
  • *****
  • Posts: 3913
  • My goal: build my own game engine using Lazarus
Re: TPairSplitter: Detecting move of middle separator
« Reply #3 on: October 04, 2020, 05:21:17 pm »
I just tested it and understand what you meant. I think you should submit a feature request: TPairSplitter.OnPositionChanged event.

wp

  • Hero Member
  • *****
  • Posts: 7752
Re: TPairSplitter: Detecting move of middle separator
« Reply #4 on: October 04, 2020, 06:54:03 pm »
I don't understand what's wrong with Blaazen's answer, except for the typo that the even is called OnResize (not Resize).
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Handoko

  • Hero Member
  • *****
  • Posts: 3913
  • My goal: build my own game engine using Lazarus
Re: TPairSplitter: Detecting move of middle separator
« Reply #5 on: October 04, 2020, 06:59:18 pm »
The OnResize will be triggered even a single pixel movement. I believe OnAfterResized is more suitable to what OP wants.

For example try to this:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.PairSplitterSide1Resize(Sender: TObject);
  2. begin
  3.   ShowMessage('test');
  4. end;

Then you will know it is unusable.

wp

  • Hero Member
  • *****
  • Posts: 7752
Re: TPairSplitter: Detecting move of middle separator
« Reply #6 on: October 04, 2020, 08:01:40 pm »
The OP needs an event to detect a change in the Position property of the PairSplitter. I still don't see why the PairSplitterSide's OnResize is not usable for this purpose. Look at attached demo.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Handoko

  • Hero Member
  • *****
  • Posts: 3913
  • My goal: build my own game engine using Lazarus
Re: TPairSplitter: Detecting move of middle separator
« Reply #7 on: October 04, 2020, 08:10:28 pm »
If I want to use ShowMessage not Memo1:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.PairSplitterSide1Resize(Sender: TObject);
  2. begin
  3. //  Memo1.Lines.Add('Side 1: PairSplitter.Position = ' + IntToStr(PairSplitter1.Position));
  4.   ShowMessage(PairSplitter1.Position.ToString);
  5. end;

How to make the event only triggered when the mouse click released (mouse up) ?

For comparison try my code, which use TSplitter:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Dialogs, ExtCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Panel1: TPanel;
  16.     Splitter1: TSplitter;
  17.     procedure Splitter1Moved(Sender: TObject);
  18.   end;
  19.  
  20. var
  21.   Form1: TForm1;
  22.  
  23. implementation
  24.  
  25. {$R *.lfm}
  26.  
  27. { TForm1 }
  28.  
  29. procedure TForm1.Splitter1Moved(Sender: TObject);
  30. begin
  31.   ShowMessage(Panel1.Width.ToString);
  32. end;
  33.  
  34. end.

If you wonder why I insist not triggered on every single pixel movement. Here the example cases:

If user change the setting, I want to save it to disk. If you use Firefox you will know there is no "Apply" nor "OK" nor "Save" button on user preference form. Many modern programs behave so.

Or if user slide the handle, I need to do screen refresh that require some heavy calculations.
« Last Edit: October 04, 2020, 08:31:06 pm by Handoko »

wp

  • Hero Member
  • *****
  • Posts: 7752
Re: TPairSplitter: Detecting move of middle separator
« Reply #8 on: October 05, 2020, 12:30:06 am »
You will have same issues with every OnResize event of any other control supporting it (TForm, TPanel, TGroupBox, TStringGrid etc).

One possibility to avoid seeng the event multiple times during the dragging action of the splitter is to add a timer: the timer must be disabled initially and be set to some acceptable interval (some 100 ms). On the OnResize event of the PairSplitter or the other controls mentioned you enable the timer. In the OnTimer event of the timer you disable the timer again and execute the code that you would like to be executed in the OnResize event. Now when you drag the splitter the OnResize events are fired in short intervals, shorter than the timer's interval, constantly resetting the timer. Only when the resizing operation stops (or when you stop moving the mouse but still keep the button down  -- that's a disadvantage...) the OnTimer event occurs.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

jamie

  • Hero Member
  • *****
  • Posts: 3797
Re: TPairSplitter: Detecting move of middle separator
« Reply #9 on: October 05, 2020, 03:20:47 am »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Splitter2ChangeBounds(Sender: TObject);
  2. begin
  3.    If Splitter2.MouseEntered then Beep;
  4. end;
  5.  
  6. procedure TForm1.Splitter2Moved(Sender: TObject);
  7. begin
  8.   if Splitter2.MouseEntered Then Beep;
  9. end;                                        
  10.  
  11.  

take your pick..

Bounds Change calls always as you are dragging it.

Moved only calls when done but the mouse enter will register on both..

This control uses the TWinControl so it has more functionality than this..

I suppose an event can be added  "OnUserMove(Sender:Tobject; aFlag=(Moving, Released)); etc..
The only true wisdom is knowing you know nothing

Milsa

  • Full Member
  • ***
  • Posts: 232
Re: TPairSplitter: Detecting move of middle separator
« Reply #10 on: October 06, 2020, 05:43:47 pm »
I just tested it and understand what you meant. I think you should submit a feature request: TPairSplitter.OnPositionChanged event.
Yes, it is problem. I have collision with main PairSplitter.OnResize.

I have application with TPairSplitter. (TPS). If I change window size, I want change TPS by window size. I change Position too by percent of TPS height. Percent of Position of height I change in TPS-Side1.OnResize. But percent of height is changed when I change the main application window size (MAWS).

How can I will create this code?
- change MAWS changes all TPS proportional with Position
I work with Lazarus 2.0.10, FPC 3.2.0, SVN 63526
This information is actual to: 1st Aug 2020

Milsa

  • Full Member
  • ***
  • Posts: 232
Re: TPairSplitter: Detecting move of middle separator
« Reply #11 on: October 06, 2020, 05:46:34 pm »
I will prepare a test application.
I work with Lazarus 2.0.10, FPC 3.2.0, SVN 63526
This information is actual to: 1st Aug 2020

wp

  • Hero Member
  • *****
  • Posts: 7752
Re: TPairSplitter: Detecting move of middle separator
« Reply #12 on: October 06, 2020, 06:40:28 pm »
I change Position too by percent of TPS height. Percent of Position of height I change in TPS-Side1.OnResize. But percent of height is changed when I change the main application window size (MAWS).

How can I will create this code?
- change MAWS changes all TPS proportional with Position
I think (not tested...) this is possible by simulating some kind of OnMoved event for the PairSplitter based on its OnMouseDown/Move/Up events, and leave the sides' OnResize alone. The splitter's OnResize, then, should reposition the splitter according to its relative position within the form. I guess it's not difficult but will require some code...

Alternatively you could use a standard TSplitter with two panels above and below the splitter. Set the splitter's Align to alNone so that it is floating. Use the anchor editor to attach the upper panel to the top, left and right sides of the form; its bottom side should be attached to the top side of the splitter. The lower panel should be attached to the left, bottom and right sides of the form, and the upper edge should be attached to the lower side of the splitter. The splitter should be anchored to the left and right sides of the form, but -- and this is important -- it must be  floating vertically, i.e. the anchor editor must not show checks for "top anchoring" and "bottom anchoring". In this configuration, the splitter will move when the size of the form changes, and its speed of movement depends on the relative position of the splitter inside the form.

Have a look at the attached sample.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Milsa

  • Full Member
  • ***
  • Posts: 232
Re: TPairSplitter: Detecting move of middle separator
« Reply #13 on: October 06, 2020, 07:13:33 pm »
Testing app in attachment.

My idea:
- resize main window => proportional change TPSs sizes and Positions
- change Position => no change (but change top of second StringGrid) but ratio calculation for main window resize
I work with Lazarus 2.0.10, FPC 3.2.0, SVN 63526
This information is actual to: 1st Aug 2020

wp

  • Hero Member
  • *****
  • Posts: 7752
Re: TPairSplitter: Detecting move of middle separator
« Reply #14 on: October 06, 2020, 07:39:09 pm »
I attempt to bend my brain in order to fix your solution because it took me only a few minutes to set up a solution with TSplitter and anchoring.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

 

TinyPortal © 2005-2018