Skip to content

Commit

Permalink
Patch text elevation
Browse files Browse the repository at this point in the history
  • Loading branch information
FrayxRulez committed Sep 13, 2024
1 parent f08fa78 commit 2dac294
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Telegram/Common/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ Color GetShade(AccentShade shade)
}
}

PatchTextControlElevationBorderFocusedBrush(requested, target, lookup, "TextControlElevationBorderFocusedBrush", create, GetShade);
PatchTextControlElevationBorderFocusedBrush(requested, target, lookup, "TextControlBorderBrushFocused", create, GetShade);

if (create)
{
ThemeDictionaries.Add(requested == TelegramTheme.Light ? "Light" : "Dark", target);
Expand Down Expand Up @@ -467,6 +470,43 @@ Color GetShade(AccentShade shade)
}
}

private void PatchTextControlElevationBorderFocusedBrush(TelegramTheme requested, ResourceDictionary target, Dictionary<string, object> lookup, string key, bool create, Func<AccentShade, Color> getShade)
{
// TextControlElevationBorderFocusedBrush is the only gradient that requires theming,
// Hence we hardcode the logic to update this brush as it's not worth it to support this scenario.
AddOrUpdate(target, key, create, (LinearGradientBrush brush) =>
{
if (create)
{
brush.MappingMode = BrushMappingMode.Absolute;
brush.StartPoint = new Windows.Foundation.Point(0, 0);
brush.EndPoint = new Windows.Foundation.Point(0, 2);
brush.RelativeTransform = new ScaleTransform
{
ScaleY = -1,
CenterY = 0.5
};
brush.GradientStops = new GradientStopCollection
{
new GradientStop
{
Offset = 1.0
},
new GradientStop
{
Offset = 1.0
}
};
}
if (lookup.TryGet("ControlStrokeColorDefaultBrush", out Color stroke))
{
brush.GradientStops[0].Color = getShade(requested == TelegramTheme.Light ? AccentShade.Dark1 : AccentShade.Light1);
brush.GradientStops[1].Color = stroke;
}
});
}

private void AddOrUpdate<T>(ResourceDictionary target, string key, bool create, Action<T> callback) where T : new()
{
if (create)
Expand Down

0 comments on commit 2dac294

Please sign in to comment.