Skip to content

Commit 26bab84

Browse files
author
Marcus Markiewicz
committed
feat: refactor hover window configuration and update logic
- Updated hover window size calculations to use a default width from configuration. - Removed unused properties related to hover window dimensions from ConfigModel. - Simplified UpdateMeeting method by removing max title width parameter. - Adjusted hover window update calls throughout the application to reflect changes in method signature and configuration.
1 parent cf7c47f commit 26bab84

File tree

4 files changed

+25
-103
lines changed

4 files changed

+25
-103
lines changed

src/ComingUpNextTray/HoverWindow.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public HoverWindow()
3737
Font = new Font(FontFamily.GenericSansSerif, 10f, FontStyle.Bold, GraphicsUnit.Point),
3838
Location = new Point(8, 8),
3939

40-
// Let layout compute width; we'll cap in UpdateMeeting to avoid overly wide windows.
41-
Size = new Size(204, 18),
40+
// Let layout compute width; default to the configured hover window width.
41+
Size = new Size(UiLayout.DefaultHoverWindowWidth - (this.Padding.Horizontal + 8), 18),
4242
};
4343

4444
this.timeLabel = new Label
@@ -73,9 +73,8 @@ public HoverWindow()
7373
/// <param name="now">Reference time for formatting.</param>
7474
/// <param name="overlayToken">Optional overlay token (e.g. "5" or "1h" or "5 min") to display after the title as "(In X)".</param>
7575
/// <param name="fetchError">Optional fetch error message to display instead of meeting information.</param>
76-
/// <param name="maxTitleWidthPx">Optional override max title width in pixels for truncation. If null uses <see cref="UiLayout.DefaultMaxTextWidth"/>.</param>
7776
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA1303:Do not pass literals as localized parameters", Justification = "Using centralized UiText constants; localization pending.")]
78-
public void UpdateMeeting(CalendarEntry? meeting, DateTime now, string? overlayToken = null, string? fetchError = null, int? maxTitleWidthPx = null)
77+
public void UpdateMeeting(CalendarEntry? meeting, DateTime now, string? overlayToken = null, string? fetchError = null)
7978
{
8079
// If an error occurred during fetch, display the error prominently instead of meeting info.
8180
if (!string.IsNullOrEmpty(fetchError))
@@ -118,10 +117,10 @@ public void UpdateMeeting(CalendarEntry? meeting, DateTime now, string? overlayT
118117
this.titleLabel.Text = title;
119118
}
120119

121-
// Truncate title to fit within reasonable width to avoid overly wide hover window.
122-
// If an overlay token is present, reserve space for the suffix (e.g. " (in 5 min)") so it is not lost.
123-
int defaultMax = UiLayout.DefaultMaxTextWidth;
124-
int maxInnerWidth = (maxTitleWidthPx ?? defaultMax) - this.Padding.Horizontal - 8; // leave some margin
120+
// Truncate title to fit within the configured hover window width.
121+
// Compute inner available width (account for padding and small margin).
122+
int formWidth = UiLayout.DefaultHoverWindowWidth;
123+
int maxInnerWidth = formWidth - this.Padding.Horizontal - 8; // leave some margin
125124

126125
string suffix = string.Empty;
127126
if (!string.IsNullOrEmpty(overlayToken)
@@ -146,6 +145,9 @@ public void UpdateMeeting(CalendarEntry? meeting, DateTime now, string? overlayT
146145

147146
this.titleLabel.Text = string.Concat(truncatedBase, suffix);
148147

148+
// Ensure titleLabel fills the inner width so ellipsis/AutoEllipsis layout works predictably.
149+
this.titleLabel.Size = new Size(maxInnerWidth, this.titleLabel.Height);
150+
149151
// Apply ellipsis behavior on the label control; UiTruncation already appends '...' when truncating the base title.
150152
this.titleLabel.AutoEllipsis = true;
151153

@@ -154,10 +156,10 @@ public void UpdateMeeting(CalendarEntry? meeting, DateTime now, string? overlayT
154156
this.timeLabel.Text = meeting.StartTime.ToString(timeFormat, CultureInfo.CurrentCulture);
155157
}
156158

157-
// Resize to fit
159+
// Resize to fit, but never exceed the configured hover window default width.
158160
int width = Math.Max(this.titleLabel.Width, this.timeLabel.Width) + this.Padding.Horizontal + 8;
159161
int height = this.timeLabel.Bottom + this.Padding.Bottom + 8;
160-
this.Size = new Size(Math.Min(width, UiLayout.DefaultMaxTextWidth), height);
162+
this.Size = new Size(Math.Min(width, UiLayout.DefaultHoverWindowWidth), height);
161163
}
162164

163165
/// <summary>

src/ComingUpNextTray/Models/ConfigModel.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,5 @@ internal sealed class ConfigModel
2828

2929
/// <summary>Gets or sets saved top coordinate of hover window (screen coordinates).</summary>
3030
public int? HoverWindowTop { get; set; }
31-
32-
/// <summary>Gets or sets saved width of hover window in pixels.</summary>
33-
public int? HoverWindowWidth { get; set; }
34-
35-
/// <summary>Gets or sets saved height of hover window in pixels.</summary>
36-
public int? HoverWindowHeight { get; set; }
37-
38-
/// <summary>Gets or sets maximum hover title width in pixels for truncation (optional).</summary>
39-
public int? MaxHoverTitleWidth { get; set; }
40-
41-
/// <summary>Gets or sets maximum menu text width in pixels for truncation (optional).</summary>
42-
public int? MaxMenuTextWidth { get; set; }
4331
}
4432
}

