Refactored all of the views to match slider.
This commit is contained in:
Родитель
bd435e91de
Коммит
8b7a835b7c
|
@ -41,7 +41,7 @@ namespace HotUI.Samples
|
|||
new VStack
|
||||
{
|
||||
(state.CanEdit
|
||||
? (View) new TextField(() => state.Text, onCommit: value => state.Text = value)
|
||||
? (View) new TextField(state.Text, onCommit: value => state.Text = value)
|
||||
: new Text(() => $"{state.Text}: multiText")), // Text will warn you. This should be done by TextBinding
|
||||
new Text(state.Text),
|
||||
new HStack
|
||||
|
|
|
@ -35,8 +35,8 @@ namespace HotUI.Samples {
|
|||
new VStack
|
||||
{
|
||||
(state.CanEdit
|
||||
? (View) new TextField(() => state.Text, onCommit: (value) => state.Text = value )
|
||||
: new Text(() => $"{state.Text}: multiText")), // Fromated Text will warn you. This should be done by TextBinding
|
||||
? (View) new TextField(state.Text, onCommit: (value) => state.Text = value )
|
||||
: new Text(() => $"{state.Text}: multiText")), // Formatted Text will warn you. This should be done by TextBinding
|
||||
new Text(state.Text),
|
||||
new HStack
|
||||
{
|
||||
|
@ -53,10 +53,7 @@ namespace HotUI.Samples {
|
|||
View.SetGlobalEnvironment (EnvironmentKeys.Fonts.Font, newFont);
|
||||
}),
|
||||
},
|
||||
new Toggle(() =>state.CanEdit)
|
||||
{
|
||||
IsOnChanged = (e) => state.CanEdit = e
|
||||
}
|
||||
new Toggle(state.CanEdit, e => state.CanEdit = e)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace HotUI.Samples
|
|||
Body = () => new VStack
|
||||
{
|
||||
new SecureField("Enter a password", newValue => password.Value = newValue),
|
||||
new Text(() => $"{password.Value}")
|
||||
new Text(password)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace HotUI.Samples
|
|||
Body = () => new VStack
|
||||
{
|
||||
//new Slider(value: 12, from: -100, through: 100, by: 0.1f),
|
||||
//new Slider(value: (Func<float>)(() => 12f), from: -100, through: 100, by: 0.1f),
|
||||
//new Slider(value: () => 12f, from: -100, through: 100, by: 0.1f),
|
||||
//new Slider(value: new Binding<float>( getValue: () => 12f, setValue:null), from: -100, through: 100, by: 0.1f),
|
||||
new Slider(value: celsius, from: -100, through: 100, by: 0.1f),
|
||||
new Text($"{celsius.Value} Celsius"),
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace HotUI
|
|||
public T BoundValue
|
||||
{
|
||||
get => _boundValue;
|
||||
protected set => this.SetValue (State, ref this._boundValue, value, ViewPropertyChanged, _propertyName);
|
||||
protected set => SetValue (ref _boundValue, value, _propertyName);
|
||||
}
|
||||
|
||||
protected void SetValue<T> (ref T currentValue, T newValue, [CallerMemberName] string propertyName = "")
|
||||
|
|
|
@ -2,48 +2,26 @@
|
|||
|
||||
namespace HotUI
|
||||
{
|
||||
public class Button : View
|
||||
public class Button : BoundView<string>
|
||||
{
|
||||
public Button ()
|
||||
public Button (
|
||||
Binding<string> value = null,
|
||||
Action action = null) : base(value, nameof(Text))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Button (string text, Action action = null) : base (true)
|
||||
{
|
||||
Text = text;
|
||||
OnClick = action;
|
||||
}
|
||||
|
||||
public Button (Func<string> text, Action action = null)
|
||||
public Button(
|
||||
Func<string> value,
|
||||
Action action = null) : this((Binding<string>)value, action)
|
||||
{
|
||||
TextBinding = text;
|
||||
OnClick = action;
|
||||
}
|
||||
|
||||
private string _text;
|
||||
public string Text {
|
||||
get => _text;
|
||||
private set => this.SetValue (State, ref _text, value, ViewPropertyChanged);
|
||||
get => BoundValue;
|
||||
private set => BoundValue = value;
|
||||
}
|
||||
|
||||
|
||||
public Action OnClick { get; private set; }
|
||||
|
||||
public Func<string> TextBinding { get; private set; }
|
||||
|
||||
protected override void WillUpdateView ()
|
||||
{
|
||||
base.WillUpdateView ();
|
||||
if (TextBinding != null) {
|
||||
State.StartProperty ();
|
||||
var text = TextBinding.Invoke ();
|
||||
var props = State.EndProperty ();
|
||||
var propCount = props.Length;
|
||||
if (propCount > 0) {
|
||||
State.BindingState.AddViewProperty (props, (s, o) => Text = TextBinding.Invoke ());
|
||||
}
|
||||
Text = text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,16 @@ namespace HotUI
|
|||
OnEditingChanged = new MulticastAction<float>(value, onEditingChanged);
|
||||
}
|
||||
|
||||
public Slider (
|
||||
Func<float> value,
|
||||
float from = 0,
|
||||
float through = 100,
|
||||
float by = 1,
|
||||
Action<float> onEditingChanged = null) : this((Binding<float>)value, from, through, by, onEditingChanged)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public float Value {
|
||||
get => BoundValue;
|
||||
private set => BoundValue = value;
|
||||
|
|
|
@ -5,48 +5,24 @@ namespace HotUI
|
|||
/// <summary>
|
||||
/// A view that displays one or more lines of read-only text.
|
||||
/// </summary>
|
||||
public class Text : View
|
||||
public class Text : BoundView<string>
|
||||
{
|
||||
public Text()
|
||||
public Text (
|
||||
Binding<string> value = null) : base(value, nameof(Value))
|
||||
{
|
||||
}
|
||||
|
||||
public Text(string value) : base(true)
|
||||
}
|
||||
|
||||
public Text (
|
||||
Func<string> value = null) : this((Binding<string>)value)
|
||||
{
|
||||
Value = value;
|
||||
|
||||
}
|
||||
|
||||
public Text(Func<string> formattedText)
|
||||
{
|
||||
TextBinding = formattedText;
|
||||
}
|
||||
|
||||
private string _value;
|
||||
|
||||
|
||||
public string Value
|
||||
{
|
||||
get => _value;
|
||||
private set => this.SetValue(State, ref _value, value, ViewPropertyChanged);
|
||||
}
|
||||
|
||||
public Func<string> TextBinding { get; }
|
||||
|
||||
protected override void WillUpdateView()
|
||||
{
|
||||
base.WillUpdateView();
|
||||
if (TextBinding != null)
|
||||
{
|
||||
State.StartProperty();
|
||||
var text = TextBinding.Invoke();
|
||||
var props = State.EndProperty();
|
||||
var propCount = props.Length;
|
||||
if (propCount > 0)
|
||||
{
|
||||
State.BindingState.AddViewProperty(props, (s, o) => Value = TextBinding.Invoke());
|
||||
}
|
||||
|
||||
Value = text;
|
||||
}
|
||||
get => BoundValue;
|
||||
private set => BoundValue = value;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,59 +2,39 @@
|
|||
|
||||
namespace HotUI
|
||||
{
|
||||
public class TextField : View
|
||||
public class TextField : BoundView<string>
|
||||
{
|
||||
public TextField (string placeholder, Action<string> onEditingChanged = null, Action<string> onCommit = null) : base (true)
|
||||
public TextField (
|
||||
Binding<string> value = null,
|
||||
string placeholder = null,
|
||||
Action<string> onEditingChanged = null,
|
||||
Action<string> onCommit = null) : base(value, nameof(Text))
|
||||
{
|
||||
Placeholder = placeholder;
|
||||
OnEditingChanged = onEditingChanged;
|
||||
OnEditingChanged = new MulticastAction<string>(value, onEditingChanged);
|
||||
OnCommit = onCommit;
|
||||
}
|
||||
|
||||
public TextField (string text = null, string placeholder = null, Action<string> onEditingChanged = null, Action<string> onCommit = null) : base (true)
|
||||
|
||||
public TextField(
|
||||
Func<string> value = null,
|
||||
string placeholder = null,
|
||||
Action<string> onEditingChanged = null,
|
||||
Action<string> onCommit = null) : this((Binding<string>)value, placeholder, onEditingChanged, onCommit)
|
||||
{
|
||||
Text = text;
|
||||
Placeholder = placeholder;
|
||||
OnEditingChanged = onEditingChanged;
|
||||
OnCommit = onCommit;
|
||||
|
||||
}
|
||||
|
||||
public TextField (Func<string> builder, string placeholder = null, Action<string> onEditingChanged = null, Action<string> onCommit = null )
|
||||
{
|
||||
TextBinding = builder;
|
||||
Placeholder = placeholder;
|
||||
OnEditingChanged = onEditingChanged;
|
||||
OnCommit = onCommit;
|
||||
}
|
||||
|
||||
string text;
|
||||
public string Text {
|
||||
get => text;
|
||||
private set => this.SetValue (State, ref text, value, ViewPropertyChanged);
|
||||
get => BoundValue;
|
||||
private set => BoundValue = value;
|
||||
}
|
||||
|
||||
string placeholder;
|
||||
public string Placeholder {
|
||||
get => placeholder;
|
||||
set => this.SetValue (State, ref placeholder, value, ViewPropertyChanged);
|
||||
set => SetValue ( ref placeholder, value);
|
||||
}
|
||||
|
||||
public Func<string> TextBinding { get; private set; }
|
||||
protected override void WillUpdateView ()
|
||||
{
|
||||
base.WillUpdateView ();
|
||||
if (TextBinding != null) {
|
||||
State.StartProperty ();
|
||||
var text = TextBinding.Invoke ();
|
||||
var props = State.EndProperty ();
|
||||
var propCount = props.Length;
|
||||
if (propCount > 0) {
|
||||
State.BindingState.AddViewProperty (props, (s,o)=> Text = TextBinding.Invoke());
|
||||
}
|
||||
Text = text;
|
||||
}
|
||||
}
|
||||
|
||||
public Action<TextField> Focused { get; private set; }
|
||||
public Action<TextField> Unfocused { get; private set; }
|
||||
public Action<string> OnEditingChanged { get; private set; }
|
||||
|
|
|
@ -2,46 +2,27 @@
|
|||
|
||||
namespace HotUI
|
||||
{
|
||||
public class Toggle : View
|
||||
public class Toggle : BoundView<bool>
|
||||
{
|
||||
|
||||
public Toggle(bool isOn)
|
||||
public Toggle (
|
||||
Binding<bool> value = null,
|
||||
Action<bool> onChanged = null) : base(value, nameof(IsOn))
|
||||
{
|
||||
IsOn = isOn;
|
||||
IsOnChanged = new MulticastAction<bool>(value, onChanged);
|
||||
}
|
||||
|
||||
public Toggle(Func<bool> builder)
|
||||
|
||||
public Toggle (
|
||||
Func<bool> value = null,
|
||||
Action<bool> onChanged = null) : this((Binding<bool>)value, onChanged)
|
||||
{
|
||||
IsOnBinding = builder;
|
||||
}
|
||||
|
||||
|
||||
private bool isOn;
|
||||
|
||||
public bool IsOn
|
||||
{
|
||||
get => isOn;
|
||||
set => this.SetValue(State, ref isOn, value, ViewPropertyChanged);
|
||||
get => BoundValue;
|
||||
set => BoundValue = value;
|
||||
}
|
||||
|
||||
public Func<bool> IsOnBinding { get; private set; }
|
||||
|
||||
protected override void WillUpdateView()
|
||||
{
|
||||
base.WillUpdateView();
|
||||
if (IsOnBinding != null)
|
||||
{
|
||||
State.StartProperty();
|
||||
var on = IsOnBinding.Invoke();
|
||||
var props = State.EndProperty();
|
||||
var propCount = props.Length;
|
||||
if (propCount > 0)
|
||||
{
|
||||
State.BindingState.AddViewProperty(props, (s, o) => IsOn = IsOnBinding.Invoke());
|
||||
}
|
||||
IsOn = on;
|
||||
}
|
||||
}
|
||||
|
||||
public Action<bool> IsOnChanged { get; set; }
|
||||
|
||||
public Action<bool> IsOnChanged { get; private set; }
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче