Skip to content

Commit

Permalink
534 fix scrolling boundaries (stevencohn#722)
Browse files Browse the repository at this point in the history
* Get boundary rather than tracking locally

* fix background color of detailview when switching theme

* theme files

* ThemeProvider rename
  • Loading branch information
stevencohn authored Nov 14, 2022
1 parent 8b5a5f1 commit 68f8443
Show file tree
Hide file tree
Showing 17 changed files with 522 additions and 332 deletions.
29 changes: 29 additions & 0 deletions OneMoreCalendar/Assets/DarkTheme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"DarkMode": true,
"Colors": {
"BackColor": "#383838",
"ForeColor": "#E6E6E6",
"Border": "DarkOrchid",
"Control": "MediumOrchid",
"Highlight": "#D2A1DF",
"ButtonBack": "#363636",
"ButtonFore": "#E6E6E6",
"ButtonDisabled": "Gray",
"ButtonBorder": "#555555",
"ButtonHotBack": "#505050",
"ButtonHotBorder": "Gray",
"ButtonPressBorder": "DarkOrchid",
"LinkColor": "MediumOrchid",
"HoverColor": "Orchid",
"MonthHeader": "#383838",
"MonthPrimary": "#1F1F1F",
"MonthSecondary": "#272727",
"MonthGrid": "#676767",
"MonthDayFore": "LightGray",
"MonthDayBack": "#383838",
"MonthTodayFore": "LightGray",
"MonthTodayBack": "#73356E",
"DetailOddBack": "#1F1F1F",
"DetailEvenBack": "#272727"
}
}
29 changes: 29 additions & 0 deletions OneMoreCalendar/Assets/LightTheme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"DarkMode": false,
"Colors": {
"BackColor": "White",
"ForeColor": "Black",
"Border": "#D2A1DF",
"Control": "#73356E",
"Highlight": "#BC58B6",
"ButtonBack": "#F7EDF7",
"ButtonFore": "#73356E",
"ButtonDisabled": "Gray",
"ButtonBorder": "#F0DAEE",
"ButtonHotBack": "#F0DAEE",
"ButtonHotBorder": "#9E5499",
"ButtonPressBorder": "#9E5499",
"LinkColor": "#73356E",
"HoverColor": "MediumOrchid",
"MonthHeader": "Control",
"MonthPrimary": "White",
"MonthSecondary": "WhiteSmoke",
"MonthGrid": "DarkGray",
"MonthDayFore": "Gray",
"MonthDayBack": "#F4E8F3",
"MonthTodayFore": "Black",
"MonthTodayBack": "#D6A6D3",
"DetailOddBack": "#FDFAFE",
"DetailEvenBack": "White"
}
}
6 changes: 5 additions & 1 deletion OneMoreCalendar/CalendarForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public override void OnThemeChange()
prevButton.PreferredFore = Theme.LinkColor;
prevButton.PreferredBack = Theme.BackColor;
todayButton.PreferredBack = Theme.BackColor;

if (contentPanel.Controls.Contains(monthView))
{
detailView.OnThemeChange();
}
}


Expand Down Expand Up @@ -191,7 +196,6 @@ await settings.GetNotebookIDs(),
settings.Created, settings.Modified, settings.Deleted);

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

contentPanel.Controls.Add(detailView);
}
Expand Down
119 changes: 72 additions & 47 deletions OneMoreCalendar/DetailView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public DetailView()
public override void OnThemeChange()
{
BackColor = Theme.BackColor;
listbox.BackColor = BackColor;
}


Expand Down Expand Up @@ -85,11 +86,14 @@ public void SetRange(DateTime startDate, DateTime endDate, CalendarPages pages)

if (daypages.Any() || settings.Empty)
{
listbox.Items.Add(new DayItem
var item = new ListViewItem();
item.Tag = new DayItem
{
Date = date,
Pages = daypages
});
};

listbox.Items.Add(item);
}

date = date.AddDays(1);
Expand All @@ -102,6 +106,8 @@ public void SetRange(DateTime startDate, DateTime endDate, CalendarPages pages)

