Skip to content

Commit

Permalink
Merge pull request #1322 from KeyWorksRW/darkmode
Browse files Browse the repository at this point in the history
Darkmode
  • Loading branch information
Randalphwa committed Nov 30, 2023
1 parent f1ad762 commit e5abc58
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 14 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# Change Log
All notable changes to this project will be documented in this file.

## [unreleased (1.2.1)]

### Added

- Dark Mode and High Contrast Dark Mode are now available in the Prefences dialog on Windows.

### Changed

- The `hide_children` property in the wxStaticBoxSizer has been removed since the `hidden` property does exactly the same thing. Projects where `hide_children` was set will be automatically converted to use `hidden` instead.

### Fixed

- The Show Hidden on the toolbar now shows (in the Mockup panel) the children of sizers that have their children hidden.
- Setting `hidden` in a wxStaticBoxSizer did not generate any code to hide the wxStaticBox and it's children (you had to check `hide_children` to get the code). This has been fixed.

## [Released (1.2.0)]

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/mainapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ wxIMPLEMENT_APP(App);

tt_string tt_empty_cstr;

#if wxCHECK_VERSION(3, 3, 0) && defined(_WIN32)
#if defined(_WIN32)
#include <wx/msw/darkmode.h>

class DarkSettings : public wxDarkModeSettings
Expand Down
6 changes: 5 additions & 1 deletion src/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ void Prefs::WriteConfig()
config->Write("fullpath_title", m_fullpath_title);

config->Write("enable_wakatime", m_enable_wakatime);
config->Write("dark_mode", m_dark_mode);
config->Write("high_contrast", m_high_constrast);
config->Write("load_last_project", m_is_load_last_project);
config->Write("right_propgrid", m_is_right_propgrid);
Expand All @@ -72,6 +71,11 @@ void Prefs::WriteConfig()
config->Write("python_line_length", m_python_line_length);
config->Write("ruby_line_length", m_ruby_line_length);

if (m_dark_mode_pending & PENDING_DARK_MODE_ENABLE)
{
config->Write("dark_mode", m_dark_mode_pending & PENDING_DARK_MODE_ON ? true : false);
}

config->SetPath("/");
}

Expand Down
11 changes: 11 additions & 0 deletions src/preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class Prefs
bool is_WakaTimeEnabled() const { return m_enable_wakatime; }

bool is_DarkMode() const { return m_dark_mode; }
bool is_DarkModePending() const { return m_dark_mode_pending; }
void set_DarkMode(bool value) { m_dark_mode = value; }
void set_DarkModePending(size_t value) { m_dark_mode_pending = value; }
bool is_HighContrast() const { return m_high_constrast; }
void set_HighContrast(bool value) { m_high_constrast = value; }

Expand Down Expand Up @@ -128,6 +130,13 @@ class Prefs
PREFS_PJT_MEMBER_PREFIX = 1 << 1,
};

enum : size_t
{
PENDING_DARK_MODE_ENABLE = 1,
PENDING_DARK_MODE_ON = 1 << 1,
PENDING_DARK_MODE_OFF = 1 << 2,
};

// clang-format on

private:
Expand All @@ -144,6 +153,8 @@ class Prefs
wxColour m_colour_python { wxColour("#FF00FF") };
wxColour m_colour_ruby { wxColour("#FF00FF") };

size_t m_dark_mode_pending { 0 }; // 0 = no change, 1 = dark_mode_on, 2 = dark_mode_off

