Skip to content

Commit

Permalink
feat: Support for SelectionHihglightColor on Skia
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Sep 16, 2022
1 parent 3d07dba commit 890f2d4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Gtk;
using Pango;
using Uno.Disposables;
using Uno.Foundation.Logging;
using Uno.UI.Runtime.Skia.GTK.UI.Text;
using Uno.UI.Xaml.Controls.Extensions;
using Windows.Foundation.Collections;
Expand Down Expand Up @@ -425,7 +426,7 @@ public int GetSelectionLength()
}
}

public void SetForeground(Windows.UI.Xaml.Media.Brush brush)
public void UpdateForeground()
{
if (_currentInputWidget is not null && brush is SolidColorBrush scb)
{
Expand All @@ -452,5 +453,11 @@ private void RemoveForegroundProvider()
_foregroundCssProvider = null;
}
}

public void UpdateSelectionHighlightColor()
{
// Selection highlight color change is not supported on GTK currently
this.Log().LogWarning("SelectionHighlightColor changes are currently not supported on GTK");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal static class Extensions
return null;
}

private static System.Windows.Media.Color ToWpfColor(this Windows.UI.Color color)
public static System.Windows.Media.Color ToWpfColor(this Windows.UI.Color color)
=> System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B);

private static System.Windows.Point ToWpfPoint(this Windows.Foundation.Point point)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public int GetSelectionLength()
return 0;
}

public void SetForeground(Windows.UI.Xaml.Media.Brush brush)
public void UpdateForeground()
{
var wpfBrush = brush.ToWpfBrush();
if (_currentTextBoxInputWidget != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Windows.Foundation;
using Windows.UI;
using Windows.UI.Xaml.Media;

namespace Uno.UI.Xaml.Controls.Extensions
Expand Down Expand Up @@ -29,6 +30,8 @@ internal interface ITextBoxViewExtension

int GetSelectionLength();

void SetForeground(Brush brush);
void UpdateForeground();

void UpdateSelectionHighlightColor();
}
}
2 changes: 2 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public partial class TextBox

partial void OnForegroundColorChangedPartial(Brush newValue) => TextBoxView?.OnForegroundChanged(newValue);

partial void OnSelectionHighlightColorChangedPartial(SolidColorBrush newValue) => TextBoxView?.OnSelectionHighlightColorChanged(newValue);

partial void OnMaxLengthChangedPartial(DependencyPropertyChangedEventArgs e) => TextBoxView?.UpdateMaxLength();

private void UpdateTextBoxView()
Expand Down
8 changes: 7 additions & 1 deletion src/Uno.UI/UI/Xaml/Controls/TextBox/TextBoxView.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ internal void Select(int start, int length)
internal void OnForegroundChanged(Brush brush)
{
DisplayBlock.Foreground = brush;
_textBoxExtension?.SetForeground(brush);
_textBoxExtension?.UpdateForeground();
}

internal void OnSelectionHighlightColorChanged(SolidColorBrush brush)
{
DisplayBlock.SelectionHighlightColor = brush;
_textBoxExtension?.UpdateSelectionHighlightColor();
}

internal void OnFocusStateChanged(FocusState focusState)
Expand Down

0 comments on commit 890f2d4

Please sign in to comment.