How to use ResizerWidget in Dlangui app..?

ShadoLight ettienne.gilbert at gmail.com
Fri Jan 3 11:01:48 UTC 2020


On Thursday, 2 January 2020 at 05:24:33 UTC, Rémy Mouëza wrote:
> On Monday, 30 December 2019 at 23:32:37 UTC, ShadoLight wrote:
>> Hi,
>>
>> I suspect I'm missing something obvious, but ResizerWidget is 
>> not working for me on Windows - it shows the 'dragging'-cursor 
>> when hovering the mouse on the ResizerWidget, but dragging 
>> with the left mouse button does nothing.
>>
>
> I ran into the same issue. The resizeEvent callback is not 
> implemented yet. Below is my custom implementation.
>
>
> /** A completed resizer widget.
>   As of 2016-12-30, the ResizerWidget does not work out of the 
> box.
>   This class implement the missing piece.
>  */
> class Resizer : ResizerWidget {
>
>     /// Default initialization.
>     this () {
>         super ();
>         initResizeCb ();
>     }
>
>     /// Create with ID parameter.
>     this (string ID, Orientation orient = Orientation.Vertical) 
> {
>         super (ID, orient);
>         initResizeCb ();
>     }
>
>     /// Initialize the resize on drag behaviour callback.
>     protected void initResizeCb () {
>         this.resizeEvent
>             = (ResizerWidget source,
>                ResizerEventType event,
>                int currentPosition)
>         {
>             if (event != ResizerEventType.Dragging) {
>                 return;
>             }
>
>             if (_orientation == Orientation.Horizontal) {
>                 auto delta = _previousWidget.width - 
> currentPosition;
>                 auto pw    = max (0, _previousWidget.width - 
> delta);
>                 auto mw    = max (0,     _nextWidget.width + 
> delta);
>
>                 _previousWidget
>                     .minWidth (pw)
>                     .maxWidth (pw);
>
>                 _nextWidget
>                     .minWidth (mw)
>                     .maxWidth (mw);
>             }
>             else if (_orientation == Orientation.Vertical) {
>                 auto delta = _previousWidget.height - 
> currentPosition;
>                 auto pw    = max (0, _previousWidget.height - 
> delta);
>                 auto mw    = max (0,     _nextWidget.height + 
> delta);
>
>                 _previousWidget
>                     .minHeight (pw)
>                     .maxHeight (pw);
>
>                 _nextWidget
>                     .minHeight (mw)
>                     .maxHeight (mw);
>             }
>
>             parent.requestLayout ();
>         };
>     }
> }

Remy, just a quick note to say thank you again!

I had to make a small adjustment to make the Resizer class 
completely generic for all cases, but I can only guess you did 
not need this as your use case probably had the ResizerWidget 
parent as the outermost widget.

The issue is that the currentPosition argument in the resizeEvent 
handler is in terms of the application window, and not in terms 
of the ResizerWidget parent. So, if you have another widget above 
the ResizerWidget parent (in the Orientation.Vertical case) or to 
the left of the ResizerWidget parent (in the 
Orientation.Horizontal case), you have a small offset issue. The 
same applies if you have margins or padding on the ResizerWidget 
parent (or any of its parent(s)).

Anyway, the fix is quite trivial:

     /// Initialize the resize on drag behaviour callback.
     protected void initResizeCb () {
         this.resizeEvent
             = delegate(ResizerWidget source,
                ResizerEventType event,
                int currentPosition)
         {
             if (event != ResizerEventType.Dragging) {
                 return;
             }

			int delta;
			int pw;
			int mw;
			int localPos;
             if (_orientation == Orientation.Horizontal) {
		localPos = currentPosition - parent.left;
                 delta = _previousWidget.width - localPos;
                 pw    = max (0, _previousWidget.width - delta);
                 mw    = max (0,     _nextWidget.width + delta);

                 _previousWidget
                     .minWidth (pw)
                     .maxWidth (pw);

                 _nextWidget
                     .minWidth (mw)
                     .maxWidth (mw);
             }
             else if (_orientation == Orientation.Vertical) {
		localPos = currentPosition - parent.top;
                 delta = _previousWidget.height - localPos;
                 pw    = max (0, _previousWidget.height - delta);
                 mw    = max (0,     _nextWidget.height + delta);

                 _previousWidget
                     .minHeight (pw)
                     .maxHeight (pw);

                 _nextWidget
                     .minHeight (mw)
                     .maxHeight (mw);
             }

             parent.requestLayout ();
         };
     }
}






More information about the Digitalmars-d-learn mailing list