src/ComingUpNextTray/TrayApplication.cs

Lines changed: 6 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ internal sealed class TrayApplication : IDisposable
2626
private string? _lastFetchError;
2727
private int? _hoverWindowLeft;
2828
private int? _hoverWindowTop;
29-
private int? _hoverWindowWidth;
30-
private int? _hoverWindowHeight;
31-
private int? _maxHoverTitleWidth;
32-
private int? _maxMenuTextWidth;
3329

3430
// Overlay is now always enabled; legacy flag retained only for backward compatible config file reads.
3531

@@ -384,7 +380,7 @@ internal void SetCalendarUrl(string? url)
384380
this._calendarUrl = string.IsNullOrWhiteSpace(url) ? string.Empty : url.Trim();
385381

386382
// Save full config to preserve other values
387-
this.SaveConfig(new ConfigModel { CalendarUrl = this._calendarUrl, RefreshMinutes = this._refreshMinutes, ShowHoverWindow = this._showHoverWindow, IgnoreFreeOrFollowing = this._ignoreFreeOrFollowing, HoverWindowLeft = this._hoverWindowLeft, HoverWindowTop = this._hoverWindowTop, HoverWindowWidth = this._hoverWindowWidth, HoverWindowHeight = this._hoverWindowHeight, MaxHoverTitleWidth = this._maxHoverTitleWidth, MaxMenuTextWidth = this._maxMenuTextWidth });
383+
this.SaveConfig(new ConfigModel { CalendarUrl = this._calendarUrl, RefreshMinutes = this._refreshMinutes, ShowHoverWindow = this._showHoverWindow, IgnoreFreeOrFollowing = this._ignoreFreeOrFollowing, HoverWindowLeft = this._hoverWindowLeft, HoverWindowTop = this._hoverWindowTop });
388384
}
389385

390386
/// <summary>Sets refresh interval minutes and persists config.</summary>
@@ -397,7 +393,7 @@ internal void SetRefreshMinutes(int minutes)
397393
}
398394

399395
this._refreshMinutes = minutes;
400-
this.SaveConfig(new ConfigModel { CalendarUrl = this._calendarUrl, RefreshMinutes = this._refreshMinutes, ShowHoverWindow = this._showHoverWindow, IgnoreFreeOrFollowing = this._ignoreFreeOrFollowing, HoverWindowLeft = this._hoverWindowLeft, HoverWindowTop = this._hoverWindowTop, HoverWindowWidth = this._hoverWindowWidth, HoverWindowHeight = this._hoverWindowHeight, MaxHoverTitleWidth = this._maxHoverTitleWidth, MaxMenuTextWidth = this._maxMenuTextWidth });
396+
this.SaveConfig(new ConfigModel { CalendarUrl = this._calendarUrl, RefreshMinutes = this._refreshMinutes, ShowHoverWindow = this._showHoverWindow, IgnoreFreeOrFollowing = this._ignoreFreeOrFollowing, HoverWindowLeft = this._hoverWindowLeft, HoverWindowTop = this._hoverWindowTop });
401397
}
402398

