1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 12:58:33 +01:00

Allow setting a default text alignment for paragraphs in UiStyle

This commit is contained in:
Ell 2022-01-22 22:54:47 +01:00
parent 58a0f8915a
commit dbf370c968
3 changed files with 9 additions and 3 deletions

View file

@ -27,6 +27,7 @@ Improvements
- Only set a paragraph's area dirty when a text change would cause it to change size
- Ensure that a panel gets notified of all relevant changes by calling OnChildAreaDirty for all grandchildren
- Avoid unnecessary panel updates by using an Epsilon comparison when scrolling children
- Allow setting a default text alignment for paragraphs in UiStyle
Fixes
- Fixed paragraph links having incorrect hover locations when using special text alignments

View file

@ -90,7 +90,7 @@ namespace MLEM.Ui.Elements {
/// <summary>
/// The <see cref="TextAlignment"/> that this paragraph's text should be rendered with
/// </summary>
public TextAlignment Alignment {
public StyleProp<TextAlignment> Alignment {
get => this.alignment;
set {
this.alignment = value;
@ -99,7 +99,7 @@ namespace MLEM.Ui.Elements {
}
private string text;
private TextAlignment alignment;
private StyleProp<TextAlignment> alignment;
private StyleProp<GenericFont> regularFont;
/// <summary>
@ -158,6 +158,7 @@ namespace MLEM.Ui.Elements {
this.RegularFont = this.RegularFont.OrStyle(style.Font ?? throw new NotSupportedException("Paragraphs cannot use ui styles that don't have a font. Please supply a custom font by setting UiStyle.Font."));
this.TextScale = this.TextScale.OrStyle(style.TextScale);
this.TextColor = this.TextColor.OrStyle(style.TextColor);
this.Alignment = this.Alignment.OrStyle(style.TextAlignment);
}
/// <summary>
@ -202,7 +203,7 @@ namespace MLEM.Ui.Elements {
}
private float GetAlignmentOffset() {
switch (this.Alignment) {
switch (this.Alignment.Value) {
case TextAlignment.Center:
return this.DisplayArea.Width / 2;
case TextAlignment.Right:

View file

@ -199,6 +199,10 @@ namespace MLEM.Ui.Style {
/// </summary>
public Color TextColor = Color.White;
/// <summary>
/// The <see cref="TextAlignment"/> that a <see cref="Paragraph"/> should use by default.
/// </summary>
public TextAlignment TextAlignment;
/// <summary>
/// The <see cref="SoundEffectInfo"/> that should be played when an element's <see cref="Element.OnPressed"/> and <see cref="Element.OnSecondaryPressed"/> events are called.
/// Note that this sound is only played if the callbacks have any subscribers.
/// </summary>