Recent

Author Topic: Learn how to (un)dock a TPanel  (Read 2313 times)

Hansvb

  • Hero Member
  • *****
  • Posts: 757
Learn how to (un)dock a TPanel
« on: February 10, 2025, 07:10:38 pm »
Hi,
I would like to be able to drag out a Tpanel that is on the main form so that it becomes its own form. And you have to be able to drag this form back and dock it in the main form. What is a good starting point to learn this? I'm not a fan of the Acnhordocking as it is now seen in lazarus, but if that's the best option, than I'm looking for a simple example to start with it and build on that.

I also found this:
Quote
https://forum.lazarus.freepascal.org/index.php?topic=25800.0
This seems to work partly but I have no idea why this works.
« Last Edit: February 10, 2025, 08:20:44 pm by Hansvb »

MarkMLl

  • Hero Member
  • *****
  • Posts: 8334
Re: Learn how to (un)dock a TPanel
« Reply #1 on: February 11, 2025, 10:07:55 am »
Just to try to keep this live since nobody else has commented.

I did this using Delphi years ago, but in the context of moving a panel (containing a text editor etc.) between a program's main form and a design-time-created (but hidden) form. In my case control was by a button or menu entry rather than using drag and drop

Code: Pascal  [Select][+][-]
  1. procedure TMimicForm.OwnWindow1Click(Sender: TObject);
  2.  
  3. begin
  4.   OwnWindow1.Checked:= NOT OwnWindow1.Checked;
  5.   IF OwnWindow1.Checked THEN BEGIN
  6.  
  7. (* We don't want to revert to running an animated panel while an editor *)
  8. (* window is open since this could change the selected record.          *)
  9.  
  10.     DesignForm.Visible1.Enabled:= FALSE;
  11.     MimicForm.Panel1.Enabled:= FALSE;
  12.  
  13. (* Move the editor pane to its own window.                              *)
  14.  
  15.     PanelLowerRightTop.Parent:= EditorForm;
  16.     EditorForm.Caption:= ScriptDatabase.AliasName + ' - ' +
  17.                 ScriptQuery.FieldByName('name').AsString +
  18.         ' (id=' + ScriptQuery.FieldByName('id').AsString +
  19.         ', sub=' + ScriptQuery.FieldByName('sub').AsString + ')';
  20.  
  21. (* Since we've got more room we can use a larger fount and fancy        *)
  22. (* furniture.                                                           *)
  23. ...
  24.   END ELSE BEGIN
  25. ...
  26. (* Move the editor pane back to the prepared space.                     *)
  27.  
  28.     PanelLowerRightTop.Parent:= PanelLowerRight;
  29.  
  30. (* Allow the user to reanimate the current panel.                       *)
  31.  
  32.     DesignForm.Visible1.Enabled:= TRUE;
  33.     MimicForm.Panel1.Enabled:= TRUE
  34.   END;
  35.  

Obvious caveat there is that I'm departing from your question (a) by not using DnD and (b) by not using the docking mechanism. However I hope it's still useful to some small extent.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Hansvb

  • Hero Member
  • *****
  • Posts: 757
Re: Learn how to (un)dock a TPanel
« Reply #2 on: February 11, 2025, 05:35:14 pm »
I think I have some starting points now. I'll start in the weekend and then I can add code i hope. That usually helps.

Hansvb

  • Hero Member
  • *****
  • Posts: 757
Re: Learn how to (un)dock a TPanel
« Reply #3 on: February 11, 2025, 07:04:29 pm »
I couldn't resist starting anyway. The start is very simple, put a few ticks right and you can drag a panel out of your form.
See the attachment. A simple beginners working example with 2 ways to drag and drop a panel from another panel (and put it back again). What I don't understand yet is that the panel only drops when you click on the canvas with the mouse and then drag. If you click with the mouse on the title bar and then the panel drops, the panel does not drag. Then you have to click on the canvas again.
If you drag a panel out of your window, it becomes a form. (Whether or not you make it yourself). What I still don't understand is how to get the form (panel) back when you close the form. Then you have lost your panel. Can that be repaired or is it better to prevent the dragged form from closing?

Any thoughts?

MarkMLl

  • Hero Member
  • *****
  • Posts: 8334
Re: Learn how to (un)dock a TPanel
« Reply #4 on: February 11, 2025, 10:27:43 pm »
Glad you're making progress. Bear in mind that some of the behaviour might be widgetset-specific.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Hansvb

  • Hero Member
  • *****
  • Posts: 757
Re: Learn how to (un)dock a TPanel
« Reply #5 on: February 12, 2025, 08:49:42 pm »
The progress is not as good as I thought yesterday. EndDrag is never called. The code in the zip file is wrong.

Hansvb

  • Hero Member
  • *****
  • Posts: 757
Re: Learn how to (un)dock a TPanel
« Reply #6 on: February 12, 2025, 09:41:01 pm »
Just found this. I have some reading to do :)

Quote
https://www.freepascal.org/~michael/articles/#docking

Hansvb

  • Hero Member
  • *****
  • Posts: 757
Re: Learn how to (un)dock a TPanel
« Reply #7 on: February 14, 2025, 04:47:21 pm »
Hi,
I can't get it to work quite right. In the attached example, you can drag panel with the memo out of the form. I can customize the newly formed form. I can also drag the new form back. That all seems to work well. It is strange that all functionality is in Panel2EndDock. I expected to use EndDrag as well, but it never gets triggered.

It goes wrong if I drag the panel out and then close the new form. Then the panel will be placed on the original location but after that you can't drag it anymore. However, if you double-click on the panel once, dragging will work again. So I suspect I'm doing something wrong when closing newly formed form.

How can I close the newly formed form in such a way that the dragging works again?

msintle

  • Sr. Member
  • ****
  • Posts: 299
Re: Learn how to (un)dock a TPanel
« Reply #8 on: February 14, 2025, 06:13:34 pm »
We never got this working for our own product, too.

If anybody has an up-to-date docking tutorial for Lazarus, it'd be much appreciated.

From what I can tell, it doesn't even work on any single given platform yet - save tackling multiple platforms (for now)!

Hansvb

  • Hero Member
  • *****
  • Posts: 757
Re: Learn how to (un)dock a TPanel
« Reply #9 on: February 15, 2025, 11:23:49 am »
Does anyone have an idea?


The examples that accompany the article
Quote
https://www.freepascal.org/~michael/articles/#docking
don't work either. (Do not compile, perhaps too old). What is also striking is that if you drag panel2 after closing the form and drop it immediately, you can then drag the panel completely out of the form again. It seems that I either don't close the newly formed form properly or that the drop operation is not being completed properly.

msintle

  • Sr. Member
  • ****
  • Posts: 299
Re: Learn how to (un)dock a TPanel
« Reply #10 on: February 15, 2025, 02:42:33 pm »
Does anyone have an idea?


The examples that accompany the article
Quote
https://www.freepascal.org/~michael/articles/#docking
don't work either. (Do not compile, perhaps too old). What is also striking is that if you drag panel2 after closing the form and drop it immediately, you can then drag the panel completely out of the form again. It seems that I either don't close the newly formed form properly or that the drop operation is not being completed properly.

No kidding, the articles make it sound so easy, and are so confident (like a hallucinating AI of sorts); but docking...just...doesn't...work, period!

Hansvb

  • Hero Member
  • *****
  • Posts: 757
Re: Learn how to (un)dock a TPanel
« Reply #11 on: February 15, 2025, 08:43:53 pm »
It works as long as you don't accidentally close the screen. I expect there is a way, but I'm missing something.

msintle

  • Sr. Member
  • ****
  • Posts: 299
Re: Learn how to (un)dock a TPanel
« Reply #12 on: February 16, 2025, 02:02:52 pm »
It works as long as you don't accidentally close the screen. I expect there is a way, but I'm missing something.

How do you mean? Can you post a project that works in this manner? Sounds like you may have gotten further ahead than we ever did!

Hansvb

  • Hero Member
  • *****
  • Posts: 757
Re: Learn how to (un)dock a TPanel
« Reply #13 on: February 21, 2025, 07:01:07 pm »
Hi msintle,
It took a while but here is what I have so far. I have given up in the meantime.

You can drag the panel out of the form and back again (works). If you have dragged the panel out of the form and close it, it will also go back neatly. But then you can't drag it out of the form UNLESS you drag the panel a little bit and and drop it immediately. Then it docks well again in some way and you can drag it out of the forum again.

msintle

  • Sr. Member
  • ****
  • Posts: 299
Re: Learn how to (un)dock a TPanel
« Reply #14 on: February 22, 2025, 11:20:08 am »
Thanks very much!

Will check this and let you know what we find.

On that note, what we had a lot of trouble with was preserving the shape of the form during the docking process.

For example, a tall "skyscraper" style docking worked.

But imagine another window, roughly the same dimensions, "fallen to the ground" instead of being vertical.

This horizontal window just would never dock horizontally, it'd always dock vertically; obscuring the entire window contents.

Were you able to preserve vertical/horizontal alignment in your attempts - I notice most your test cases are more or less squares, and not rectangles with either a horizontal or vertical bent.

 

TinyPortal © 2005-2018