Skip to content

[Gallery] Colorcoding for code snippets #103

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

Merged
merged 7 commits into from
Aug 30, 2023
Merged

Conversation

niels9001
Copy link
Collaborator

@niels9001 niels9001 commented Jul 18, 2023

Addressing: #104

WASM doesn't support RichTextBlock, so we're falling back on a regular TextBlock there.

UWP/WASDK:
ColorCodeCode

WASM:
image

@niels9001 niels9001 changed the title Niels9001/colorcode [Gallery] Code colorcoding Jul 18, 2023
@@ -9,8 +9,10 @@
xmlns:renderer="using:CommunityToolkit.App.Shared.Renderers"
xmlns:wasm="http://uno.ui/wasm"
xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:xamarin="http://uno.ui/xamarin"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Arlodotexe @michael-hawker I got this using from the Uno.CommunityToolkit sample app repo.. and it works, but not sure if this is the right one :-)?

Copy link
Member

Choose a reason for hiding this comment

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

@Arlodotexe thoughts on this bit?

Copy link
Member

Choose a reason for hiding this comment

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

Not sure if they'll be keeping xamarin long term, if we're keeping this we should use not_win instead.

Though I think this becomes extra if we create the composed (not inherited) markdown textblock, since we can use our C# compilation conditionals.

@niels9001 niels9001 marked this pull request as ready for review July 18, 2023 13:47
@niels9001 niels9001 linked an issue Jul 18, 2023 that may be closed by this pull request
@niels9001 niels9001 changed the title [Gallery] Code colorcoding [Gallery] Colorcoding for code snippets Jul 18, 2023
Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Bind CSharpCode, Mode=OneWay}" />
<StackPanel Orientation="Vertical">
<xamarin:TextBlock x:Name="CSharpCodeRenderer"
Copy link
Member

Choose a reason for hiding this comment

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

As an add-on to this, we could take the same approach I did for the MarkdownTextBlock in the sample app, and create a wrapper around TextBlock, but on WASM we call the ColorCode HTML generator and then inject that HTML into the control...

Copy link
Member

Choose a reason for hiding this comment

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

Actually you could just encapsulate all this XAML stuff and the code into the control, like the MarkdownTextBlock helper does: https://github.com/CommunityToolkit/Tooling-Windows-Submodule/blob/main/CommunityToolkit.App.Shared/Renderers/Markdown/MarkdownTextBlock.cs

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@michael-hawker I was thinking, for UWP/WinUI I'd base the CodeRenderer on RichTextBlock, right? But that would be sealed?

image

Copy link
Member

Choose a reason for hiding this comment

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

Ugh, forgot about that (and thus why sealing UI controls is generally annoying...) - Linking to microsoft/microsoft-ui-xaml#780 as usual...

I guess for the native platform you could have a ContentPresenter or something and stick in a RTB, or create a local UserControl or something that just wraps a RTB within it? Have it expose a Text property?

Copy link
Member

Choose a reason for hiding this comment

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

Was thinking maybe we can just use composition instead of inheritance, i.e. wrap everything in just a Control, and that control can setup it's content based on platform, on WinUI2/3 it sets it as a RTB and uses ColorCode directly, for WASM it sets it to a TextBlock or whatever but replaces the HTML content with the ColorCode output, and then on other Uno targets it just uses a TextBlock with the raw text? The control can just expose a general Text property that can be passed in the Markdown from the ToolkitSampleRenderer, so then the renderer doesn't care about the platform.

@niels9001 what did you want to do here? Should we just commit this as-is for now or did you want to take a stab at the above?

@michael-hawker
Copy link
Member

Talked to @niels9001, since the control will be harder to build than we thought with RTB being sealed, we'll just merge this working approach in as-is for now and revisit later.

I'm updating this with main and will re-test

@Arlodotexe
Copy link
Member

Arlodotexe commented Aug 30, 2023

Talked to @niels9001, since the control will be harder to build than we thought with RTB being sealed, we'll just merge this working approach in as-is for now and revisit later.

I'm updating this with main and will re-test

@michael-hawker Think that was why we decided on using composition instead of inheritance a few weeks ago (see your comment here).

@michael-hawker
Copy link
Member

michael-hawker commented Aug 30, 2023

Oops, rebased on top of #131 as I was testing... needs that merged first

@michael-hawker michael-hawker enabled auto-merge (squash) August 30, 2023 20:50
@michael-hawker michael-hawker merged commit 86db77d into main Aug 30, 2023
@delete-merged-branch delete-merged-branch bot deleted the niels9001/colorcode branch August 30, 2023 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Gallery] Add colorcoding to XAML/C# snippets
3 participants