Skip to content

Commit

Permalink
Renamed Cycling to Transition in MarqueeBehaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
Avid29 committed Jul 21, 2024
1 parent 584371e commit cbb80a6
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
<Page x:Class="MarqueeTextExperiment.Samples.CustomStyleMarqueeTextSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand All @@ -11,7 +11,7 @@

<StackPanel Padding="16">
<labs:MarqueeText x:Name="Marquee"
Behavior="Cycle"
Behavior="Transition"
FontSize="18"
Text="{x:Bind MQText, Mode=OneWay}">
<labs:MarqueeText.Style>
Expand All @@ -30,7 +30,7 @@
CornerRadius="{TemplateBinding CornerRadius}">

<Grid.Resources>
<Storyboard x:Name="CyclingAnimation"
<Storyboard x:Name="TransitionAnimation"
Duration="0:0:0.5">
<!-- Animate out -->
<DoubleAnimationUsingKeyFrames x:Name="CycleAnimationTranslationAnimation"
Expand Down Expand Up @@ -129,7 +129,7 @@
<Setter Target="Segment2.Visibility" Value="Collapsed" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Cycle">
<VisualState x:Name="Transition">
<VisualState.Setters>
<Setter Target="Segment1.Padding" Value="0" />
<Setter Target="Segment2.Visibility" Value="Collapsed" />
Expand Down
6 changes: 3 additions & 3 deletions components/MarqueeText/samples/MarqueeTextSample.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace MarqueeTextExperiment.Samples;
[ToolkitSampleMultiChoiceOption("MQDirection", "Left", "Right", "Up", "Down", Title = "Marquee Direction")]
//[ToolkitSampleMultiChoiceOption("MarqueeRepeat", "Repeat", "Forever", "1x", "2x")]
#if !HAS_UNO
[ToolkitSampleMultiChoiceOption("MQBehavior", "Ticker", "Looping", "Bouncing", "Cycle", Title = "Marquee Behavior")]
[ToolkitSampleMultiChoiceOption("MQBehavior", "Ticker", "Looping", "Bouncing", "Transition", Title = "Marquee Behavior")]
#else
[ToolkitSampleMultiChoiceOption("MQBehavior", "Ticker", "Looping", "Cycle", Title = "Marquee Behavior")]
[ToolkitSampleMultiChoiceOption("MQBehavior", "Ticker", "Looping", "Transition", Title = "Marquee Behavior")]
#endif
public sealed partial class MarqueeTextSample : Page
{
Expand All @@ -32,7 +32,7 @@ public MarqueeTextSample()
#if !HAS_UNO
"Bouncing" => MarqueeBehavior.Bouncing,
#endif
"Cycle" => MarqueeBehavior.Cycle,
"Transition" => MarqueeBehavior.Transition,
_ => throw new NotImplementedException(),
};

Expand Down
4 changes: 2 additions & 2 deletions components/MarqueeText/src/MarqueeBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public enum MarqueeBehavior
#endif

/// <summary>
/// The text will cycle fading between a list of statements.
/// The text will transition when the text property changes.
/// </summary>
Cycle,
Transition,
}
6 changes: 3 additions & 3 deletions components/MarqueeText/src/MarqueeText.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ private void Container_SizeChanged(object sender, SizeChangedEventArgs e)
UpdateClipping();

// Update the animation when the size changes
// Unless in cycling mode where the container size doesn't affect the animation.
if (!IsCycling)
// Unless in transition mode where the container size doesn't affect the animation.
if (!IsTransition)
{
UpdateAnimation(true);
}
Expand All @@ -63,7 +63,7 @@ private void StoryBoard_Completed(object? sender, object e)
MarqueeCompleted?.Invoke(this, EventArgs.Empty);

