Recent

Author Topic: Weird TSplitter behavior  (Read 607 times)

MISV

  • Hero Member
  • *****
  • Posts: 700
Weird TSplitter behavior
« on: August 07, 2019, 01:03:15 am »
I added ondblclick event handler...

in that I have tried all sorts of ways to change .Left or Width of the two panels on each side.

I want the doubleclick to act as a "snap" so left side takes whole screen (and back if doubleclicked agagin)

When I doubleclick I can see it works... until... I release the mousebutton on the 2nd click in the doubleclick ... Then it all snaps back o the original placement.

My guess is that there some place inside code is some kind of management handling drags/moves which sets the position of the splitter afterwads a drag/move (and doubleclick it seems)

... Any solutions for this? Is there something like PostMessage I could use wherefrom I could set widh *after* the mouse button has been released.

I have been sitting trail and erroring this for many hours, so I figured I should hear you if you had any ideas I could try...

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2515
    • havefunsoft.com
Re: Weird TSplitter behavior
« Reply #1 on: August 07, 2019, 01:17:42 am »
sample app?
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

MISV

  • Hero Member
  • *****
  • Posts: 700
Re: Weird TSplitter behavior
« Reply #2 on: August 07, 2019, 03:04:43 am »
Will make unless I find solution. Will post solution here if I find it. (Was hoping someone might have an idea I could try before I try split the UI furher to create a sample app.)

lucamar

  • Hero Member
  • *****
  • Posts: 3027
Re: Weird TSplitter behavior
« Reply #3 on: August 07, 2019, 03:56:33 am »
Maybe add a handler for OnCanOffset? You can use OnMouseDown/Up to set a flag to know whether you're in a doubleclick and make the OnCanOffset check it and act accordingly.

Note that (at least in Linux) mouse clicks also generate OnMove events.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

MISV

  • Hero Member
  • *****
  • Posts: 700
Re: Weird TSplitter behavior
« Reply #4 on: August 08, 2019, 10:32:13 pm »
I am still working on this...

I know tried using Application.QueueAsyncCall

and then all kinds of "hacks" I can think of like disabling all event handlers while resizing using the above...

but yet... it bounces back.... So I am out of ideas almost...

It seems it sometimes when when in debug/stepping through code, but otherwise it fails completely




skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2515
    • havefunsoft.com
Re: Weird TSplitter behavior
« Reply #5 on: August 08, 2019, 10:41:42 pm »
The first question to ask - is it LCL behavior or is it LCLCocoa behavior.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

MISV

  • Hero Member
  • *****
  • Posts: 700
Re: Weird TSplitter behavior
« Reply #6 on: August 08, 2019, 11:07:44 pm »
This seems to do the trick...

WC is the splitter

I am bit tired now so have not cut the code down the bare minimum. But here is something people can use as starting point if they suffer of the same problem:

What helped was inserting sleep before the call to the async... I think the reason is that ensures I physically actually release the mouse button (and the firing of associated messages) *before* my async code runs

Code: Pascal  [Select][+][-]
  1.   P := WC.Parent;
  2.   //--
  3.   // Lazarus/LCL required quite a bit extra code to get this working
  4.   // 1) We have disabled all event handlers to avoid more event-handler-code "firing" which --maybe helps--
  5.   // 2) *Sleep* ensures we finish the physical doubleclick including release.
  6.   // 3) *ProcessMessages* --maybe helps-- ensure related messages are handled
  7.   // 4) *Application.QueueASyncCall* queues the rest of the code to back of messages queue
  8.   // 5) *OwnHelper_Lazarus_Async_splWebsiteDblClick* also calls *ProcessMessages* as first thing which --maybe helps--  
  9.   //--
  10.   if WC.Left < (P.ClientWidth - WC.Width - 40) then
  11.     begin
  12.       {$IFDEF mymsDELPHI}
  13.       W := (P.ClientWidth - WC.Width);
  14.       pnlWebsiteStructuresMain.Width := W;
  15.       {$ENDIF}
  16.       {$IFDEF mymsFPCDevTool}
  17.       Sleep(1000);
  18.       Application.ProcessMessages;
  19.       Application.QueueASyncCall(@OwnHelper_Lazarus_Async_splWebsiteDblClick, 1);
  20.       {$ENDIF}
  21.     end
  22.   else
  23.     begin
  24.       {$IFDEF mymsDELPHI}
  25.       W := Max(400, (P.ClientWidth div 4));
  26.       pnlWebsiteStructuresMain.Width := W;
  27.       {$ENDIF}
  28.       {$IFDEF mymsFPCDevTool}
  29.       Sleep(1000);
  30.       Application.ProcessMessages;
  31.       Application.QueueASyncCall(@OwnHelper_Lazarus_Async_splWebsiteDblClick, 0);
  32.       {$ENDIF}
  33.     end;
  34.   ;
  35.  

 

TinyPortal © 2005-2018