Skip to content

Commit ba43326

Browse files
committed
Merge branch 'marquee/pausing' of https://github.com/Avid29/Labs-Windows into marquee/pausing
2 parents 61ca149 + f847934 commit ba43326

File tree

16 files changed

+156
-31
lines changed

16 files changed

+156
-31
lines changed

components/MarkdownTextBlock/src/HtmlWriter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public static void WriteHtml(WinUIRenderer renderer, HtmlNodeCollection nodes)
4949
else
5050
{
5151
var myHyperlink = new MyHyperlink(node, renderer.Config.BaseUrl);
52+
myHyperlink.TextElement.Foreground = renderer.Config.Themes.LinkForeground;
5253
myHyperlink.ClickEvent += (sender, e) =>
5354
{
5455
var uri = sender.NavigateUri;

components/MarkdownTextBlock/src/MarkdownTextBlock.Properties.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ public partial class MarkdownTextBlock
108108
typeof(MarkdownTextBlock),
109109
new PropertyMetadata(null));
110110

111+
/// <summary>
112+
/// Identifies the <see cref="IsTextSelectionEnabled"/> dependency property.
113+
/// </summary>
114+
private static readonly DependencyProperty IsTextSelectionEnabledProperty = DependencyProperty.Register(
115+
nameof(IsTextSelectionEnabled),
116+
typeof(bool),
117+
typeof(MarkdownTextBlock),
118+
new PropertyMetadata(false, OnIsTextSelectionEnabledChanged));
119+
120+
private static void OnIsTextSelectionEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
121+
{
122+
if (d is MarkdownTextBlock mtb && mtb._document != null)
123+
{
124+
mtb._document.RichTextBlock.IsTextSelectionEnabled = (bool)e.NewValue;
125+
}
126+
}
127+
111128
public MarkdownConfig Config
112129
{
113130
get => (MarkdownConfig)GetValue(ConfigProperty);
@@ -203,4 +220,13 @@ public MarkdownDocument? MarkdownDocument
203220
get => (MarkdownDocument)GetValue(MarkdownDocumentProperty);
204221
private set => SetValue(MarkdownDocumentProperty, value);
205222
}
223+
224+
/// <summary>
225+
/// Gets or sets a value indicating whether text selection is enabled.
226+
/// </summary>
227+
public bool IsTextSelectionEnabled
228+
{
229+
get => (bool)GetValue(IsTextSelectionEnabledProperty);
230+
set => SetValue(IsTextSelectionEnabledProperty, value);
231+
}
206232
}

components/MarkdownTextBlock/src/MarkdownThemes.cs

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@ public sealed class MarkdownThemes : DependencyObject
3434

3535
public double H6FontSize { get; set; } = 12;
3636

37-
public Brush HeadingForeground { get; set; } = Extensions.GetAccentColorBrush();
37+
public Brush H1Foreground { get; set; } = (Brush)Application.Current.Resources["TextFillColorPrimaryBrush"];
38+
public Brush H2Foreground { get; set; } = (Brush)Application.Current.Resources["TextFillColorPrimaryBrush"];
39+
public Brush H3Foreground { get; set; } = (Brush)Application.Current.Resources["TextFillColorPrimaryBrush"];
40+
public Brush H4Foreground { get; set; } = (Brush)Application.Current.Resources["TextFillColorPrimaryBrush"];
41+
public Brush H5Foreground { get; set; } = (Brush)Application.Current.Resources["TextFillColorPrimaryBrush"];
42+
public Brush H6Foreground { get; set; } = (Brush)Application.Current.Resources["TextFillColorPrimaryBrush"];
3843

39-
public FontWeight H1FontWeight { get; set; } = FontWeights.Bold;
44+
public FontWeight H1FontWeight { get; set; } = FontWeights.SemiBold;
4045

4146
public FontWeight H2FontWeight { get; set; } = FontWeights.Normal;
4247

@@ -48,10 +53,10 @@ public sealed class MarkdownThemes : DependencyObject
4853

4954
public FontWeight H6FontWeight { get; set; } = FontWeights.Normal;
5055

51-
public Thickness H1Margin { get; set; } = new(left: 0, top: 14, right: 0, bottom: 0);
52-
public Thickness H2Margin { get; set; } = new(left: 0, top: 14, right: 0, bottom: 0);
53-
public Thickness H3Margin { get; set; } = new(left: 0, top: 14, right: 0, bottom: 0);
54-
public Thickness H4Margin { get; set; } = new(left: 0, top: 14, right: 0, bottom: 0);
56+
public Thickness H1Margin { get; set; } = new(left: 0, top: 16, right: 0, bottom: 0);
57+
public Thickness H2Margin { get; set; } = new(left: 0, top: 16, right: 0, bottom: 0);
58+
public Thickness H3Margin { get; set; } = new(left: 0, top: 16, right: 0, bottom: 0);
59+
public Thickness H4Margin { get; set; } = new(left: 0, top: 16, right: 0, bottom: 0);
5560
public Thickness H5Margin { get; set; } = new(left: 0, top: 8, right: 0, bottom: 0);
5661
public Thickness H6Margin { get; set; } = new(left: 0, top: 8, right: 0, bottom: 0);
5762

@@ -73,4 +78,54 @@ public sealed class MarkdownThemes : DependencyObject
7378
public double InlineCodeFontSize { get; set; } = 10;
7479

7580
public FontWeight InlineCodeFontWeight { get; set; } = FontWeights.Normal;
81+
82+
// Legacy parity properties (new)
83+
// Code block styling
84+
public Brush CodeBlockBackground { get; set; } = (Brush)Application.Current.Resources["ExpanderHeaderBackground"];
85+
public Brush CodeBlockBorderBrush { get; set; } = new SolidColorBrush(Colors.Gray);
86+
public Thickness CodeBlockBorderThickness { get; set; } = new Thickness(1);
87+
public Thickness CodeBlockPadding { get; set; } = new Thickness(8);
88+
public Thickness CodeBlockMargin { get; set; } = new Thickness(0, 8, 0, 8);
89+
public FontFamily CodeBlockFontFamily { get; set; } = new FontFamily("Consolas");
90+
public Brush CodeBlockForeground { get; set; } = (Brush)Application.Current.Resources["TextFillColorPrimaryBrush"];
91+
public CornerRadius CodeBlockCornerRadius { get; set; } = new CornerRadius(4);
92+
93+
// Horizontal rule
94+
public Brush HorizontalRuleBrush { get; set; } = new SolidColorBrush(Colors.Gray);
95+
public double HorizontalRuleThickness { get; set; } = 1.0;
96+
public Thickness HorizontalRuleMargin { get; set; } = new Thickness(0, 12, 0, 12);
97+
98+
// Link styling
99+
public Brush LinkForeground { get; set; } = (Brush)Application.Current.Resources["AccentTextFillColorPrimaryBrush"] ?? new SolidColorBrush(Colors.DodgerBlue);
100+
101+
// Paragraph / list
102+
public Thickness ParagraphMargin { get; set; } = new Thickness(0, 8, 0, 8);
103+
public double ParagraphLineHeight { get; set; } = 0; // 0 = default
104+
public double ListBulletSpacing { get; set; } = 4; // spaces after bullet
105+
public double ListGutterWidth { get; set; } = 30; // indent delta per level
106+
public Thickness ListMargin { get; set; } = new Thickness(0, 4, 0, 4);
107+
108+
// Quote styling
109+
public Brush QuoteBackground { get; set; } = new SolidColorBrush(Colors.Transparent);
110+
public Brush QuoteBorderBrush { get; set; } = new SolidColorBrush(Colors.Gray);
111+
public Thickness QuoteBorderThickness { get; set; } = new Thickness(4, 0, 0, 0);
112+
public Brush QuoteForeground { get; set; } = (Brush)Application.Current.Resources["TextFillColorPrimaryBrush"];
113+
public Thickness QuoteMargin { get; set; } = new Thickness(0, 4, 0, 4);
114+
public Thickness QuotePadding { get; set; } = new Thickness(4);
115+
public CornerRadius QuoteCornerRadius { get; set; } = new CornerRadius(4);
116+
117+
// Image styling
118+
public double ImageMaxWidth { get; set; } = 0; // 0 = no constraint
119+
public double ImageMaxHeight { get; set; } = 0;
120+
public Stretch ImageStretch { get; set; } = Stretch.Uniform;
121+
122+
// Table styling
123+
public Brush TableBorderBrush { get; set; } = new SolidColorBrush(Colors.Gray);
124+
public double TableBorderThickness { get; set; } = 1;
125+
public Thickness TableCellPadding { get; set; } = new Thickness(4);
126+
public Thickness TableMargin { get; set; } = new Thickness(0, 10, 0, 10);
127+
128+
// YAML / not currently used - placeholders for parity
129+
public Brush YamlBorderBrush { get; set; } = new SolidColorBrush(Colors.Gray);
130+
public Thickness YamlBorderThickness { get; set; } = new Thickness(1);
76131
}

