Allow user to resize wxDialog without border Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
rudolfninja
Earned some good credits
Earned some good credits
Posts: 107
Joined: Tue Aug 28, 2018 1:02 pm
Location: Belarus

Allow user to resize wxDialog without border

Post by rudolfninja »

Greetings,
I need to make wxDialog resistible by user but without border (thus, not using wxRESIZE_BORDER style). This ugly border doesn't fit in my dialog's appearance.
without resize border
without resize border
withoutBorder.png (16.14 KiB) Viewed 1071 times
with resize border
with resize border
withBorder.png (15.49 KiB) Viewed 1071 times
So I need to combine wxRESIZE_BORDER style with wxNO_BORDER.
Are there variants to solve the problem using features provided by wxWidgets or should I do resize by myself?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Allow user to resize wxDialog without border

Post by doublemax »

You can't get the OS's resize behavior without the wxRESIZE_BORDER flag. You'll have to implement that yourself.

This is not difficult in principle, but will require more code than you might expect. And on top of that, the default resize border is a clear indicator to the user that he can resize the window, which is important IMHO. So i'm not sure it's worth the effort.
Use the source, Luke!
rudolfninja
Earned some good credits
Earned some good credits
Posts: 107
Joined: Tue Aug 28, 2018 1:02 pm
Location: Belarus

Re: Allow user to resize wxDialog without border

Post by rudolfninja »

Could you please describe common algorithm how to implement it by myself?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Allow user to resize wxDialog without border

Post by doublemax »

In words:

Capture mouse move events. If mouse pointer is near the edge of the frame, change mouse cursor accordingly.
If the user clicks while near the edge, capture the mouse until the mouse is released.
While the mouse it captured, on mouse move, resize and move the window, depending on where the user grabbed the window (possibilities: 4 edges and 4 corners).

The "shaped" sample that comes with wxWidgets implements its own code to move the window. The approach is similar and could serve as a starting point.
Use the source, Luke!
rudolfninja
Earned some good credits
Earned some good credits
Posts: 107
Joined: Tue Aug 28, 2018 1:02 pm
Location: Belarus

Re: Allow user to resize wxDialog without border

Post by rudolfninja »

Tried to implement this solution:

Code: Select all

void wxRTSharesManagerDialog::OnLeftDown(wxMouseEvent& event)
{
    CaptureMouse();
}

void wxRTSharesManagerDialog::OnLeftUp(wxMouseEvent& event)
{
    if (HasCapture())
    {
        ReleaseMouse();
    }
}

void wxRTSharesManagerDialog::OnMouseMove(wxMouseEvent& event)
{
    wxPoint pt = event.GetPosition();
    wxRect windowRect = this->GetRect();
    if (windowRect.GetHeight() - pt.y < 5)
    {
        SetCursor(wxCURSOR_SIZENS);
        if (event.Dragging() && event.LeftIsDown())
        {
            wxPoint pos = ClientToScreen(pt);
            wxSize sz = GetSize();
            sz.y += pos.y - windowRect.GetBottom();
            SetSize(sz);
        }
    }
    else
    {
        SetCursor(wxCURSOR_DEFAULT);
    }
}
This code works fine when I increase dialog's size (height), however when I try to decrease height (moving mouse up with left button pressed) dialog's height almost doesn't changed - it is decreased by 5-6 pixels and then size isn't changed.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Allow user to resize wxDialog without border

Post by doublemax »

Code: Select all

if (windowRect.GetHeight() - pt.y < 5)
You should skip this check if you're already in "resize mode", the difference between two mouse positions can easily be bigger than 5.
Use the source, Luke!
Post Reply