403399
/// <summary>Gets whether to show the hover window.</summary>
@@ -409,7 +405,7 @@ internal void SetRefreshMinutes(int minutes)
409405
internal void SetShowHoverWindow(bool v)
410406
{
411407
this._showHoverWindow = v;
412-
this.SaveConfig(new ConfigModel { CalendarUrl = this._calendarUrl, RefreshMinutes = this._refreshMinutes, ShowHoverWindow = this._showHoverWindow, IgnoreFreeOrFollowing = this._ignoreFreeOrFollowing, HoverWindowLeft = this._hoverWindowLeft, HoverWindowTop = this._hoverWindowTop, HoverWindowWidth = this._hoverWindowWidth, HoverWindowHeight = this._hoverWindowHeight, MaxHoverTitleWidth = this._maxHoverTitleWidth, MaxMenuTextWidth = this._maxMenuTextWidth });
408+
this.SaveConfig(new ConfigModel { CalendarUrl = this._calendarUrl, RefreshMinutes = this._refreshMinutes, ShowHoverWindow = this._showHoverWindow, IgnoreFreeOrFollowing = this._ignoreFreeOrFollowing, HoverWindowLeft = this._hoverWindowLeft, HoverWindowTop = this._hoverWindowTop });
413409
}
414410

415411
/// <summary>
@@ -424,37 +420,7 @@ internal void SetShowHoverWindow(bool v)
424420
/// <returns>Top coordinate in screen pixels, or null if not set.</returns>
425421
internal int? GetHoverWindowTopForUi() => this._hoverWindowTop;
426422

427-
/// <summary>Gets saved hover window width in pixels.</summary>
428-
/// <returns>Width in pixels or null.</returns>
429-
internal int? GetHoverWindowWidthForUi() => this._hoverWindowWidth;
430-
431-
/// <summary>Gets saved hover window height in pixels.</summary>
432-
/// <returns>Height in pixels or null.</returns>
433-
internal int? GetHoverWindowHeightForUi() => this._hoverWindowHeight;
434-
435-
/// <summary>Gets configured maximum hover title width in pixels for truncation purposes.</summary>
436-
/// <returns>Max hover title width in pixels or null to use default.</returns>
437-
internal int? GetHoverTitleMaxWidthForUi() => this._maxHoverTitleWidth;
438-
439-
/// <summary>Sets configured maximum hover title width in pixels and persists config.</summary>
440-
/// <param name="pixels">Width in pixels or null to clear.</param>
441-
internal void SetHoverTitleMaxWidth(int? pixels)
442-
{
443-
this._maxHoverTitleWidth = pixels;
444-
this.SaveConfig(new ConfigModel { CalendarUrl = this._calendarUrl, RefreshMinutes = this._refreshMinutes, ShowHoverWindow = this._showHoverWindow, IgnoreFreeOrFollowing = this._ignoreFreeOrFollowing, HoverWindowLeft = this._hoverWindowLeft, HoverWindowTop = this._hoverWindowTop, HoverWindowWidth = this._hoverWindowWidth, HoverWindowHeight = this._hoverWindowHeight, MaxHoverTitleWidth = this._maxHoverTitleWidth, MaxMenuTextWidth = this._maxMenuTextWidth });
445-
}
446-
447-
/// <summary>Gets configured maximum menu text width in pixels for truncation purposes.</summary>
448-
/// <returns>Max menu text width in pixels or null to use default.</returns>
449-
internal int? GetMenuTextMaxWidthForUi() => this._maxMenuTextWidth;
450-
451-
/// <summary>Sets configured maximum menu text width in pixels and persists config.</summary>
452-
/// <param name="pixels">Width in pixels or null to clear.</param>
453-
internal void SetMenuTextMaxWidth(int? pixels)
454-
{
455-
this._maxMenuTextWidth = pixels;
456-
this.SaveConfig(new ConfigModel { CalendarUrl = this._calendarUrl, RefreshMinutes = this._refreshMinutes, ShowHoverWindow = this._showHoverWindow, IgnoreFreeOrFollowing = this._ignoreFreeOrFollowing, HoverWindowLeft = this._hoverWindowLeft, HoverWindowTop = this._hoverWindowTop, HoverWindowWidth = this._hoverWindowWidth, HoverWindowHeight = this._hoverWindowHeight, MaxHoverTitleWidth = this._maxHoverTitleWidth, MaxMenuTextWidth = this._maxMenuTextWidth });
457-
}
423+
// Hover window size getters removed; sizes are not persisted.
458424

