Skip to content

Commit c85c1f2

Browse files
committed
Refactoring.
1 parent b4b9052 commit c85c1f2

File tree

6 files changed

+38
-45
lines changed

6 files changed

+38
-45
lines changed

samples/Unity.Mvvm.Counter/Assets/Scripts/BindableUIElementWrappers/BindableCounterSliderWrapper.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,39 @@ namespace BindableUIElementWrappers
88
public class BindableCounterSliderWrapper : BindableCommandElement, IInitializable, IDisposable
99
{
1010
private readonly BindableCounterSlider _counterSlider;
11-
private readonly ICommand _increaseCommand;
12-
private readonly ICommand _decreaseCommand;
11+
private readonly ICommand _incrementCommand;
12+
private readonly ICommand _decrementCommand;
1313

1414
public BindableCounterSliderWrapper(BindableCounterSlider counterSlider, IObjectProvider objectProvider)
1515
: base(objectProvider)
1616
{
1717
_counterSlider = counterSlider;
18-
_increaseCommand = GetCommand<ICommand>(counterSlider.IncreaseCommand);
19-
_decreaseCommand = GetCommand<ICommand>(counterSlider.DecreaseCommand);
18+
_incrementCommand = GetCommand<ICommand>(counterSlider.IncrementCommand);
19+
_decrementCommand = GetCommand<ICommand>(counterSlider.DecrementCommand);
2020
}
2121

22-
public bool CanInitialize => _increaseCommand != null && _decreaseCommand != null;
22+
public bool CanInitialize => _incrementCommand != null && _decrementCommand != null;
2323

2424
public void Initialize()
2525
{
26-
_counterSlider.Increase += OnIncrease;
27-
_counterSlider.Decrease += OnDecrease;
26+
_counterSlider.Increment += OnIncrement;
27+
_counterSlider.Decrement += OnDecrement;
2828
}
2929

3030
public void Dispose()
3131
{
32-
_counterSlider.Increase -= OnIncrease;
33-
_counterSlider.Decrease -= OnDecrease;
32+
_counterSlider.Increment -= OnIncrement;
33+
_counterSlider.Decrement -= OnDecrement;
3434
}
3535

36-
private void OnIncrease(object sender, EventArgs e)
36+
private void OnIncrement(object sender, EventArgs e)
3737
{
38-
_increaseCommand.Execute();
38+
_incrementCommand.Execute();
3939
}
4040

41-
private void OnDecrease(object sender, EventArgs e)
41+
private void OnDecrement(object sender, EventArgs e)
4242
{
43-
_decreaseCommand.Execute();
43+
_decrementCommand.Execute();
4444
}
4545
}
4646
}

samples/Unity.Mvvm.Counter/Assets/Scripts/BindableUIElements/BindableCounterSlider.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@ namespace BindableUIElements
66
{
77
public class BindableCounterSlider : CounterSlider, IBindableUIElement
88
{
9-
public string IncreaseCommand { get; set; }
10-
public string DecreaseCommand { get; set; }
9+
public string IncrementCommand { get; set; }
10+
public string DecrementCommand { get; set; }
1111

1212
public new class UxmlFactory : UxmlFactory<BindableCounterSlider, UxmlTraits>
1313
{
1414
}
1515

1616
public new class UxmlTraits : CounterSlider.UxmlTraits
1717
{
18-
private readonly UxmlStringAttributeDescription _increaseCommandAttribute = new()
19-
{ name = "increase-command", defaultValue = "" };
18+
private readonly UxmlStringAttributeDescription _incrementCommandAttribute = new()
19+
{ name = "increment-command", defaultValue = "" };
2020

21-
private readonly UxmlStringAttributeDescription _decreaseCommandAttribute = new()
22-
{ name = "decrease-command", defaultValue = "" };
21+
private readonly UxmlStringAttributeDescription _decrementCommandAttribute = new()
22+
{ name = "decrement-command", defaultValue = "" };
2323

2424
public override void Init(VisualElement visualElement, IUxmlAttributes bag, CreationContext context)
2525
{
2626
base.Init(visualElement, bag, context);
2727

2828
var bindableCounterSlider = (BindableCounterSlider) visualElement;
29-
bindableCounterSlider.IncreaseCommand = _increaseCommandAttribute.GetValueFromBag(bag, context);
30-
bindableCounterSlider.DecreaseCommand = _decreaseCommandAttribute.GetValueFromBag(bag, context);
29+
bindableCounterSlider.IncrementCommand = _incrementCommandAttribute.GetValueFromBag(bag, context);
30+
bindableCounterSlider.DecrementCommand = _decrementCommandAttribute.GetValueFromBag(bag, context);
3131
}
3232
}
3333
}

samples/Unity.Mvvm.Counter/Assets/Scripts/UIElements/CounterSlider.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ public CounterSlider()
2626
RegisterCallback<GeometryChangedEvent>(OnLayoutCalculated);
2727
}
2828

