mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Added property change notification to Justifyer
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.ComponentModel;
|
||||
using static Terminal.Gui.Pos;
|
||||
|
||||
namespace Terminal.Gui;
|
||||
@@ -113,26 +114,57 @@ public enum Justification
|
||||
/// <summary>
|
||||
/// Justifies items within a container based on the specified <see cref="Justification"/>.
|
||||
/// </summary>
|
||||
public class Justifier
|
||||
public class Justifier : INotifyPropertyChanged
|
||||
{
|
||||
private Justification _justification;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets how the <see cref="Justifier"/> justifies items within a container.
|
||||
/// </summary>
|
||||
public Justification Justification { get; set; }
|
||||
public Justification Justification
|
||||
{
|
||||
get => _justification;
|
||||
set
|
||||
{
|
||||
_justification = value;
|
||||
PropertyChanged?.Invoke (this, new PropertyChangedEventArgs (nameof (Justification)));
|
||||
}
|
||||
}
|
||||
|
||||
private int _containerSize;
|
||||
|
||||
/// <summary>
|
||||
/// The size of the container.
|
||||
/// </summary>
|
||||
public int ContainerSize { get; set; }
|
||||
public int ContainerSize
|
||||
{
|
||||
get => _containerSize;
|
||||
set
|
||||
{
|
||||
_containerSize = value;
|
||||
PropertyChanged?.Invoke (this, new PropertyChangedEventArgs (nameof (ContainerSize)));
|
||||
}
|
||||
}
|
||||
|
||||
private bool _putSpaceBetweenItems;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether <see cref="Justifier"/> puts a space is placed between items. Default is
|
||||
/// <see langword="false"/>. If <see langword="true"/>, a space will be
|
||||
/// placed between each item, which is useful for justifying text.
|
||||
/// </summary>
|
||||
public bool PutSpaceBetweenItems { get; set; }
|
||||
public bool PutSpaceBetweenItems
|
||||
{
|
||||
get => _putSpaceBetweenItems;
|
||||
set
|
||||
{
|
||||
_putSpaceBetweenItems = value;
|
||||
PropertyChanged?.Invoke (this, new PropertyChangedEventArgs (nameof (PutSpaceBetweenItems)));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add property change events so PosJustify can know when to update the locations.
|
||||
/// <inheritdoc />
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Takes a list of items and returns their positions when justified within a container <see name="ContainerSize"/>
|
||||
@@ -340,15 +372,4 @@ public class Justifier
|
||||
throw new ArgumentException ("The size of an item cannot be negative.");
|
||||
}
|
||||
}
|
||||
public override bool Equals (object other)
|
||||
{
|
||||
if (other is Justifier justifier)
|
||||
{
|
||||
return Justification == justifier.Justification &&
|
||||
ContainerSize == justifier.ContainerSize &&
|
||||
PutSpaceBetweenItems == justifier.PutSpaceBetweenItems;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -606,6 +606,12 @@ public class Pos
|
||||
{
|
||||
Justifier.Justification = justification;
|
||||
_groupId = groupId;
|
||||
Justifier.PropertyChanged += Justifier_PropertyChanged;
|
||||
}
|
||||
|
||||
private void Justifier_PropertyChanged (object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
_location = null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -633,7 +639,7 @@ public class Pos
|
||||
|
||||
internal override int Calculate (int superviewDimension, Dim dim, View us, Dim.Dimension dimension)
|
||||
{
|
||||
if (_location.HasValue)
|
||||
if (_location.HasValue && Justifier.ContainerSize == superviewDimension)
|
||||
{
|
||||
return _location.Value;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,6 @@ public sealed class PosJustification : Scenario
|
||||
if (view.X is Pos.PosJustify j)
|
||||
{
|
||||
j.Justifier.PutSpaceBetweenItems = _horizJustifier.PutSpaceBetweenItems;
|
||||
view.X = j;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user