Skip to content

Commit

Permalink
Code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Lamparter committed Jan 9, 2025
1 parent 351b095 commit 5b7e85b
Show file tree
Hide file tree
Showing 31 changed files with 14,575 additions and 14,754 deletions.
251 changes: 125 additions & 126 deletions src/Riverside.Toolkit/Controls/Card.cs
Original file line number Diff line number Diff line change
@@ -1,147 +1,146 @@
namespace Riverside.Toolkit.Controls
namespace Riverside.Toolkit.Controls;

/// <summary>
/// Represents a custom Card control.
/// </summary>
public sealed class Card : Control
{
/// <summary>
/// Represents a custom Card control.
/// Initializes a new instance of the <see cref="Card"/> class.
/// </summary>
public sealed class Card : Control
public Card()
{
/// <summary>
/// Initializes a new instance of the <see cref="Card"/> class.
/// </summary>
public Card()
{
this.DefaultStyleKey = typeof(Card);
this.PointerEntered += Card_PointerEntered;
this.PointerPressed += Card_PointerPressed;
this.PointerReleased += Card_PointerReleased;
this.PointerExited += Card_PointerExited;
}
this.DefaultStyleKey = typeof(Card);
PointerEntered += Card_PointerEntered;
PointerPressed += Card_PointerPressed;
PointerReleased += Card_PointerReleased;
PointerExited += Card_PointerExited;
}

/// <summary>
/// Identifies the <see cref="Title"/> dependency property.
/// </summary>
public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register(
"Title", // The name of the property
typeof(string), // The type of the property
typeof(Card), // The type of the owner class
new PropertyMetadata("Title") // Default value
);
/// <summary>
/// Identifies the <see cref="Title"/> dependency property.
/// </summary>
public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register(
"Title", // The name of the property
typeof(string), // The type of the property
typeof(Card), // The type of the owner class
new PropertyMetadata("Title") // Default value
);

/// <summary>
/// Gets or sets the title of the Card.
/// </summary>
[Browsable(true)]
[Category("Common")]
[Description("The title of the Card")]
public string Title
{
get { return (string)GetValue(TitleProperty); }
set { SetValue(TitleProperty, value); }
}
/// <summary>
/// Gets or sets the title of the Card.
/// </summary>
[Browsable(true)]
[Category("Common")]
[Description("The title of the Card")]
public string Title
{
get => (string)GetValue(TitleProperty);
set => SetValue(TitleProperty, value);
}

/// <summary>
/// Identifies the <see cref="Subtitle"/> dependency property.
/// </summary>
public static readonly DependencyProperty SubtitleProperty =
DependencyProperty.Register(
"Subtitle", // The name of the property
typeof(string), // The type of the property
typeof(Card), // The type of the owner class
new PropertyMetadata("Subtitle") // Default value
);
/// <summary>
/// Identifies the <see cref="Subtitle"/> dependency property.
/// </summary>
public static readonly DependencyProperty SubtitleProperty =
DependencyProperty.Register(
"Subtitle", // The name of the property
typeof(string), // The type of the property
typeof(Card), // The type of the owner class
new PropertyMetadata("Subtitle") // Default value
);

/// <summary>
/// Gets or sets the subtitle of the Card.
/// </summary>
[Browsable(true)]
[Category("Common")]
[Description("The Subtitle of the Card")]
public string Subtitle
{
get { return (string)GetValue(SubtitleProperty); }
set { SetValue(SubtitleProperty, value); }
}
/// <summary>
/// Gets or sets the subtitle of the Card.
/// </summary>
[Browsable(true)]
[Category("Common")]
[Description("The Subtitle of the Card")]
public string Subtitle
{
get => (string)GetValue(SubtitleProperty);
set => SetValue(SubtitleProperty, value);
}

/// <summary>
/// Identifies the <see cref="Content"/> dependency property.
/// </summary>
public static readonly DependencyProperty ContentProperty =
DependencyProperty.Register(
"Content", // The name of the property
typeof(string), // The type of the property
typeof(Card), // The type of the owner class
new PropertyMetadata("Content") // Default value
);
/// <summary>
/// Identifies the <see cref="Content"/> dependency property.
/// </summary>
public static readonly DependencyProperty ContentProperty =
DependencyProperty.Register(
"Content", // The name of the property
typeof(string), // The type of the property
typeof(Card), // The type of the owner class
new PropertyMetadata("Content") // Default value
);

/// <summary>
/// Gets or sets the content of the Card.
/// </summary>
[Browsable(true)]
[Category("Common")]
[Description("The Content of the Card")]
public string Content
{
get { return (string)GetValue(ContentProperty); }
set { SetValue(ContentProperty, value); }
}
/// <summary>
/// Gets or sets the content of the Card.
/// </summary>
[Browsable(true)]
[Category("Common")]
[Description("The Content of the Card")]
public string Content
{
get => (string)GetValue(ContentProperty);
set => SetValue(ContentProperty, value);
}

private bool invokedFromLeftButton;
private bool invokedFromLeftButton;

/// <summary>
/// Handles the PointerExited event of the Card control.
/// Changes the visual state to "Normal".
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="PointerRoutedEventArgs"/> instance containing the event data.</param>
private void Card_PointerExited(object sender, PointerRoutedEventArgs e)
{
VisualStateManager.GoToState(this, "Normal", true);
}
/// <summary>
/// Handles the PointerExited event of the Card control.
/// Changes the visual state to "Normal".
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="PointerRoutedEventArgs"/> instance containing the event data.</param>
private void Card_PointerExited(object sender, PointerRoutedEventArgs e) => VisualStateManager.GoToState(this, "Normal", true);

/// <summary>
/// Handles the PointerReleased event of the Card control.
/// Changes the visual state to "PointerOver" and invokes the Click event if the left button was pressed.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="PointerRoutedEventArgs"/> instance containing the event data.</param>
private void Card_PointerReleased(object sender, PointerRoutedEventArgs e)
{
VisualStateManager.GoToState(this, "PointerOver", true);
if (invokedFromLeftButton == true) this.Click?.Invoke(this, new RoutedEventArgs());
}
/// <summary>
/// Handles the PointerReleased event of the Card control.
/// Changes the visual state to "PointerOver" and invokes the Click event if the left button was pressed.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="PointerRoutedEventArgs"/> instance containing the event data.</param>
private void Card_PointerReleased(object sender, PointerRoutedEventArgs e)
{
_ = VisualStateManager.GoToState(this, "PointerOver", true);
if (invokedFromLeftButton == true) Click?.Invoke(this, new RoutedEventArgs());
}

/// <summary>
/// Handles the PointerPressed event of the Card control.
/// Changes the visual state to "Pressed" if the left button is pressed.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="PointerRoutedEventArgs"/> instance containing the event data.</param>
private void Card_PointerPressed(object sender, PointerRoutedEventArgs e)
/// <summary>
/// Handles the PointerPressed event of the Card control.
/// Changes the visual state to "Pressed" if the left button is pressed.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="PointerRoutedEventArgs"/> instance containing the event data.</param>
private void Card_PointerPressed(object sender, PointerRoutedEventArgs e)
{
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed == true)
{
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed == true)
{
VisualStateManager.GoToState(this, "Pressed", true);
invokedFromLeftButton = true;
}
else invokedFromLeftButton = false;
_ = VisualStateManager.GoToState(this, "Pressed", true);
invokedFromLeftButton = true;
}

