Skip to content

Commit

Permalink
fix: fix invisible issue when Dot=True & fix some style issues in Badge.
Browse files Browse the repository at this point in the history
  • Loading branch information
zdpcdt committed Jan 15, 2025
1 parent e570361 commit 63be2d1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
30 changes: 28 additions & 2 deletions src/Ursa.Themes.Semi/Controls/Badge.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,27 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:Ursa.Converters;assembly=Ursa"
xmlns:u="https://irihi.tech/ursa">
<!-- Add Resources Here -->
<Design.PreviewWith>
<StackPanel Orientation="Horizontal" Margin="20" Width="300" Spacing="10">
<u:Badge Header="5">
<u:Avatar Classes="Square Blue" Content="BM" />
</u:Badge>
<u:Badge Dot="True">
<u:Avatar Classes="Square Blue" Content="YL" />
</u:Badge>
<u:Badge>
<u:Badge.Header>
<PathIcon
Theme="{StaticResource InnerPathIcon}"
Data="{StaticResource SemiIconLock}" />
</u:Badge.Header>
<u:Avatar Classes="Square Blue" Content="YL" />
</u:Badge>
<u:Badge Header="NEW">
<u:Avatar Classes="Square LightBlue" Content="WF" />
</u:Badge>
</StackPanel>
</Design.PreviewWith>

<converters:BadgeContentOverflowConverter x:Key="BadgeContentConverter" />

Expand Down Expand Up @@ -94,7 +114,6 @@
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"
IsVisible="{Binding Header, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static ObjectConverters.IsNotNull}}"
RenderTransformOrigin=".5,.5" />
</Grid>
</ControlTemplate>
Expand Down Expand Up @@ -138,6 +157,12 @@
</Style>

<Style Selector="^.Light">
<Style Selector="^/template/ ContentPresenter#PART_HeaderPresenter">
<Setter Property="Foreground" Value="{DynamicResource BadgeLightPrimaryBadgeForeground}" />
</Style>
<Style Selector="^/template/ Border#PART_BadgeContainer">
<Setter Property="Background" Value="{DynamicResource BadgeLightPrimaryBadgeBackground}" />
</Style>
<Style Selector="^.Primary">
<Style Selector="^/template/ ContentPresenter#PART_HeaderPresenter">
<Setter Property="Foreground" Value="{DynamicResource BadgeLightPrimaryBadgeForeground}" />
Expand Down Expand Up @@ -191,6 +216,7 @@
<Style Selector="^/template/ Border#PART_BadgeContainer">
<Setter Property="Background" Value="{DynamicResource BadgeInvertedBadgeBackground}" />
</Style>
<Setter Property="Foreground" Value="{DynamicResource BadgeInvertedPrimaryBadgeForeground}" />
<Style Selector="^.Primary /template/ ContentPresenter#PART_HeaderPresenter">
<Setter Property="Foreground" Value="{DynamicResource BadgeInvertedPrimaryBadgeForeground}" />
</Style>
Expand Down
2 changes: 1 addition & 1 deletion src/Ursa.Themes.Semi/Themes/Shared/Badge.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<x:Double x:Key="BadgeMinHeight">18</x:Double>
<x:Double x:Key="BadgeDotWidth">8</x:Double>
<x:Double x:Key="BadgeDotHeight">8</x:Double>
<Thickness x:Key="BadgePadding">6,0</Thickness>
<Thickness x:Key="BadgePadding">4,0</Thickness>
<Thickness x:Key="BadgeBorderThickness">1</Thickness>
<x:Double x:Key="BadgeFontSize">10</x:Double>
<CornerRadius x:Key="BadgeCornerRadius">100</CornerRadius>
Expand Down
11 changes: 6 additions & 5 deletions src/Ursa/Converters/BadgeContentOverflowConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@

namespace Ursa.Converters;

public class BadgeContentOverflowConverter: IMultiValueConverter
public class BadgeContentOverflowConverter : IMultiValueConverter
{
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
{
string overflowMark = parameter is string s ? s : "+";
if (double.TryParse(values[0]?.ToString(), out var b) && values[1] is int i and > 0)
var overflowMark = parameter as string ?? "+";
if (double.TryParse(values[0]?.ToString(), out var b) && values[1] is int count and > 0)
{
if (b > i)
if (b > count)
{
return i + overflowMark;
return $"{count}{overflowMark}";
}
}

return values[0];
}
}

0 comments on commit 63be2d1

Please sign in to comment.