private void HeaderPanelPaint(object sender, PaintEventArgs e)
{
e.Graphics.Clear(BackColor);

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

private void ListBoxMeasureItem(object sender, MeasureItemEventArgs e)
{
if (listbox.Items[e.Index] is DayItem day)
if (listbox.Items[e.Index] is ListViewItem item && item.Tag is DayItem day)
{
e.ItemHeight = day.Pages.Count > 1
? (day.Pages.Count * listbox.Font.Height) + (VPadding * 3)
Expand Down Expand Up @@ -151,7 +157,7 @@ private void ListBoxDrawItem(object sender, DrawItemEventArgs e)
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)
if (listbox.Items[e.Index] is ListViewItem item && item.Tag is DayItem day)
{
// set every time to handle scrolled view
day.Bounds = e.Bounds;
Expand All @@ -170,7 +176,7 @@ private void ListBoxDrawItem(object sender, DrawItemEventArgs e)
// pages
var top = e.Bounds.Top + VPadding;
foreach (var page in day.Pages)
{
{
// predict width of page title
size = e.Graphics.MeasureString(page.Title, listbox.Font);

Expand Down Expand Up @@ -228,39 +234,51 @@ private void ListBoxKeyDown(object sender, KeyEventArgs e)

private void ListBoxMouseMove(object sender, MouseEventArgs e)
{
var day = listbox.Items.OfType<DayItem>()
.FirstOrDefault(d => d.Bounds.Contains(e.Location));
//Logger.Current.WriteLine($"moveto {e.Location}");

CalendarPage page = null;
if (day != null)
if (listbox.Items.OfType<ListViewItem>()
.FirstOrDefault(d =>
listbox.GetItemRectangle(listbox.Items.IndexOf(d)).Contains(e.Location))?
.Tag is not DayItem day)
{
page = day.Pages.FirstOrDefault(p => p.Bounds.Contains(e.Location));
return;
}

//Logger.Current.WriteLine($"day bounds {day.Bounds}");

var page = day.Pages.FirstOrDefault(p => p.Bounds.Contains(e.Location));

//Logger.Current.WriteLine($"page bounds {page.Bounds}");

if (page == hotpage)
{
if (hotpage != null)
{
Native.SetCursor(hand);
}

return;
}

using var g = listbox.CreateGraphics();
int index;

if (hotpage != null)
{
using (var g = listbox.CreateGraphics())
{
var index = listbox.Items.IndexOf(hotday);
using var fill = new SolidBrush(index % 2 == 1 ? Theme.DetailOddBack : Theme.DetailEvenBack);
g.FillRectangle(fill, hotpage.Bounds);
index = listbox.Items.OfType<ListViewItem>()
.Where(item => item.Tag == hotday)
.Select(item => listbox.Items.IndexOf(item))
.FirstOrDefault();

using var fore = new SolidBrush(hotpage.IsDeleted ? Color.Gray : Theme.ForeColor);
using var fill = new SolidBrush(index % 2 == 1 ? Theme.DetailOddBack : Theme.DetailEvenBack);
g.FillRectangle(fill, hotpage.Bounds);

g.DrawString(hotpage.Title,
hotpage.IsDeleted ? deletedFont : listbox.Font,
fore,
hotpage.Bounds, format);
}
using var fore = new SolidBrush(hotpage.IsDeleted ? Color.Gray : Theme.ForeColor);

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

HoverPage?.Invoke(this, new CalendarPageEventArgs(null));

Expand All @@ -270,17 +288,18 @@ private void ListBoxMouseMove(object sender, MouseEventArgs e)

if (page != null)
{
using (var g = listbox.CreateGraphics())
{
var index = listbox.Items.IndexOf(day);
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,
fore, page.Bounds, format);
}
index = listbox.Items.OfType<ListViewItem>()
.Where(item => item.Tag == day)
.Select(item => listbox.Items.IndexOf(item))
.FirstOrDefault();

using var fill2 = new SolidBrush(index % 2 == 1 ? Theme.DetailOddBack : Theme.DetailEvenBack);
g.FillRectangle(fill2, page.Bounds);

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

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

Expand All @@ -290,6 +309,7 @@ private void ListBoxMouseMove(object sender, MouseEventArgs e)
}
}


private void ListBoxResize(object sender, EventArgs e)
{
headerPanel.Invalidate();
Expand All @@ -305,26 +325,31 @@ private void ListBoxResize(object sender, EventArgs e)
*/
private void ListBoxMouseUp(object sender, MouseEventArgs e)
{
var day = listbox.Items.OfType<DayItem>()
.FirstOrDefault(d => d.Bounds.Contains(e.Location));
if (listbox.Items.OfType<ListViewItem>()
.FirstOrDefault(d =>
listbox.GetItemRectangle(listbox.Items.IndexOf(d)).Contains(e.Location))?
.Tag is not DayItem day)
{
return;
}

if (day != null)
var page = day.Pages.FirstOrDefault(p => p.Bounds.Contains(e.Location));
if (page == null)
{
var page = day.Pages.FirstOrDefault(p => p.Bounds.Contains(e.Location));
if (page != null)
{
if (e.Button == MouseButtons.Right)
{
SnappedPage?.Invoke(this, new CalendarSnapshotEventArgs(page, page.Bounds));
}
else
{
ClickedPage?.Invoke(this, new CalendarPageEventArgs(page));
}
}
return;
}

if (e.Button == MouseButtons.Right)
{
SnappedPage?.Invoke(this, new CalendarSnapshotEventArgs(page, page.Bounds));
}
else
{
ClickedPage?.Invoke(this, new CalendarPageEventArgs(page));
}
}


private void ListBoxScrolled(object sender, ScrollEventArgs e)
{
listbox.Invalidate();
Expand Down
10 changes: 9 additions & 1 deletion OneMoreCalendar/OneMoreCalendar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<Compile Include="DetailView.Designer.cs">
<DependentUpon>DetailView.cs</DependentUpon>
</Compile>
<Compile Include="Things\Theme.cs" />
<Compile Include="Things\ThemeMode.cs" />
<Compile Include="Things\BitmapExtensions.cs" />
<Compile Include="Things\DateTimeExtensions.cs" />
<Compile Include="Things\GraphicsExtensions.cs" />
Expand Down Expand Up @@ -126,6 +126,7 @@
<Compile Include="Things\ThemedUserControl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Things\ThemeProvider.cs" />
<Compile Include="YearsForm.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -163,6 +164,8 @@
<EmbeddedResource Include="YearsForm.resx">
<DependentUpon>YearsForm.cs</DependentUpon>
</EmbeddedResource>
<None Include="Assets\DarkTheme.json" />
<None Include="Assets\LightTheme.json" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down Expand Up @@ -192,6 +195,11 @@
<Content Include="Assets\today-32.png" />
<Content Include="Logo.ico" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.1</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>taskkill /fi "pid gt 0" /im OneMoreCalendar.exe</PreBuildEvent>
Expand Down
Loading

0 comments on commit 68f8443

Please sign in to comment.