Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add theme-independent clock format customization #754

Closed

Conversation

thisismy-github
Copy link

@thisismy-github thisismy-github commented Feb 17, 2024

clockformattab_demo2_cropped.mp4

Fixes #217, #300, #477, #671, #726
Partially fixes #110, #445, #508

Changes

  • Adds a new Clock tab to the settings dialog:
    • Set custom clock formatting
      • Split clock into multiple lines using \n
    • Set custom AM/PM designators

This works by simply overriding CultureInfo.DateTimeFormat's ShortTimePattern, AMDesignator, and PMDesignator properties in Clock.SetCurrentCulture() with our custom values. Editing any of the formatting settings (or changing the theme, to fix an unusual bug) resets the culture, so your changes are reflected in real time.

Also, I turned the "Notification area" preview into a ControlTemplate and moved it into the resource dictionary (using the key "NotificationAreaPreview") so I could reuse it. I don't know if this is how you're supposed to do it.

Minor issues

  • I didn't bother adding support for escaping \n so the literal sequence "\n" cannot appear on the clock (unless you put it in the designators). I apologize for the thousands of issues that will surely be opened regarding this.
  • Leaving the format/designators blank will have them fallback to their normal values, to prevent confusion. Having only whitespace as your format/designator is still accepted however, which itself might cause confusion, but it can be used as makeshift padding so I left it as is.
  • Ending the clock format with a single backlash causes the entire clock to become blank. Fixing this "properly" means counting the number of trailing backslashes to see if there's an odd or even number so you know whether or not to remove the last one, so I just... didn't.

Irrelevant notes

  • I prototyped a setting for optionally overriding even a themed clock's baked-in format, but I ultimately decided against it.
  • I chose h:mm:ss tt | ddd, MMM d, yyyy and a.m./p.m. as the default format and designators to make it clear to the user how far they can take the formatting before they actually read the text at the bottom. I didn't include \n however, as multi-line clocks don't look good on themes with harsh gradients or limited clock space (like the default theme).
  • The "What the notations mean" text is derived from the official Windows dialogs.
    • I defined all of that text as a single line. Sorry for making Languages/English.xaml really, really wide.
  • The Show the clock checkbox logically fits on both tabs, but I didn't want to disturb the nostalgic sanctity of its original placement, so I duplicated it. Let me know if that's okay.
  • I spent an excessive amount of time deciding on aesthetics/presentation, and I only settled on adding a new tab for clarity and aesthetics. I hope what I ended up with is acceptable. I think if any additional clock settings are added, the layout should probably be rearranged - I went for something like this at first but it felt too claustrophobic with the limited number of settings (just look at that groupbox-less preview clock, it's basically naked).
  • XAML is the worst thing that's ever happened to anyone ever

Also, moved the "Notification area" `ContentControl` and its `Border`
into the resource dictionary as a `ControlTemplate` (using the key
`"NotificationAreaPreview"`) so it can be reused.
@thisismy-github
Copy link
Author

thisismy-github commented Feb 17, 2024

I just realized, to my indescribable disappointment, that I accidentally deleted the new Show the keyboard layout controls. This happened because that pull request happened while I was working, so I lazily merged the files by hand and somehow forgot the most important, obvious file of all.

If there are any other changes I need to make, I will restore the controls along with those changes as a single commit. Otherwise, I'll restore the controls as their own commit.


Another disaster: I mentioned "an unusual bug" that's fixed by resetting the culture when changing themes - the bug was that the Clock tab's preview clock (and ONLY that one) resets its formatting after changing themes until you switch tabs back and forth or edit any of the clock settings. Miraculously, the bug has returned. I have confirmed that the culture is being properly reset, so I have no leads. Maybe resetting the culture on a short delay after changing themes, but I don't know how to properly do that in C#, so I will pursue this no further.


Edit: Another thing I only just noticed - I mixed up some of the semicolons and commas in the "What the notations mean" text. I'll fix that as well pending a review.

@dremin
Copy link
Owner

dremin commented Feb 22, 2024

Thanks for working on this! I'll be taking a closer look after I get the latest release wrapped up.

One thought that came to mind is that this should probably always override the theme clock format (when enabled), since otherwise it would be very inconsistent for vertical taskbars, which most themes set a clock format for.

Copy link
Owner

@dremin dremin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the delay! This will need merge conflicts resolved before merging, and I also left some additional comments.

}
break;

