Skip to content

Commit

Permalink
fix(windows): Improved minimal window sizes and general window layout…
Browse files Browse the repository at this point in the history
…s. (#13)
  • Loading branch information
Burtan authored Apr 26, 2024
1 parent fd257a1 commit a6b690a
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 80 deletions.
5 changes: 4 additions & 1 deletion liblpe/controller/AboutController.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@

#include <liblpe/ui/base/DockWindow.h>

class AboutController : public DockWindow {
class AboutController final : public DockWindow {
public:
AboutController();
protected:
LONG getMinWidth() override { return 250; }
LONG getMinHeight() override { return 50; }
};

#endif //LPE_ABOUTCONTROLLER_H
3 changes: 3 additions & 0 deletions liblpe/controller/ConfirmationController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

#include <liblpe/resources/resource.h>
#include <liblpe/controller/ConfirmationController.h>
#ifndef _WIN32
#include <swell/swell.h>
#endif

ConfirmationController::ConfirmationController(const std::string& title, std::string* name)
: ModalWindow(IDD_CONFIRM, title.data(), "ConfirmationController", 0), mName(name) {
Expand Down
4 changes: 3 additions & 1 deletion liblpe/controller/ConfirmationController.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#include <liblpe/ui/base/ModalWindow.h>

class ConfirmationController : public ModalWindow {
class ConfirmationController final : public ModalWindow {
public:
explicit ConfirmationController(const std::string& title, std::string* name);
protected:
Expand All @@ -43,6 +43,8 @@ class ConfirmationController : public ModalWindow {
void onClose() override;
LPARAM result() override;
int onNotify(WPARAM wParam, LPARAM lParam) override;
LONG getMinHeight() override { return 52; }
LONG getMinWidth() override { return 168; }
private:
std::string* mName;
};
Expand Down
2 changes: 2 additions & 0 deletions liblpe/controller/ControlViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class ControlViewController : public DockWindow {
void onClose() override;
void onResize() override;
void onInitDlg() override;
LONG getMinWidth() override { return 416; }
LONG getMinHeight() override { return 180; }
private:
HWND tabHwnd = nullptr;
std::set<int> mControlIds;
Expand Down
5 changes: 0 additions & 5 deletions liblpe/controller/LivePresetEditController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,4 @@ void LivePresetEditController::showFilterSettings() {
RECT r{};
GetWindowRect(GetDlgItem(mHwnd, IDC_SETTINGS), &r);
TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_TOPALIGN, r.left, r.bottom, 0, mHwnd, nullptr);
}

void LivePresetEditController::getMinMaxInfo(LPMINMAXINFO info) {
info->ptMinTrackSize.x = 1400;
info->ptMinTrackSize.y = 1200;
}
5 changes: 3 additions & 2 deletions liblpe/controller/LivePresetEditController.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <liblpe/ui/base/ComboBox.h>
#include <liblpe/data/models/LivePreset.h>

class LivePresetEditController : public ModalWindow {
class LivePresetEditController final : public ModalWindow {
public:
explicit LivePresetEditController(LivePreset* preset);

Expand All @@ -49,8 +49,9 @@ class LivePresetEditController : public ModalWindow {
int onKey(MSG* msg, int iKeyState) override;
void onClose() override;
LPARAM result() override;
void getMinMaxInfo(LPMINMAXINFO info) override;
int onNotify(WPARAM wParam, LPARAM lParam) override;
LONG getMinWidth() override { return 310; }
LONG getMinHeight() override { return 122; }
private:
static WNDPROC defWndProc;
static LRESULT WINAPI wndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
Expand Down
5 changes: 0 additions & 5 deletions liblpe/controller/LivePresetsController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,4 @@ void LivePresetsController::reset() const {
mList->setAdapter(std::move(adapter));
mList->invalidate();
}
}

void LivePresetsController::getMinMaxInfo(LPMINMAXINFO info) {
info->ptMinTrackSize.x = 1284;
info->ptMinTrackSize.y = 625;
}
6 changes: 3 additions & 3 deletions liblpe/controller/LivePresetsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
#include <liblpe/ui/base/DockWindow.h>
#include <liblpe/ui/base/ListView.h>
#include <liblpe/data/models/LivePreset.h>
#include <liblpe/controller/LivePresetEditController.h>

class LivePresetsController : public DockWindow {
class LivePresetsController final : public DockWindow {
public:
LivePresetsController();
std::unique_ptr<ListView<LivePreset>> mList = nullptr;
Expand All @@ -53,7 +52,8 @@ class LivePresetsController : public DockWindow {
int onNotify(WPARAM wParam, LPARAM lParam) override;
void onClose() override;
void onInitDlg() override;
void getMinMaxInfo(LPMINMAXINFO info) override;
LONG getMinWidth() override { return 300; }
LONG getMinHeight() override { return 200; }
private:
static void recallLivePreset(LivePreset* preset);
void applyFilterToSelectedTracks(int filterIndex) const;
Expand Down
4 changes: 3 additions & 1 deletion liblpe/controller/SettingsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <liblpe/ui/base/ModalWindow.h>
#include <liblpe/ui/base/ComboBox.h>

class SettingsController : public ModalWindow {
class SettingsController final : public ModalWindow {
public:
SettingsController();
protected:
Expand All @@ -43,6 +43,8 @@ class SettingsController : public ModalWindow {
void onClose() override;
LPARAM result() override;
int onNotify(WPARAM wParam, LPARAM lParam) override;
LONG getMinHeight() override { return 278; }
LONG getMinWidth() override { return 200; }
private:
std::unique_ptr<ComboBox> mCombo = nullptr;

Expand Down
2 changes: 1 addition & 1 deletion liblpe/data/models/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ std::string Control::getChunkId() const {
}

const char *Control::getName(int index) const {
sprintf(mNameText, "%i: \n", index);
snprintf(mNameText, 256, "%i: \n", index);
return (const char*) mNameText;
}
44 changes: 22 additions & 22 deletions liblpe/resources/resource.rc
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#include <resource.h>
#include "resource.h"

#ifdef _WIN32
#include <winres.h>
#endif

IDD_LIVEPRESETS DIALOGEX 0, 0, 528, 200
STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
IDD_LIVEPRESETS DIALOGEX 0, 0, 450, 200
STYLE DS_SETFONT | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
FONT DEFAULT_FONT
BEGIN
CONTROL "",IDC_LIST,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | WS_BORDER,8,8,512,160
PUSHBUTTON "Add",IDC_ADD,8,176,72,16
PUSHBUTTON "Update",IDC_UPDATE,88,176,72,16
PUSHBUTTON "Edit",IDC_EDIT,168,176,72,16
PUSHBUTTON "Remove",IDC_REMOVE,248,176,72,16
PUSHBUTTON "Settings", IDC_SETTINGS,448,176,72,16
CONTROL "",IDC_LIST,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | WS_BORDER,8,8,434,160
PUSHBUTTON "Add",IDC_ADD,8,176,48,16
PUSHBUTTON "Update",IDC_UPDATE,64,176,48,16
PUSHBUTTON "Edit",IDC_EDIT,120,176,48,16
PUSHBUTTON "Remove",IDC_REMOVE,176,176,48,16
PUSHBUTTON "Settings", IDC_SETTINGS,394,176,48,16
END

IDD_LIVEPRESET DIALOGEX 0, 0, 310, 92
STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
IDD_LIVEPRESET DIALOGEX 0, 0, 310, 122
STYLE DS_SETFONT | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
FONT DEFAULT_FONT
BEGIN
LTEXT "Name:",IDC_STATIC,8,10,40,8
Expand All @@ -27,16 +27,16 @@ BEGIN
EDITTEXT IDC_DESC,56,28,128,12,ES_AUTOHSCROLL
EDITTEXT IDC_ID,56,48,128,12,ES_AUTOHSCROLL | ES_NUMBER
PUSHBUTTON "Set Recall Hotkey",IDC_RECALL,56,68,128,12
PUSHBUTTON "Cancel",IDC_CANCEL,8,68,72,16
PUSHBUTTON "OK",IDC_SAVE,88,68,72,16
PUSHBUTTON "Cancel",IDC_CANCEL,8,98,72,16
PUSHBUTTON "OK",IDC_SAVE,88,98,72,16
LTEXT "Filter:",IDC_LABEL1,192,10,20,8
COMBOBOX IDC_COMBO,220,8,68,16,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "+",IDC_SETTINGS,292,8,10,10
CONTROL "",IDC_TREE,"SysTreeView32",TVS_HASBUTTONS | TVS_DISABLEDRAGDROP | TVS_TRACKSELECT | TVS_LINESATROOT | WS_BORDER,192,24,110,60
END

IDD_SETTINGS DIALOGEX 0, 0, 200, 278
STYLE DS_MODALFRAME | DS_SHELLFONT | WS_POPUP | WS_SYSMENU | WS_CAPTION
STYLE DS_SETFONT | DS_CENTER | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
FONT DEFAULT_FONT
BEGIN
PUSHBUTTON "Bind recall action",IDC_RECALL,8,8,184,16
Expand All @@ -54,7 +54,7 @@ BEGIN
END

IDD_CONFIRM DIALOGEX 0, 0, 168, 52
STYLE DS_MODALFRAME | DS_SHELLFONT | WS_POPUP | WS_SYSMENU | WS_CAPTION
STYLE DS_SETFONT | DS_CENTER | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
FONT DEFAULT_FONT
BEGIN
LTEXT "Name:",IDC_STATIC,8,10,40,8
Expand All @@ -63,19 +63,19 @@ BEGIN
PUSHBUTTON "OK",IDC_SAVE,88,28,72,16
END

IDD_CONTROLVIEW DIALOGEX 0, 0, 616, 380
STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
IDD_CONTROLVIEW DIALOGEX 0, 0, 416, 180
STYLE DS_SETFONT | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
FONT DEFAULT_FONT
BEGIN
PUSHBUTTON "Add Hardware",IDC_ADD,8,8,72,16
PUSHBUTTON "Remove Hardware",IDC_REMOVE,88,8,72,16
PUSHBUTTON "Add Control",IDC_ADD2,456,8,72,16
PUSHBUTTON "Remove Control",IDC_REMOVE2,536,8,72,16
CONTROL "TabControl", IDC_TAB,"SysTabControl32",WS_TABSTOP,8,72,600,300
PUSHBUTTON "Add Control",IDC_ADD2,256,8,72,16
PUSHBUTTON "Remove Control",IDC_REMOVE2,336,8,72,16
CONTROL "TabControl", IDC_TAB,"SysTabControl32",WS_TABSTOP,8,72,400,300
END

IDD_ABOUT DIALOGEX 0, 0, 500, 250
STYLE DS_MODALFRAME | DS_SHELLFONT | WS_POPUP | WS_SYSMENU | WS_CAPTION
IDD_ABOUT DIALOGEX 0, 0, 250, 50
STYLE DS_SETFONT | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
FONT DEFAULT_FONT
BEGIN

Expand Down
72 changes: 61 additions & 11 deletions liblpe/ui/base/DockWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <liblpe/ui/base/DockWindow.h>
#ifdef _WIN32
#include <windowsx.h>
#include <shellscalingapi.h>
#else
#include <liblpe/util/util.h>
#endif
Expand Down Expand Up @@ -80,11 +81,57 @@ void DockWindow::initDialog(HWND hwndDlg) {
* @param pointer that stores the size infos
*/
void DockWindow::getMinMaxInfo(LPMINMAXINFO info) {
int w = 150;
int h = 150;
double dpiFactor = 1.5;
int staticX = 0;
int staticY = 0;

info->ptMinTrackSize.x = w;
info->ptMinTrackSize.y = h;
#ifdef _WIN32
// 310/92 in .rc scales to 465/481/150/189 at 100 %, 930/958/288/359 at 200 %,
// 100 % is 1,5 * x + 0/16 and 1,5 * y + 12/51 (16 width and 39 height for window decorations at 100 %)
// 200 % is 3 * x + 0/28 and 3 * y + 12/83 (28 width and 71 height for window decorations at 200 %)
DPI_AWARENESS dpiAwareness = GetAwarenessFromDpiAwarenessContext(GetThreadDpiAwarenessContext());
if (dpiAwareness == DPI_AWARENESS_PER_MONITOR_AWARE) {
dpiFactor = 3 * GetDpiForWindow(mHwnd) / 192.0;
} else if (dpiAwareness == DPI_AWARENESS_UNAWARE) {
// only works on DPI_AWARENESS_UNAWARE
auto monitor = MonitorFromWindow(mHwnd, MONITOR_DEFAULTTONEAREST);
DEVICE_SCALE_FACTOR scale;
auto result = GetScaleFactorForMonitor(monitor, &scale);
if (result == S_OK) {
dpiFactor = 3 * scale / 200.0;
} else {
dpiFactor = 1.5;
}
} else {
dpiFactor = 1.5;
}

staticY = 12;
#elif __APPLE__
// 310/92 in .rc scales to 527/156/184 at 100 %
// 100 % is 1,7 * x and 1,7 * y + 28 (28 height for window decorations at 100 %)
// TODO
/*RECT wnd, clnt;
GetClientRect(mHwnd, &clnt);
GetWindowRect(mHwnd, &wnd);
char msg[512];
snprintf(msg, 512,
"client: %d, %d, %d, %d\nwnd: %d, %d, %d, %d\nfactor: %f\n",
clnt.left, clnt.top, clnt.right - clnt.left, clnt.bottom - clnt.top,
wnd.left, wnd.top, wnd.right - wnd.left, wnd.bottom - wnd.top,
dpiFactor
);
ShowConsoleMsg(msg);*/
dpiFactor = 1.7;
#else
// LPMINMAX corresponds to Window rect 1:2 for 100 % and scales linear
// 310/92 in .rc scales to 620/184 at 100 % and 1240/368 at 200 % for client and window rect
dpiFactor = SWELL_GetScaling256() / 128.0;
#endif

info->ptMinTrackSize.x = getMinWidth() * dpiFactor + staticX;
info->ptMinTrackSize.y = getMinHeight() * dpiFactor + staticY;
}

/**
Expand All @@ -106,7 +153,7 @@ void DockWindow::toggleVisibility() {
}
}

void DockWindow::focus() {
[[maybe_unused]] void DockWindow::focus() {
if (isDocked()) {
DockWindowActivate(mHwnd);
}
Expand Down Expand Up @@ -235,9 +282,12 @@ int DockWindow::keyHandler(MSG* msg, accelerator_register_t* ctx) {
DockWindowState DockWindow::getStateForPersistance() {
DockWindowState state{};
state.dockId = DockIsChildOfDock(mHwnd, nullptr);
RECT r = RECT();
GetWindowRect(mHwnd, &r);
state.pos = r;
auto rect = RECT();
GetWindowRect(mHwnd, &rect);
state.top = rect.top;
state.left = rect.left,
state.width = rect.right - rect.left;
state.height = rect.bottom - rect.top;
state.visible = isVisible();
return state;
}
Expand All @@ -254,9 +304,9 @@ void DockWindow::loadStateFromPersistance(DockWindowState state) {
DockWindowAddEx(mHwnd, mTitle.data(), mId.data(), true);
Dock_UpdateDockID(mId.data(), state.dockId);
} else {
RECT r = state.pos;
EnsureNotCompletelyOffscreen(&r);
SetWindowPos(mHwnd, nullptr, r.left, r.top, r.right - r.left, r.bottom - r.top, 0);
auto rect = RECT{state.left, state.top, state.left + state.width, state.top + state.height};
EnsureNotCompletelyOffscreen(&rect);
SetWindowPos(mHwnd, nullptr, state.left, state.top, state.width, state.height, 0);
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions liblpe/ui/base/DockWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,18 @@
typedef struct DockWindowState {
int visible = 1; //-1 not saved, 0 hidden, 1 showing
int dockId = -1; //-1 not docked, >= 0 dockId
RECT pos = RECT{500, 200, 1000, 500}; // position and size
LONG left = 500;
LONG top = 200;
LONG width = 500;
LONG height = 300;
} DockWindowState;

class DockWindow {
public:
explicit DockWindow(int iResource = 0, const char* cWndTitle = "", const char* cId = "", int iCmdID = 0);
virtual ~DockWindow();

void focus();
[[maybe_unused]] [[maybe_unused]] void focus();
bool isDocked();
bool isVisible();
void show(bool loadState = true);
Expand All @@ -73,7 +76,8 @@ class DockWindow {
virtual void onInitDlg() {}
virtual int onKey(MSG* msg, int iKeyState) { return 0; } // return 1 for "processed key"
virtual INT_PTR onUnhandledMsg(UINT uMsg, WPARAM wParam, LPARAM lParam) { return 0; }
virtual void getMinMaxInfo(LPMINMAXINFO info);
virtual LONG getMinWidth() { return 150; }
virtual LONG getMinHeight() { return 150; }

HWND mHwnd;
int mCmdId;
Expand All @@ -92,6 +96,7 @@ class DockWindow {
DockWindowState getStateForPersistance();
void loadStateFromPersistance(DockWindowState state);
void showContextMenu(int x, int y, HMENU menu);
virtual void getMinMaxInfo(LPMINMAXINFO info);
};

#endif //LPE_DOCKWINDOW_H
Loading

0 comments on commit a6b690a

Please sign in to comment.