Skip to content

Commit

Permalink
feat: add CreateFieldRaw(), CreateSliderRaw()
Browse files Browse the repository at this point in the history
  • Loading branch information
fuqunaga committed Jun 27, 2023
1 parent 937d473 commit 4c19757
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
12 changes: 7 additions & 5 deletions Packages/PrefsGUI.RosettaUI/Runtime/PrefsGUIExtensionField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ public static class PrefsGUIExtensionField
public static Element CreateElement<T>(this PrefsParamOuter<T> prefs, LabelElement label = null)
{
var element = UI.Row(
UI.Field(
label ?? UI.Label(() => prefs.key),
prefs.Get,
v => prefs.Set(v)
),
prefs.CreateFieldRaw(label ?? UI.Label(() => prefs.key)),
prefs.CreateDefaultButtonElement()
);

PrefsGUIExtension.SubscribeSyncedFlag(prefs, element);

return element;
}

public static Element CreateFieldRaw<T>(this PrefsParamOuter<T> prefs, LabelElement label = null)
{
return UI.Field(label, prefs.Get, v => prefs.Set(v));
}


public static Element CreateElement<TPrefs0, TPrefs1, TOuter0, TOuter1>(
this PrefsSet<TPrefs0, TPrefs1, TOuter0, TOuter1> prefs)
Expand Down
16 changes: 13 additions & 3 deletions Packages/PrefsGUI.RosettaUI/Runtime/PrefsGUIExtensionSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static Element CreateSlider<T>(this PrefsParamOuter<T> prefs, LabelElemen
public static Element CreateSlider<T>(this PrefsParamOuter<T> prefs, LabelElement label, IGetter<T> minGetter, IGetter<T> maxGetter)
{
var element = UI.Row(
_CreateSlider(prefs, label, minGetter, maxGetter),
CreateSliderRaw(prefs, label ?? UI.Label(() => prefs.key), minGetter, maxGetter),
prefs.CreateDefaultButtonElement()
);

Expand All @@ -49,10 +49,20 @@ public static Element CreateSlider<T>(this PrefsParamOuter<T> prefs, LabelElemen
return element;
}

private static Element _CreateSlider<T>(PrefsParamOuter<T> prefs, LabelElement label, IGetter<T> minGetter, IGetter<T> maxGetter)
public static Element CreateSliderRaw<T>(this PrefsParamOuter<T> prefs, LabelElement label, T max)
{
return CreateSliderRaw(prefs, label, default, max);
}

public static Element CreateSliderRaw<T>(this PrefsParamOuter<T> prefs, LabelElement label, T min, T max)
{
return CreateSliderRaw(prefs, label, ConstGetter.Create(min), ConstGetter.Create(max));
}

public static Element CreateSliderRaw<T>(this PrefsParamOuter<T> prefs, LabelElement label, IGetter<T> minGetter, IGetter<T> maxGetter)
{
return UI.Slider(
label ?? UI.Label(() => prefs.key),
label,
Binder.Create(prefs.Get, v => prefs.Set(v)),
minGetter,
maxGetter
Expand Down

0 comments on commit 4c19757

Please sign in to comment.