[idd] helper: display configured modes in listbox

This commit is contained in:
Quantum
2025-09-22 01:56:46 -04:00
committed by Geoffrey McRae
parent 96367e83f1
commit 7a3833782c
2 changed files with 28 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
#include "CConfigWindow.h"
#include "CListBox.h"
#include <CDebug.h>
#include <windowsx.h>
#include <strsafe.h>
@@ -20,16 +21,18 @@ bool CConfigWindow::registerClass()
CConfigWindow::CConfigWindow() : m_scale(1)
{
LSTATUS error = m_settings.open();
if (error != ERROR_SUCCESS)
DEBUG_ERROR_HR(error, "Failed to load settings");
else
m_modes = m_settings.getModes();
if (!CreateWindowEx(0, MAKEINTATOM(s_atom), L"Looking Glass IDD Configuration",
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, 500, 400,
NULL, NULL, hInstance, this))
{
DEBUG_ERROR_HR(GetLastError(), "Failed to create window");
}
m_scale = GetDpiForWindow(m_hwnd) / 96.0;
m_version.reset(new CStaticWidget(L"Looking Glass IDD " LG_VERSION_STR, WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE, m_hwnd));
updateFont();
}
void CConfigWindow::updateFont()
@@ -49,7 +52,7 @@ void CConfigWindow::updateFont()
return;
}
for (HWND child : std::initializer_list<HWND>({ *m_version }))
for (HWND child : std::initializer_list<HWND>({ *m_version, *m_modeBox }))
SendMessage(child, WM_SETFONT, (WPARAM)m_font.Get(), 1);
}
@@ -77,6 +80,18 @@ LRESULT CConfigWindow::handleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
LRESULT CConfigWindow::onCreate()
{
m_scale = GetDpiForWindow(m_hwnd) / 96.0;
m_version.reset(new CStaticWidget(L"Looking Glass IDD " LG_VERSION_STR, WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE, m_hwnd));
m_modeBox.reset(new CListBox(WS_CHILD | WS_VISIBLE | LBS_NOTIFY, m_hwnd));
if (m_modes)
{
auto &modes = *m_modes;
for (size_t i = 0; i < modes.size(); ++i)
m_modeBox->addItem(modes[i].toString(), i);
}
updateFont();
return 0;
}
@@ -91,5 +106,6 @@ LRESULT CConfigWindow::onResize(DWORD width, DWORD height)
{
WidgetPositioner pos(m_scale, width, height);
pos.pinTopLeftRight(*m_version, 12, 12, 12, 20);
pos.pinLeftTopBottom(*m_modeBox, 12, 40, 200, 12);
return 0;
}

View File

@@ -1,20 +1,27 @@
#pragma once
#include "CWindow.h"
#include "CStaticWidget.h"
#include "CRegistrySettings.h"
#include <functional>
#include <memory>
#include <optional>
#include <wrl.h>
#include "UIHelpers.h"
class CListBox;
class CConfigWindow : public CWindow
{
static ATOM s_atom;
std::unique_ptr<CStaticWidget> m_version;
std::unique_ptr<CListBox> m_modeBox;
std::function<void()> m_onDestroy;
double m_scale;
Microsoft::WRL::Wrappers::HandleT<FontTraits> m_font;
CRegistrySettings m_settings;
std::optional<std::vector<DisplayMode>> m_modes;
void updateFont();