Skip to content

Commit

Permalink
Fix a bug that the methods of the GradientSynchronizer is not called …
Browse files Browse the repository at this point in the history
…properly
  • Loading branch information
Haruma-K committed Apr 14, 2024
1 parent 4989fb9 commit f4c8d1f
Show file tree
Hide file tree
Showing 19 changed files with 15 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,13 @@ protected override void CellGUI(int columnIndex, Rect cellRect, RowGUIArgs args)
else
{
var themeId = _columnIndexToThemeIdMap[columnIndex];
item.Values[themeId].Value = DrawValueField(cellRect, item.Values[themeId].Value);
// For Gradient, use SetValueAndNotify to notify the change.
using (var ccs = new EditorGUI.ChangeCheckScope())
{
var newValue = DrawValueField(cellRect, item.Values[themeId].Value);
if (ccs.changed)
item.Values[themeId].SetValueAndNotify(newValue);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ void ObserveItemValue(KeyValuePair<string, ObservableProperty<T>> value)
{
var oldValue = entry.Values[themeId].Value;
_editService.Edit($"Set {typeof(T).Name} Entry Value {entry.Id}",
() => { entry.Values[themeId].Value = x; },
() => { entry.Values[themeId].Value = oldValue; });
() => { entry.Values[themeId].SetValueAndNotify(x); },
() => { entry.Values[themeId].SetValueAndNotify(oldValue); });
}).DisposeWith(disposables);
}

Expand Down
8 changes: 4 additions & 4 deletions Assets/uPalette/Runtime/Core/Model/Palette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void ISerializationCallbackReceiver.OnAfterDeserialize()
var value = entry.Values[activeThemeId];
var colorProperty = new ObservableProperty<T>();
_activeValues[entry.Id] = colorProperty;
value.Subscribe(x => { colorProperty.Value = x; })
value.Subscribe(x => { colorProperty.SetValueAndNotify(x); })
.DisposeWith(_activeThemeDisposables);
}

Expand Down Expand Up @@ -117,7 +117,7 @@ public void SetActiveTheme(string themeId)
{
var valueProperty = _activeValues[entry.Id];
entry.Values[themeId]
.Subscribe(x => valueProperty.Value = x)
.Subscribe(x => valueProperty.SetValueAndNotify(x))
.DisposeWith(_activeThemeDisposables);
}

Expand Down Expand Up @@ -284,7 +284,7 @@ internal Entry<T> AddEntry(string id)
{
var colorProperty = new ObservableProperty<T>();
_activeValues[entry.Id] = colorProperty;
value.Subscribe(x => { colorProperty.Value = x; })
value.Subscribe(x => { colorProperty.SetValueAndNotify(x); })
.DisposeWith(_activeThemeDisposables);
}
}
Expand Down Expand Up @@ -356,7 +356,7 @@ public Entry<T> RestoreEntry(string removedEntryId)
{
var colorProperty = new ObservableProperty<T>();
_activeValues[removedEntry.Id] = colorProperty;
value.Subscribe(x => { colorProperty.Value = x; })
value.Subscribe(x => { colorProperty.SetValueAndNotify(x); })
.DisposeWith(_activeThemeDisposables);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,13 @@ protected internal override Foundation.CharacterStyles.CharacterStyle GetValue()
lineSpacing = Component.lineSpacing
};
}

private static int _latestRepaintFrame;


protected internal override void SetValue(Foundation.CharacterStyles.CharacterStyle value)
{
Component.font = value.font;
Component.fontStyle = value.fontStyle;
Component.fontSize = value.fontSize;
Component.lineSpacing = value.lineSpacing;
}

