From ae3225a4e7ef86d159fdf27834c453ffcd4da76c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Tue, 2 Aug 2022 20:10:35 +0200 Subject: Implement draggable split. Next step is to allow a double click to reset the split to be automatically resized. --- c/layout.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 c/layout.cpp (limited to 'c/layout.cpp') diff --git a/c/layout.cpp b/c/layout.cpp new file mode 100644 index 0000000..77aa88e --- /dev/null +++ b/c/layout.cpp @@ -0,0 +1,64 @@ +#include +#include + +#include "common.h" +#include "episodelistview.h" +#include "datalistview.h" +#include "layout.h" + +extern HWND g_hWnd; +extern HWND g_hWndStatus; +extern EpisodeListView* g_elv; +extern DataListView* g_dlv; + +void UpdateLayout(int w, int h) +{ + if (!g_hWndStatus) return; + + RECT rc, rrStatus; + if (w && h) rc = {0, 0, w, h}; + else require(GetClientRect(g_hWnd, &rc)); + require(GetRelativeRect(g_hWndStatus, &rrStatus)); + + SendMessage(g_hWnd, WM_SETREDRAW, FALSE, 0); + + /* Resize list views. */ + const long pad = IsThemeActive()? Dpi(6): 0; /* Add padding in modern themes. */ + const long cyDlv = rrStatus.top-g_dlv->Height()-pad; + require(SetWindowRect(g_dlv->hWnd, pad, cyDlv, rc.right-pad, rrStatus.top-pad)); + require(SetWindowRect(g_elv->hWnd, pad, pad, rc.right-pad, cyDlv-pad)); + g_dlv->ResizeColumns(rc.right-pad-pad); + g_elv->ResizeColumns(rc.right-pad-pad); + + /* Resize status bar parts. */ + const int aParts[] = {rc.right-Dpi(55), rc.right}; + SendMessage(g_hWndStatus, SB_SETPARTS, (WPARAM)sizeof(aParts), (LPARAM)aParts); + + SendMessage(g_hWnd, WM_SETREDRAW, TRUE, 0); + RedrawWindow(g_hWnd, NULL, NULL, + RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN); +} + +bool Dragger::InDragArea(const int x, const int y) +{ + RECT rrDlv; + require(GetRelativeRect(g_dlv->hWnd, &rrDlv)); + + const int pad = IsThemeActive()? Dpi(6): 0; + const int extra = IsThemeActive()? 0: Dpi(2); + if (x < rrDlv.left || x > rrDlv.right) return false; + if (y < rrDlv.top-pad*2-extra*3 || y > rrDlv.top+extra) return false; + return true; +} + +void Dragger::Drag(const int, const int y) +{ + RECT rrDlv; + require(GetRelativeRect(g_dlv->hWnd, &rrDlv)); + int h; + h = rrDlv.bottom-y; + g_dlv->SetHeight(h); + UpdateLayout(); + RedrawWindow(g_hWnd, NULL, NULL, + RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN|RDW_UPDATENOW); +} -- cgit v1.2.3