components/MarkdownTextBlock/src/Renderers/ObjectRenderers/Inlines/LinkInlineRenderer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@ protected override void Write(WinUIRenderer renderer, LinkInline link)
4343
// Optionally restore later; not needed unless reused.
4444
}
4545
};
46+
// Apply link foreground to nested RichTextBlock content
47+
// (Handled in MyHyperlinkButton initialization via MarkdownConfig.Default for now)
4648
renderer.Push(myHyperlinkButton);
4749
}
4850
else
4951
{
5052
var hyperlink = new MyHyperlink(link, renderer.Config.BaseUrl);
53+
hyperlink.TextElement.Foreground = renderer.Config.Themes.LinkForeground;
5154
hyperlink.ClickEvent += (sender, e) =>
5255
{
5356
var uri = sender.NavigateUri;

components/MarkdownTextBlock/src/Renderers/ObjectRenderers/QuoteBlockRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protected override void Write(WinUIRenderer renderer, QuoteBlock obj)
1414
if (renderer == null) throw new ArgumentNullException(nameof(renderer));
1515
if (obj == null) throw new ArgumentNullException(nameof(obj));
1616

17-
var quote = new MyQuote(obj);
17+
var quote = new MyQuote(obj, renderer.Config.Themes);
1818

1919
renderer.Push(quote);
2020
renderer.WriteChildren(obj);

components/MarkdownTextBlock/src/TextElements/MyCodeBlock.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ public MyCodeBlock(CodeBlock codeBlock, MarkdownConfig config)
2424
_paragraph = new Paragraph();
2525
var container = new InlineUIContainer();
2626
var border = new Border();
27-
border.Background = (Brush)Application.Current.Resources["ExpanderHeaderBackground"];
28-
border.Padding = _config.Themes.Padding;
29-
border.Margin = _config.Themes.InternalMargin;
30-
border.CornerRadius = _config.Themes.CornerRadius;
27+
border.Background = _config.Themes.CodeBlockBackground;
28+
border.BorderBrush = _config.Themes.CodeBlockBorderBrush;
29+
border.BorderThickness = _config.Themes.CodeBlockBorderThickness;
30+
border.Padding = _config.Themes.CodeBlockPadding;
31+
border.Margin = _config.Themes.CodeBlockMargin;
32+
border.CornerRadius = _config.Themes.CodeBlockCornerRadius;
3133
var richTextBlock = new RichTextBlock();
34+
richTextBlock.FontFamily = _config.Themes.CodeBlockFontFamily;
35+
richTextBlock.Foreground = _config.Themes.CodeBlockForeground;
3236

3337
#if false
3438
if (codeBlock is FencedCodeBlock fencedCodeBlock)

components/MarkdownTextBlock/src/TextElements/MyHeading.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,15 @@ private void SetHProperties(int level)
6060
5 => _config.Themes.H5FontSize,
6161
_ => _config.Themes.H6FontSize,
6262
};
63-
_paragraph.Foreground = _config.Themes.HeadingForeground;
63+
_paragraph.Foreground = level switch
64+
{
65+
1 => _config.Themes.H1Foreground,
66+
2 => _config.Themes.H2Foreground,
67+
3 => _config.Themes.H3Foreground,
68+
4 => _config.Themes.H4Foreground,
69+
5 => _config.Themes.H5Foreground,
70+
_ => _config.Themes.H6Foreground,
71+
};
6472
_paragraph.FontWeight = level switch
6573
{
6674
1 => _config.Themes.H1FontWeight,

components/MarkdownTextBlock/src/TextElements/MyHyperlink.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public MyHyperlink(LinkInline linkInline, string? baseUrl)
4141
_hyperlink = new Hyperlink()
4242
{
4343
NavigateUri = Extensions.GetUri(url, baseUrl),
44+
Foreground = MarkdownConfig.Default.Themes.LinkForeground
4445
};
4546
}
4647

@@ -52,6 +53,7 @@ public MyHyperlink(HtmlNode htmlNode, string? baseUrl)
5253
_hyperlink = new Hyperlink()
5354
{
5455
NavigateUri = Extensions.GetUri(url, baseUrl),
56+
Foreground = MarkdownConfig.Default.Themes.LinkForeground
5557
};
5658
}
5759

components/MarkdownTextBlock/src/TextElements/MyHyperlinkButton.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ private MyHyperlinkButton(string? url, string? baseUrl, HtmlNode? htmlNode, Link
6565
_flowDoc = new MyFlowDocument(_linkInline!);
6666
}
6767
_inlineUIContainer.Child = _hyperLinkButton;
68-
_hyperLinkButton.Content = _flowDoc.RichTextBlock;
68+
_flowDoc.RichTextBlock.Foreground = MarkdownConfig.Default.Themes.LinkForeground;
69+
_hyperLinkButton.Content = _flowDoc.RichTextBlock;
6970
}
7071

7172
public void AddChild(IAddChild child)

components/MarkdownTextBlock/src/TextElements/MyImage.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ private async void LoadImage(object sender, RoutedEventArgs e)
150150
{
151151
_image.Height = _precedentHeight;
152152
}
153+
154+
// Apply theme constraints if provided
155+
var themes = MarkdownConfig.Default.Themes;
156+
if (themes.ImageMaxWidth > 0)
157+
{
158+
_image.MaxWidth = themes.ImageMaxWidth;
159+
}
160+
if (themes.ImageMaxHeight > 0)
161+
{
162+
_image.MaxHeight = themes.ImageMaxHeight;
163+
}
164+
_image.Stretch = themes.ImageStretch;
153165
}
154166
catch (Exception) { }
155167
}

0 commit comments

Comments
 (0)