protected override bool EqualsToCurrentValue(Foundation.CharacterStyles.CharacterStyle value)
{
if (Component.font != value.font
|| Component.fontStyle != value.fontStyle
|| Component.fontSize != value.fontSize
|| Component.lineSpacing != value.lineSpacing)
return false;

return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ namespace uPalette.Runtime.Core.Synchronizer.CharacterStyleTMP
[CharacterStyleTMPSynchronizer(typeof(TextMeshProUGUI), "Character Style")]
public sealed class TextMeshProUGUICharacterStyleTMPSynchronizer : CharacterStyleTMPSynchronizer<TextMeshProUGUI>
{
private static int _latestRepaintFrame;

protected internal override Foundation.CharacterStyles.CharacterStyleTMP GetValue()
{
return new Foundation.CharacterStyles.CharacterStyleTMP
Expand Down Expand Up @@ -46,30 +44,5 @@ protected internal override void SetValue(Foundation.CharacterStyles.CharacterSt
Component.lineSpacing = value.lineSpacing;
Component.paragraphSpacing = value.paragraphSpacing;
}

protected override bool EqualsToCurrentValue(Foundation.CharacterStyles.CharacterStyleTMP value)
{
if (Component.font != null && Component.font.sourceFontFile != value.font.sourceFontFile)
{
return false;
}

var isNotEquals = Component.fontStyle != value.fontStyle
|| Component.enableAutoSizing != value.enableAutoSizing
|| Component.fontSize != value.fontSize
|| Component.characterSpacing != value.characterSpacing
|| Component.wordSpacing != value.wordSpacing
|| Component.lineSpacing != value.lineSpacing
|| Component.paragraphSpacing != value.paragraphSpacing;

if (value.enableAutoSizeOptions)
isNotEquals = isNotEquals
|| Component.fontSizeMin != value.fontSizeMin
|| Component.fontSizeMax != value.fontSizeMax
|| Component.characterWidthAdjustment != value.characterWidthAdjustment
|| Component.lineSpacingAdjustment != value.lineSpacingAdjustment;

return !isNotEquals;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,5 @@ protected internal override void SetValue(UnityEngine.Color value)
{
Component.color = value;
}

protected override bool EqualsToCurrentValue(UnityEngine.Color value)
{
return Component.color == value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,5 @@ protected internal override void SetValue(UnityEngine.Color value)
Component.customCaretColor = true;
Component.caretColor = value;
}

protected override bool EqualsToCurrentValue(UnityEngine.Color value)
{
return Component.caretColor == value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,5 @@ protected internal override void SetValue(UnityEngine.Color value)
{
Component.selectionColor = value;
}

protected override bool EqualsToCurrentValue(UnityEngine.Color value)
{
return Component.selectionColor == value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,5 @@ protected internal override void SetValue(UnityEngine.Color value)
{
Component.effectColor = value;
}

protected override bool EqualsToCurrentValue(UnityEngine.Color value)
{
return Component.effectColor == value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,5 @@ protected internal override void SetValue(UnityEngine.Color value)
colors.disabledColor = value;
Component.colors = colors;
}

protected override bool EqualsToCurrentValue(UnityEngine.Color value)
{
return Component.colors.disabledColor == value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,5 @@ protected internal override void SetValue(UnityEngine.Color value)
colors.highlightedColor = value;
Component.colors = colors;
}

protected override bool EqualsToCurrentValue(UnityEngine.Color value)
{
return Component.colors.highlightedColor == value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,5 @@ protected internal override void SetValue(UnityEngine.Color value)
colors.normalColor = value;
Component.colors = colors;
}

protected override bool EqualsToCurrentValue(UnityEngine.Color value)
{
return Component.colors.normalColor == value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,5 @@ protected internal override void SetValue(UnityEngine.Color value)
colors.pressedColor = value;
Component.colors = colors;
}

protected override bool EqualsToCurrentValue(UnityEngine.Color value)
{
return Component.colors.pressedColor == value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,5 @@ protected internal override void SetValue(UnityEngine.Color value)
colors.selectedColor = value;
Component.colors = colors;
}

protected override bool EqualsToCurrentValue(UnityEngine.Color value)
{
return Component.colors.selectedColor == value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,5 @@ protected internal override void SetValue(UnityEngine.Color value)
Component.customCaretColor = true;
Component.caretColor = value;
}

protected override bool EqualsToCurrentValue(UnityEngine.Color value)
{
return Component.caretColor == value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,5 @@ protected internal override void SetValue(UnityEngine.Color value)
{
Component.selectionColor = value;
}

protected override bool EqualsToCurrentValue(UnityEngine.Color value)
{
return Component.selectionColor == value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ public abstract class ValueSynchronizer<T> : ValueSynchronizerBase<T>

protected internal abstract void SetValue(T value);

protected abstract bool EqualsToCurrentValue(T value);

protected override void OnValueChanged(T value)
{
if (!EqualsToCurrentValue(value))
SetValue(value);
SetValue(value);
}
}
}
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,6 @@ public sealed class GraphicColorSynchronizer : GradientSynchronizer<SampleGradie
{
_component.Gradient = value;
}

protected override bool EqualsToCurrentValue(Gradient value)
{
return _component.Gradient.Equals(value);
}
}
```

Expand Down
5 changes: 0 additions & 5 deletions README_JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,6 @@ public sealed class GraphicColorSynchronizer : GradientSynchronizer<SampleGradie
{
_component.Gradient = value;
}

protected override bool EqualsToCurrentValue(Gradient value)
{
return _component.Gradient.Equals(value);
}
}
```

Expand Down

0 comments on commit f4c8d1f

Please sign in to comment.