Skip to content

Commit

Permalink
Dark calendar (stevencohn#721)
Browse files Browse the repository at this point in the history
* upgrade csharp v9
* introduce dark theme
  • Loading branch information
stevencohn authored Nov 13, 2022
1 parent 5c80a73 commit 8b5a5f1
Show file tree
Hide file tree
Showing 27 changed files with 725 additions and 273 deletions.
7 changes: 5 additions & 2 deletions OneMore/Helpers/Office/Office.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,11 @@ private static bool DarkModeLightsOn()
/// <summary>
/// Determines if Windows is set to dark mode
/// </summary>
/// <returns></returns>
private static bool SystemDefaultDarkMode()
/// <returns>True if the system default is dark mode</returns>
/// <remarks>
/// Declared as public so it can be used by OneMoreCalendar
/// </remarks>
public static bool SystemDefaultDarkMode()
{
using var key = Registry.CurrentUser.OpenSubKey(
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize");
Expand Down
28 changes: 14 additions & 14 deletions OneMoreCalendar/AboutDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions OneMoreCalendar/AboutDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
namespace OneMoreCalendar
{
using System;
using System.Drawing;
using System.Windows.Forms;


internal partial class AboutDialog : Form
internal partial class AboutDialog : ThemedForm
{

public AboutDialog()
Expand All @@ -19,11 +18,18 @@ public AboutDialog()
sponsorButton.SetHandCursor();

// TODO: beta
versionLabel.Text = string.Format(versionLabel.Text, AssemblyInfo.Version) + " (BETA)";
versionLabel.Text = string.Format(versionLabel.Text, AssemblyInfo.Version);
copyLabel.Text = string.Format(copyLabel.Text, DateTime.Now.Year);
}


protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
BackColor = Theme.BackColor;
}


private void OK(object sender, EventArgs e)
{
Close();
Expand Down
36 changes: 32 additions & 4 deletions OneMoreCalendar/CalendarForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace OneMoreCalendar
{
using OneMoreCalendar.Properties;
using River.OneMoreAddIn;
using System;
using System.Drawing;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
Expand All @@ -14,7 +16,7 @@ namespace OneMoreCalendar
/// <summary>
/// Main OneMoreCalendar form
/// </summary>
public partial class CalendarForm : Form
internal partial class CalendarForm : ThemedForm
{
private DateTime date;
private CalendarPages pages;
Expand All @@ -35,9 +37,6 @@ public CalendarForm()

Width = 1500; // TODO: save as settings?
Height = 1000;

// TODO: beta
Text = $"{Text} (BETA)";
}


Expand Down Expand Up @@ -72,6 +71,32 @@ protected override async void OnLoad(EventArgs e)
}


public override void OnThemeChange()
{
if (Theme.DarkMode)
{
var fromColor = ColorTranslator.FromHtml("#FF80397B");
todayButton.Image = Resources.today_32.MapColor(fromColor, Color.MediumOrchid);
monthButton.Image = Resources.month_32.MapColor(fromColor, Color.MediumOrchid);
dayButton.Image = Resources.day_32.MapColor(fromColor, Color.MediumOrchid);
settingsButton.Image = Resources.settings_32.MapColor(fromColor, Color.MediumOrchid);
}
else
{
todayButton.Image = Resources.settings_32;
monthButton.Image = Resources.month_32;
dayButton.Image = Resources.day_32;
settingsButton.Image = Resources.settings_32;
}

nextButton.PreferredFore = Theme.LinkColor;
nextButton.PreferredBack = Theme.BackColor;
prevButton.PreferredFore = Theme.LinkColor;
prevButton.PreferredBack = Theme.BackColor;
todayButton.PreferredBack = Theme.BackColor;
}


private async Task SetMonth(int delta)
{
if (delta < 1000)
Expand Down Expand Up @@ -166,6 +191,8 @@ await settings.GetNotebookIDs(),
settings.Created, settings.Modified, settings.Deleted);

detailView.SetRange(date, endDate, pages);
detailView.OnThemeChange();

contentPanel.Controls.Add(detailView);
}

Expand Down Expand Up @@ -378,6 +405,7 @@ private async void ClosingSettings(object sender, FormClosingEventArgs e)

if (settingsForm.DialogResult == DialogResult.OK)
{
Theme.InitializeTheme(this);
await SetMonth(date.Year);
}
}
Expand Down
61 changes: 39 additions & 22 deletions OneMoreCalendar/DetailView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace OneMoreCalendar
using System.Windows.Forms;


internal partial class DetailView : UserControl, ICalendarView
internal partial class DetailView : ThemedUserControl, ICalendarView
{
private sealed class DayItem
{
Expand Down Expand Up @@ -52,6 +52,12 @@ public DetailView()
}


public override void OnThemeChange()
{
BackColor = Theme.BackColor;
}


public event CalendarDayHandler ClickedDay;
public event CalendarHoverHandler HoverPage;
public event CalendarPageHandler ClickedPage;
Expand All @@ -60,6 +66,7 @@ public DetailView()

public void SetRange(DateTime startDate, DateTime endDate, CalendarPages pages)
{
SuspendLayout();
listbox.Items.Clear();

var date = startDate;
Expand Down Expand Up @@ -89,27 +96,26 @@ public void SetRange(DateTime startDate, DateTime endDate, CalendarPages pages)
}

Invalidate();
ResumeLayout();
}


private void HeaderPanelPaint(object sender, PaintEventArgs e)
{
using (var font = new Font("Segoe UI Light", 10.0f, FontStyle.Regular))
{
headerPanel.Height = font.Height + VPadding;
var y = (headerPanel.Height - font.Height) / 2;
using var font = new Font("Segoe UI Light", 10.0f, FontStyle.Regular);
headerPanel.Height = font.Height + VPadding;
var y = (headerPanel.Height - font.Height) / 2;

var size = e.Graphics.MeasureString("DATE", font);
e.Graphics.DrawString("DATE", font, Brushes.SlateGray,
(HeadWidth - size.Width) / 2, y);
var size = e.Graphics.MeasureString("DATE", font);
var width = e.ClipRectangle.Width - SystemInformation.VerticalScrollBarWidth;

var width = e.ClipRectangle.Width - SystemInformation.VerticalScrollBarWidth;
using var brush = new SolidBrush(Theme.MonthDayFore);

e.Graphics.DrawString("SECTION", font, Brushes.SlateGray, HeadWidth + 20, y);
e.Graphics.DrawString("PAGE", font, Brushes.SlateGray, HeadWidth + PathWidth + 40, y);
e.Graphics.DrawString("CREATED", font, Brushes.SlateGray, width - DateWidth * 2, y);
e.Graphics.DrawString("MODIFIED", font, Brushes.SlateGray, width - DateWidth, y);
}
e.Graphics.DrawString("DATE", font, brush, (HeadWidth - size.Width) / 2, y);
e.Graphics.DrawString("SECTION", font, brush, HeadWidth + 20, y);
e.Graphics.DrawString("PAGE", font, brush, HeadWidth + PathWidth + 40, y);
e.Graphics.DrawString("CREATED", font, brush, width - DateWidth * 2, y);
e.Graphics.DrawString("MODIFIED", font, brush, width - DateWidth, y);
}


Expand Down Expand Up @@ -138,9 +144,11 @@ private void ListBoxDrawItem(object sender, DrawItemEventArgs e)
return;
}

e.Graphics.FillRectangle(e.Index % 2 == 1 ? AppColors.RowBrush : Brushes.White, e.Bounds);
using var fill = new SolidBrush(e.Index % 2 == 1 ? Theme.DetailOddBack : Theme.DetailEvenBack);
e.Graphics.FillRectangle(fill, e.Bounds);

e.Graphics.DrawLine(Pens.LightGray, e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Top);
using var line = new Pen(Theme.MonthGrid);
e.Graphics.DrawLine(line, e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Top);
//e.Graphics.DrawLine(Pens.LightGray, HeadWidth, e.Bounds.Top, HeadWidth, e.Bounds.Bottom);

if (listbox.Items[e.Index] is DayItem day)
Expand All @@ -151,7 +159,11 @@ private void ListBoxDrawItem(object sender, DrawItemEventArgs e)
// header
var head = day.Date.ToString("ddd, MMM d");
var size = e.Graphics.MeasureString(head, listbox.Font);
e.Graphics.DrawString(head, listbox.Font, Brushes.Black,

using var fore = new SolidBrush(Theme.ForeColor);
using var gray = new SolidBrush(Color.Gray);

e.Graphics.DrawString(head, listbox.Font, fore,
(HeadWidth - size.Width) / 2,
e.Bounds.Top + (e.Bounds.Height - size.Height) / 2);

Expand All @@ -162,7 +174,7 @@ private void ListBoxDrawItem(object sender, DrawItemEventArgs e)
// predict width of page title
size = e.Graphics.MeasureString(page.Title, listbox.Font);

var color = page.IsDeleted ? Brushes.Gray : Brushes.Black;
var color = page.IsDeleted ? gray : fore;

// section
e.Graphics.DrawString(page.Path,
Expand Down Expand Up @@ -239,11 +251,14 @@ private void ListBoxMouseMove(object sender, MouseEventArgs e)
using (var g = listbox.CreateGraphics())
{
var index = listbox.Items.IndexOf(hotday);
g.FillRectangle(index % 2 == 1 ? AppColors.RowBrush : Brushes.White, hotpage.Bounds);
using var fill = new SolidBrush(index % 2 == 1 ? Theme.DetailOddBack : Theme.DetailEvenBack);
g.FillRectangle(fill, hotpage.Bounds);

using var fore = new SolidBrush(hotpage.IsDeleted ? Color.Gray : Theme.ForeColor);

g.DrawString(hotpage.Title,
hotpage.IsDeleted ? deletedFont : listbox.Font,
hotpage.IsDeleted ? Brushes.Gray : Brushes.Black,
fore,
hotpage.Bounds, format);
}

Expand All @@ -258,11 +273,13 @@ private void ListBoxMouseMove(object sender, MouseEventArgs e)
using (var g = listbox.CreateGraphics())
{
var index = listbox.Items.IndexOf(day);
g.FillRectangle(index % 2 == 1 ? AppColors.RowBrush : Brushes.White, page.Bounds);
using var fill = new SolidBrush(index % 2 == 1 ? Theme.DetailOddBack : Theme.DetailEvenBack);
g.FillRectangle(fill, page.Bounds);

using var fore = new SolidBrush(Theme.Highlight);
g.DrawString(page.Title,
page.IsDeleted ? deletedFont : hotFont,
Brushes.DarkOrchid, page.Bounds, format);
fore, page.Bounds, format);
}

HoverPage?.Invoke(this, new CalendarPageEventArgs(page));
Expand Down
Loading

0 comments on commit 8b5a5f1

Please sign in to comment.