MSW specific: Fixed update of the UI after system color change.

Note: the wxEVT_SYS_COLOUR_CHANGED event works only for high contrast settings under MSW.

+ ConfigSnapshotDialog: Fixed UI colors for dark mode on all platforms
This commit is contained in:
YuSanka 2021-04-06 22:20:24 +02:00
parent 2418b3dbeb
commit effad844e2
6 changed files with 40 additions and 8 deletions

View file

@ -29,11 +29,20 @@ static wxString format_reason(const Config::Snapshot::Reason reason)
}
}
static wxString generate_html_row(const Config::Snapshot &snapshot, bool row_even, bool snapshot_active)
static std::string get_color(wxColour colour)
{
wxString clr_str = wxString::Format(wxT("#%02X%02X%02X"), colour.Red(), colour.Green(), colour.Blue());
return clr_str.ToStdString();
};
static wxString generate_html_row(const Config::Snapshot &snapshot, bool row_even, bool snapshot_active, bool dark_mode)
{
// Start by declaring a row with an alternating background color.
wxString text = "<tr bgcolor=\"";
text += snapshot_active ? "#B3FFCB" : (row_even ? "#FFFFFF" : "#D5D5D5");
text += snapshot_active ?
dark_mode ? "#208a20" : "#B3FFCB" :
(row_even ? get_color(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)) : dark_mode ? "#656565" : "#D5D5D5" );
text += "\">";
text += "<td>";
@ -92,14 +101,15 @@ static wxString generate_html_row(const Config::Snapshot &snapshot, bool row_eve
static wxString generate_html_page(const Config::SnapshotDB &snapshot_db, const wxString &on_snapshot)
{
bool dark_mode = wxGetApp().dark_mode();
wxString text =
"<html>"
"<body bgcolor=\"#ffffff\" cellspacing=\"2\" cellpadding=\"0\" border=\"0\" link=\"#800000\">"
"<font color=\"#000000\">";
"<body bgcolor=\"" + get_color(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)) + "\" cellspacing=\"2\" cellpadding=\"0\" border=\"0\" link=\"#800000\">"
"<font color=\"" + get_color(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)) + "\">";
text += "<table style=\"width:100%\">";
for (size_t i_row = 0; i_row < snapshot_db.snapshots().size(); ++ i_row) {
const Config::Snapshot &snapshot = snapshot_db.snapshots()[snapshot_db.snapshots().size() - i_row - 1];
text += generate_html_row(snapshot, i_row & 1, snapshot.id == on_snapshot);
text += generate_html_row(snapshot, i_row & 1, snapshot.id == on_snapshot, dark_mode);
}
text +=
"</table>"
@ -115,8 +125,8 @@ ConfigSnapshotDialog::ConfigSnapshotDialog(const Config::SnapshotDB &snapshot_db
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX)
{
this->SetFont(wxGetApp().normal_font());
this->SetBackgroundColour(*wxWHITE);
this->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
wxBoxSizer* vsizer = new wxBoxSizer(wxVERTICAL);
this->SetSizer(vsizer);