// Update the secondary text to match the new text
if (IsCycling)
if (IsTransition)
{
SecondaryText = Text;
}
Expand Down
14 changes: 7 additions & 7 deletions components/MarqueeText/src/MarqueeText.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public string SecondaryText
/// Gets or sets the speed the text moves in the Marquee.
/// </summary>
/// <remarks>
/// Ignored if the behavior is <see cref="MarqueeBehavior.Cycle"/>
/// Ignored if the behavior is <see cref="MarqueeBehavior.Transition"/>
/// </remarks>
public double Speed
{
Expand All @@ -68,7 +68,7 @@ public double Speed
/// Gets or sets a value indicating whether or not the marquee scroll repeats.
/// </summary>
/// <remarks>
/// Ignored if the behavior is <see cref="MarqueeBehavior.Cycle"/>
/// Ignored if the behavior is <see cref="MarqueeBehavior.Transition"/>
/// </remarks>
public RepeatBehavior RepeatBehavior
{
Expand Down Expand Up @@ -98,7 +98,7 @@ public MarqueeBehavior Behavior
private bool IsBouncing => false;
#endif

private bool IsCycling => Behavior == MarqueeBehavior.Cycle;
private bool IsTransition => Behavior == MarqueeBehavior.Transition;

/// <summary>
/// Gets or sets the direction the Marquee should scroll
Expand Down Expand Up @@ -158,7 +158,7 @@ private static void DirectionPropertyChanged(DependencyObject d, DependencyPrope
bool oldAxisX = oldDirection is MarqueeDirection.Left or MarqueeDirection.Right;
bool newAxisX = newDirection is MarqueeDirection.Left or MarqueeDirection.Right;

if (control.IsCycling || oldAxisX != newAxisX)
if (control.IsTransition || oldAxisX != newAxisX)
{
control.StopMarquee(false);
}
Expand All @@ -178,8 +178,8 @@ private static void TextPropertyChanged(DependencyObject d, DependencyPropertyCh
return;
}

// If the mode is not cycling, update the secondary text to match and handle with standard property changed.
if (!control.IsCycling)
// If the mode is not transition, update the secondary text to match and handle with standard property changed.
if (!control.IsTransition)
{
control.SecondaryText = (string)e.NewValue;
PropertyChanged(d, e);
Expand All @@ -188,7 +188,7 @@ private static void TextPropertyChanged(DependencyObject d, DependencyPropertyCh

if (!control._isActive)
{
// If the mode is cycling, start the marquee.
// If the mode is transition, start the marquee.
// We can skip this if the animation is already
// playing because that's smoother than starting a new animation.
control.StartMarquee();
Expand Down
24 changes: 12 additions & 12 deletions components/MarqueeText/src/MarqueeText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ namespace CommunityToolkit.Labs.WinUI.MarqueeTextRns;
[TemplatePart(Name = Segment2PartName, Type = typeof(FrameworkTemplate))]
[TemplatePart(Name = Segment2PartName, Type = typeof(FrameworkTemplate))]
[TemplatePart(Name = MarqueeTransformPartName, Type = typeof(TranslateTransform))]
[TemplatePart(Name = CyclingAnaimationPartName, Type = typeof(Storyboard))]
[TemplatePart(Name = TransitionAnaimationPartName, Type = typeof(Storyboard))]
[TemplateVisualState(GroupName = DirectionVisualStateGroupName, Name = LeftwardsVisualStateName)]
[TemplateVisualState(GroupName = DirectionVisualStateGroupName, Name = RightwardsVisualStateName)]
[TemplateVisualState(GroupName = DirectionVisualStateGroupName, Name = UpwardsVisualStateName)]
[TemplateVisualState(GroupName = DirectionVisualStateGroupName, Name = DownwardsVisualStateName)]
[TemplateVisualState(GroupName = BehaviorVisualStateGroupName, Name = TickerVisualStateName)]
[TemplateVisualState(GroupName = BehaviorVisualStateGroupName, Name = LoopingVisualStateName)]
[TemplateVisualState(GroupName = BehaviorVisualStateGroupName, Name = BouncingVisualStateName)]
[TemplateVisualState(GroupName = BehaviorVisualStateGroupName, Name = CycleVisualStateName)]
[TemplateVisualState(GroupName = BehaviorVisualStateGroupName, Name = TransitionVisualStateName)]
[ContentProperty(Name = nameof(Text))]

#if HAS_UNO
Expand All @@ -33,7 +33,7 @@ public partial class MarqueeText : Control
private const string Segment1PartName = "Segment1";
private const string Segment2PartName = "Segment2";
private const string MarqueeTransformPartName = "MarqueeTransform";
private const string CyclingAnaimationPartName = "CyclingAnimation";
private const string TransitionAnaimationPartName = "TransitionAnimation";

private const string MarqueeActiveState = "MarqueeActive";
private const string MarqueeStoppedState = "MarqueeStopped";
Expand All @@ -48,13 +48,13 @@ public partial class MarqueeText : Control
private const string TickerVisualStateName = "Ticker";
private const string LoopingVisualStateName = "Looping";
private const string BouncingVisualStateName = "Bouncing";
private const string CycleVisualStateName = "Cycle";
private const string TransitionVisualStateName = "Transition";

private Panel? _marqueeContainer;
private FrameworkElement? _segment1;
private FrameworkElement? _segment2;
private CompositeTransform? _marqueeTransform;
private Storyboard? _cyclingStoryboard;
private Storyboard? _transitionStoryboard;
private Storyboard? _marqueeStoryboard;

private bool _isActive;
Expand All @@ -77,7 +77,7 @@ protected override void OnApplyTemplate()
_segment1 = (FrameworkElement)GetTemplateChild(Segment1PartName);
_segment2 = (FrameworkElement)GetTemplateChild(Segment2PartName);
_marqueeTransform = (CompositeTransform)GetTemplateChild(MarqueeTransformPartName);
_cyclingStoryboard = (Storyboard)GetTemplateChild(CyclingAnaimationPartName);
_transitionStoryboard = (Storyboard)GetTemplateChild(TransitionAnaimationPartName);

_marqueeContainer.SizeChanged += Container_SizeChanged;

Expand Down Expand Up @@ -170,7 +170,7 @@ private bool UpdateAnimation(bool resume = true)
_marqueeTransform is null ||
_segment1 is null ||
_segment2 is null ||
_cyclingStoryboard is null)
_transitionStoryboard is null)
{
return false;
}
Expand Down Expand Up @@ -231,7 +231,7 @@ _segment2 is null ||
double end = Behavior switch
{
// (this value just needs to be non-Zero, the real number is handled in the Style)
MarqueeBehavior.Cycle => 20,
MarqueeBehavior.Transition => 20,
#if !HAS_UNO
// When the end of the text reaches the border if in bouncing mode
MarqueeBehavior.Bouncing => containerSize - segmentSize,
Expand Down Expand Up @@ -270,7 +270,7 @@ _segment2 is null ||
// Create new storyboard and animation
_marqueeStoryboard = Behavior switch
{
MarqueeBehavior.Cycle => _cyclingStoryboard,
MarqueeBehavior.Transition => _transitionStoryboard,
_ => CreateMarqueeStoryboardAnimation(start, end, duration, targetProperty),
};

Expand All @@ -292,7 +292,7 @@ _segment2 is null ||
}

/// <remarks>
/// This is method is used for all modes except cycling.
/// This is method is used for all modes except transition.
/// </remarks>
private Storyboard CreateMarqueeStoryboardAnimation(double start, double end, TimeSpan duration, string targetProperty)
{
Expand Down Expand Up @@ -354,9 +354,9 @@ private void UpdateClipping()
Rect = new Rect(0, 0, ActualWidth, ActualHeight)
};

if (IsCycling)
if (IsTransition)
{
// Don't clip in cycling mode
// Don't clip in transition mode
_marqueeContainer.Clip = null;
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/MarqueeText/src/MarqueeText.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
CornerRadius="{TemplateBinding CornerRadius}">

<Grid.Resources>
<Storyboard x:Name="CyclingAnimation"
<Storyboard x:Name="TransitionAnimation"
Duration="0:0:1.2">
<!-- Animate the translation -->
<DoubleAnimationUsingKeyFrames x:Name="CycleAnimationTranslationAnimation"
Expand Down Expand Up @@ -130,7 +130,7 @@
<Setter Target="Segment2.Visibility" Value="Collapsed" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Cycle">
<VisualState x:Name="Transition">
<VisualState.Setters>
<Setter Target="Segment1.Padding" Value="0" />
<Setter Target="Segment2.Visibility" Value="Collapsed" />
Expand Down

0 comments on commit cbb80a6

Please sign in to comment.