int m_cpp_line_length { 110 };
int m_python_line_length { 90 };
int m_ruby_line_length { 80 };
Expand Down
25 changes: 14 additions & 11 deletions src/ui/preferences_dlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ bool PreferencesDlg::Create(wxWindow* parent, wxWindowID id, const wxString& tit
auto* page_general = new wxPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
notebook->AddPage(page_general, "General", true);

auto* page_sizer_1 = new wxBoxSizer(wxVERTICAL);
m_general_page_sizer = new wxBoxSizer(wxVERTICAL);

m_box_dark_settings = new wxBoxSizer(wxHORIZONTAL);

Expand All @@ -43,25 +43,25 @@ bool PreferencesDlg::Create(wxWindow* parent, wxWindowID id, const wxString& tit
m_check_high_contrast->SetToolTip("Only used if Dark Mode is selected");
m_box_dark_settings->Add(m_check_high_contrast, wxSizerFlags().Border(wxALL));
m_box_dark_settings->ShowItems(false);
page_sizer_1->Add(m_box_dark_settings,
m_general_page_sizer->Add(m_box_dark_settings,
wxSizerFlags().Expand().Border(wxRIGHT|wxTOP|wxBOTTOM, wxSizerFlags::GetDefaultBorder()));

m_check_right_propgrid = new wxCheckBox(page_general, wxID_ANY, "Property Panel on Right");
m_check_right_propgrid->SetToolTip("If checked, the Property panel will be moved to the right side");
page_sizer_1->Add(m_check_right_propgrid, wxSizerFlags(1).Border(wxALL));
m_general_page_sizer->Add(m_check_right_propgrid, wxSizerFlags(1).Border(wxALL));

m_check_load_last = new wxCheckBox(page_general, wxID_ANY, "Always load last project");
page_sizer_1->Add(m_check_load_last, wxSizerFlags(1).Border(wxALL));
m_general_page_sizer->Add(m_check_load_last, wxSizerFlags(1).Border(wxALL));

m_check_fullpath = new wxCheckBox(page_general, wxID_ANY, "Full project path in title bar");
page_sizer_1->Add(m_check_fullpath, wxSizerFlags(1).Border(wxALL));
m_general_page_sizer->Add(m_check_fullpath, wxSizerFlags(1).Border(wxALL));

auto* checkBox_wakatime = new wxCheckBox(page_general, wxID_ANY, "Enable WakaTime");
checkBox_wakatime->SetValue(true);
checkBox_wakatime->SetValidator(wxGenericValidator(&m_isWakaTimeEnabled));
checkBox_wakatime->SetToolTip(
"If you have WakaTime installed, checking this will record time spent in the editor as \"designing\". (See https://wakatime.com/about)");
page_sizer_1->Add(checkBox_wakatime, wxSizerFlags().Border(wxALL));
m_general_page_sizer->Add(checkBox_wakatime, wxSizerFlags().Border(wxALL));

m_box_code_font = new wxBoxSizer(wxHORIZONTAL);

Expand All @@ -74,8 +74,8 @@ bool PreferencesDlg::Create(wxWindow* parent, wxWindowID id, const wxString& tit
m_code_font_picker->SetToolTip("This font will be used for all of the Code panels");
m_box_code_font->Add(m_code_font_picker, wxSizerFlags(1).Expand().Border(wxALL));

page_sizer_1->Add(m_box_code_font, wxSizerFlags().Expand().Border(wxALL));
page_general->SetSizerAndFit(page_sizer_1);
m_general_page_sizer->Add(m_box_code_font, wxSizerFlags().Expand().Border(wxALL));
page_general->SetSizerAndFit(m_general_page_sizer);

auto* page_cpp = new wxPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
notebook->AddPage(page_cpp, "C++");
Expand Down Expand Up @@ -234,8 +234,9 @@ void PreferencesDlg::OnInit(wxInitDialogEvent& event)
m_box_code_font->ShowItems(false);
// m_code_font_picker = UserPrefs.get_CodeDisplayFont();

#if !wxCHECK_VERSION(3, 3, 0) || !defined(_WIN32)
m_box_dark_settings->ShowItems(false);
#if defined(__WXMSW__)
m_box_dark_settings->ShowItems(true);
m_general_page_sizer->Layout();
Fit();
#endif

Expand Down Expand Up @@ -274,7 +275,9 @@ void PreferencesDlg::OnOK(wxCommandEvent& WXUNUSED(event))
if (m_check_fullpath->GetValue() != UserPrefs.is_FullPathTitle())
is_fullpath_changed = true;

UserPrefs.set_DarkMode(m_check_dark_mode->GetValue());
UserPrefs.set_DarkModePending(
Prefs::PENDING_DARK_MODE_ENABLE |
(m_check_dark_mode->GetValue() ? Prefs::PENDING_DARK_MODE_ON : Prefs::PENDING_DARK_MODE_OFF));
UserPrefs.set_HighContrast(m_check_high_contrast->GetValue());
UserPrefs.set_FullPathTitle(m_check_fullpath->GetValue());

Expand Down
1 change: 1 addition & 0 deletions src/ui/preferences_dlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class PreferencesDlg : public wxDialog

wxBoxSizer* m_box_code_font;
wxBoxSizer* m_box_dark_settings;
wxBoxSizer* m_general_page_sizer;
wxCheckBox* m_check_cpp_snake_case;
wxCheckBox* m_check_dark_mode;
wxCheckBox* m_check_fullpath;
Expand Down
3 changes: 2 additions & 1 deletion src/wxui/wxUiEditor.wxui
Original file line number Diff line number Diff line change
Expand Up @@ -6456,8 +6456,9 @@
window_style="wxTAB_TRAVERSAL">
<node
class="wxBoxSizer"
class_access="protected:"
orientation="wxVERTICAL"
var_name="page_sizer_1">
var_name="m_general_page_sizer">
<node
class="wxBoxSizer"
class_access="protected:"
Expand Down

0 comments on commit e5abc58

Please # to comment.