459425
/// <summary>
460426
/// Sets hover window position and persists config.
@@ -465,17 +431,7 @@ internal void SetHoverWindowPosition(int? left, int? top)
465431
{
466432
this._hoverWindowLeft = left;
467433
this._hoverWindowTop = top;
468-
this.SaveConfig(new ConfigModel { CalendarUrl = this._calendarUrl, RefreshMinutes = this._refreshMinutes, ShowHoverWindow = this._showHoverWindow, IgnoreFreeOrFollowing = this._ignoreFreeOrFollowing, HoverWindowLeft = this._hoverWindowLeft, HoverWindowTop = this._hoverWindowTop, HoverWindowWidth = this._hoverWindowWidth, HoverWindowHeight = this._hoverWindowHeight, MaxHoverTitleWidth = this._maxHoverTitleWidth, MaxMenuTextWidth = this._maxMenuTextWidth });
469-
}
470-
471-
/// <summary>Sets hover window size and persists config.</summary>
472-
/// <param name="width">Width in pixels, or null to clear.</param>
473-
/// <param name="height">Height in pixels, or null to clear.</param>
474-
internal void SetHoverWindowSize(int? width, int? height)
475-
{
476-
this._hoverWindowWidth = width;
477-
this._hoverWindowHeight = height;
478-
this.SaveConfig(new ConfigModel { CalendarUrl = this._calendarUrl, RefreshMinutes = this._refreshMinutes, ShowHoverWindow = this._showHoverWindow, IgnoreFreeOrFollowing = this._ignoreFreeOrFollowing, HoverWindowLeft = this._hoverWindowLeft, HoverWindowTop = this._hoverWindowTop, HoverWindowWidth = this._hoverWindowWidth, HoverWindowHeight = this._hoverWindowHeight, MaxHoverTitleWidth = this._maxHoverTitleWidth, MaxMenuTextWidth = this._maxMenuTextWidth });
434+
this.SaveConfig(new ConfigModel { CalendarUrl = this._calendarUrl, RefreshMinutes = this._refreshMinutes, ShowHoverWindow = this._showHoverWindow, IgnoreFreeOrFollowing = this._ignoreFreeOrFollowing, HoverWindowLeft = this._hoverWindowLeft, HoverWindowTop = this._hoverWindowTop });
479435
}
480436

481437
/// <summary>Gets whether free/following meetings are ignored.</summary>
@@ -487,7 +443,7 @@ internal void SetHoverWindowSize(int? width, int? height)
487443
internal void SetIgnoreFreeOrFollowing(bool v)
488444
{
489445
this._ignoreFreeOrFollowing = v;
490-
this.SaveConfig(new ConfigModel { CalendarUrl = this._calendarUrl, RefreshMinutes = this._refreshMinutes, ShowHoverWindow = this._showHoverWindow, IgnoreFreeOrFollowing = this._ignoreFreeOrFollowing, HoverWindowLeft = this._hoverWindowLeft, HoverWindowTop = this._hoverWindowTop, HoverWindowWidth = this._hoverWindowWidth, HoverWindowHeight = this._hoverWindowHeight, MaxHoverTitleWidth = this._maxHoverTitleWidth, MaxMenuTextWidth = this._maxMenuTextWidth });
446+
this.SaveConfig(new ConfigModel { CalendarUrl = this._calendarUrl, RefreshMinutes = this._refreshMinutes, ShowHoverWindow = this._showHoverWindow, IgnoreFreeOrFollowing = this._ignoreFreeOrFollowing, HoverWindowLeft = this._hoverWindowLeft, HoverWindowTop = this._hoverWindowTop });
491447
}
492448

493449
/// <summary>
@@ -564,26 +520,6 @@ private void LoadConfig()
564520
{
565521
this._hoverWindowTop = ht;
566522
}
567-
568-
if (cfg.HoverWindowWidth is int ww)
569-
{
570-
this._hoverWindowWidth = ww;
571-
}
572-
573-
if (cfg.MaxHoverTitleWidth is int mhw)
574-
{
575-
this._maxHoverTitleWidth = mhw;
576-
}
577-
578-
if (cfg.MaxMenuTextWidth is int mmw)
579-
{
580-
this._maxMenuTextWidth = mmw;
581-
}
582-
583-
if (cfg.HoverWindowHeight is int wh)
584-
{
585-
this._hoverWindowHeight = wh;
586-
}
587523
}
588524
}
589525
catch (JsonException)
@@ -608,7 +544,5 @@ private void LoadConfig()
608544
this._configErrorDetected = true;
609545
}
610546
}
611-
612-
// Removed legacy MaybeShowBalloon method.
613547
}
614548
}

0 commit comments

Comments
 (0)