/// <summary>
/// Handles the PointerEntered event of the Card control.
/// Changes the visual state to "PointerOver" or "Pressed" based on the pointer state.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="PointerRoutedEventArgs"/> instance containing the event data.</param>
private void Card_PointerEntered(object sender, PointerRoutedEventArgs e)
else
{
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed == false) VisualStateManager.GoToState(this, "PointerOver", true);
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed == true) VisualStateManager.GoToState(this, "Pressed", true);
invokedFromLeftButton = false;
}
}

/// <summary>
/// Occurs when the Card is clicked.
/// </summary>
public event RoutedEventHandler Click;
/// <summary>
/// Handles the PointerEntered event of the Card control.
/// Changes the visual state to "PointerOver" or "Pressed" based on the pointer state.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="PointerRoutedEventArgs"/> instance containing the event data.</param>
private void Card_PointerEntered(object sender, PointerRoutedEventArgs e)
{
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed == false) _ = VisualStateManager.GoToState(this, "PointerOver", true);
if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed == true) _ = VisualStateManager.GoToState(this, "Pressed", true);
}

/// <summary>
/// Occurs when the Card is clicked.
/// </summary>
public event RoutedEventHandler Click;
}
67 changes: 30 additions & 37 deletions src/Riverside.Toolkit/Controls/ChatBubble.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,38 @@
namespace Riverside.Toolkit.Controls
namespace Riverside.Toolkit.Controls;

/// <summary>
/// Represents a custom ChatBubble control.
/// </summary>
public sealed class ChatBubble : Control
{
/// <summary>
/// Represents a custom ChatBubble control.
/// Initializes a new instance of the <see cref="ChatBubble"/> class.
/// </summary>
public sealed class ChatBubble : Control
public ChatBubble()
{
/// <summary>
/// Initializes a new instance of the <see cref="ChatBubble"/> class.
/// </summary>
public ChatBubble()
{
this.DefaultStyleKey = typeof(ChatBubble);
}
this.DefaultStyleKey = typeof(ChatBubble);
}

/// <summary>
/// Identifies the <see cref="Text"/> dependency property.
/// </summary>
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register(
"Text", // The name of the property
typeof(string), // The type of the property
typeof(ChatBubble), // The type of the owner class
new PropertyMetadata("Text") // Default value
);
/// <summary>
/// Identifies the <see cref="Text"/> dependency property.
/// </summary>
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register(
"Text", // The name of the property
typeof(string), // The type of the property
typeof(ChatBubble), // The type of the owner class
new PropertyMetadata("Text") // Default value
);

/// <summary>
/// Gets or sets the text in the ChatBubble.
/// </summary>
[Browsable(true)]
[Category("Common")]
[Description("The text in the ChatBubble")]
public string Text
{
get
{
return (string)GetValue(TextProperty);
}
set
{
SetValue(TextProperty, value);
}
}
/// <summary>
/// Gets or sets the text in the ChatBubble.
/// </summary>
[Browsable(true)]
[Category("Common")]
[Description("The text in the ChatBubble")]
public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}
}
Loading

0 comments on commit 5b7e85b

Please sign in to comment.