29-
public event EventHandler Increase
29+
public event EventHandler Increment
3030
{
31-
add => _manipulator.Increase += value;
32-
remove => _manipulator.Increase -= value;
31+
add => _manipulator.Increment += value;
32+
remove => _manipulator.Increment -= value;
3333
}
3434

35-
public event EventHandler Decrease
35+
public event EventHandler Decrement
3636
{
37-
add => _manipulator.Decrease += value;
38-
remove => _manipulator.Decrease -= value;
37+
add => _manipulator.Decrement += value;
38+
remove => _manipulator.Decrement -= value;
3939
}
4040

4141
private void CreateLabel(string labelName, string labelText)

samples/Unity.Mvvm.Counter/Assets/Scripts/UIElements/SliderManipulator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public SliderManipulator(VisualElement slider, VisualElement thumb)
2222
_thumb = thumb;
2323
}
2424

25-
public event EventHandler Increase;
26-
public event EventHandler Decrease;
25+
public event EventHandler Increment;
26+
public event EventHandler Decrement;
2727

2828
public void Initialize()
2929
{
@@ -77,11 +77,11 @@ private async UniTaskVoid EndThumbMove(Vector2 localPosition)
7777

7878
if (localPosition.x >= _increasePositionX)
7979
{
80-
Increase?.Invoke(this, EventArgs.Empty);
80+
Increment?.Invoke(this, EventArgs.Empty);
8181
}
8282
else if (localPosition.x <= _decreasePositionX)
8383
{
84-
Decrease?.Invoke(this, EventArgs.Empty);
84+
Decrement?.Invoke(this, EventArgs.Empty);
8585
}
8686
}
8787

samples/Unity.Mvvm.Counter/Assets/Scripts/ViewModels/CounterViewModel.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public class CounterViewModel : ViewModel
1111

1212
public CounterViewModel()
1313
{
14-
IncreaseCommand = new Command(IncreaseCount);
15-
DecreaseCommand = new Command(DecreaseCount);
14+
IncrementCommand = new Command(IncrementCount);
15+
DecrementCommand = new Command(DecrementCount);
1616
}
1717

1818
public int Count
@@ -27,17 +27,10 @@ public ThemeMode ThemeMode
2727
set => Set(ref _themeMode, value);
2828
}
2929

30-
public ICommand IncreaseCommand { get; }
31-
public ICommand DecreaseCommand { get; }
30+
public ICommand IncrementCommand { get; }
31+
public ICommand DecrementCommand { get; }
3232

33-
private void IncreaseCount()
34-
{
35-
Count++;
36-
}
37-
38-
private void DecreaseCount()
39-
{
40-
Count--;
41-
}
33+
private void IncrementCount() => Count++;
34+
private void DecrementCount() => Count--;
4235
}
4336
}

samples/Unity.Mvvm.Counter/Assets/UI Toolkit/CounterView.uxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
<BindableUIElements.BindableCountLabel text="25" binding-text-path="Count" class="count-label count-label--animation" />
99
</ui:VisualElement>
1010
<BindableUIElements.BindableThemeSwitcher binding-value-path="ThemeMode, Converter={ThemeModeToBoolConverter}" />
11-
<BindableUIElements.BindableCounterSlider increase-command="IncreaseCommand" decrease-command="DecreaseCommand" style="margin-bottom: 15%;" />
11+
<BindableUIElements.BindableCounterSlider increment-command="IncrementCommand" decrement-command="DecrementCommand" style="margin-bottom: 15%;" />
1212
</BindableUIElements.BindableContentPage>
1313
</ui:UXML>

0 commit comments

Comments
 (0)