case "Theme":
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Theme need to be here? I don't believe it will influence SetCurrentCulture, and it doesn't seem to fix the odd Properties preview bug you mentioned in your comment.

@@ -57,6 +58,14 @@
<s:String x:Key="debug_logging">Enable debug logging</s:String>
<s:String x:Key="ok_dialog">OK</s:String>

<s:String x:Key="clock_appearance">Clock appearance</s:String>
<s:String x:Key="clock_format_info" xml:space="preserve">What the notations mean:&#10;&#10;h = hour; m = minute, s = second, tt = AM/PM&#10;d = day; M = month; yy, yyyy = year&#10;ddd, dddd = weekday; MMM, MMMM = month name&#10;&#10;h/H = 12/24 hour&#10;hh, mm, ss, dd, MM = display leading zero&#10;h, m, s, d, M = do not display leading zero&#10;&#10;\n = split clock into multiple lines&#10;(not recommended on all themes)&#10;&#10;Use "\" in front of other notations to use their actual characters</s:String>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit gnarly to localize. Given that we are using standard format specifiers, what are your thoughts regarding instead providing a link to this table which also includes examples and descriptions of all specifiers?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They probably wanted to copy the design from these intl.cpl dialogs (which, interestingly, also store the text as one big string with \n\ns in between):

изображение
изображение

@@ -57,6 +58,14 @@
<s:String x:Key="debug_logging">Enable debug logging</s:String>
<s:String x:Key="ok_dialog">OK</s:String>

<s:String x:Key="clock_appearance">Clock appearance</s:String>
<s:String x:Key="clock_format_info" xml:space="preserve">What the notations mean:&#10;&#10;h = hour; m = minute, s = second, tt = AM/PM&#10;d = day; M = month; yy, yyyy = year&#10;ddd, dddd = weekday; MMM, MMMM = month name&#10;&#10;h/H = 12/24 hour&#10;hh, mm, ss, dd, MM = display leading zero&#10;h, m, s, d, M = do not display leading zero&#10;&#10;\n = split clock into multiple lines&#10;(not recommended on all themes)&#10;&#10;Use "\" in front of other notations to use their actual characters</s:String>
<s:String x:Key="clock_format_warning" xml:space="preserve">Note: Custom clock formatting may not be applied&#10;if your selected theme specifies its own format.</s:String>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of putting a manual break in here, we can add padding/margin to the TextBlock to limit its width.

<GroupBox Header="{DynamicResource clock_appearance}"
Margin="0,0,0,10">
<StackPanel Orientation="Vertical">
<ContentControl Template="{StaticResource NotificationAreaPreview}"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug with the preview seems to happen because the clock control has no children at the time the Loaded event fires, so the ConverterCulture doesn't get set. I'm not sure why it is happening in this specific case.

IMO this should be fixed before the changes can be merged. There is an alternative, we could remove the extra preview, but that would make the Clock tab a bit sparse. Together with replacing the explanatory string with a link, the clock format section could fit on the Advanced tab instead.

@l0oo
Copy link

l0oo commented Oct 4, 2024

Hello!
Thanks for great feature! :) Could we ask for custom clock font and its size? :)

SeventySev3n added a commit to SeventySev3n/RetroBar that referenced this pull request Oct 5, 2024
@windowsxpforlife
Copy link

this needs to be added

@windowsxpforlife
Copy link

wait what did do

@1280px
Copy link
Contributor

1280px commented Jan 4, 2025

Any progress on this PR status?

@dremin
Copy link
Owner

dremin commented Jan 8, 2025

Any progress on this PR status?

The review comments are not addressed. I may need to make the changes.

@xoascf

This comment was marked as off-topic.

@dremin
Copy link
Owner

dremin commented Feb 14, 2025

I've decided to close this without merging for a few reasons:

  • It needs a non-negligible amount of work to be merge-able but the author has stopped responding
  • I have a PR coming that will add an option to display seconds, which is the common request. Custom themes can still use custom formats.
  • If the author is interested in finishing it, we can always re-open, and the above item won't prevent that!

@dremin dremin closed this Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an option to show seconds in task bar T-Clock not working
6 participants