Skip to content

Commit

Permalink
Merge branch 'release/v2.12.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
naukri7707 committed Jan 29, 2024
2 parents f39d49b + d823a28 commit bdf4d0a
Show file tree
Hide file tree
Showing 15 changed files with 233 additions and 73 deletions.
22 changes: 20 additions & 2 deletions Packages/com.naukri.inspector-maid/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
# Changelog

## [2.12.0] - 2024-01-29

### 新增

- `Style` 新增 `BorderColorAll``borderColorVertical``borderColorHorizontal` 三種快捷屬性。
- 新增 `Label` 用以在 Inspector 上顯示文字。


### 更新

- `Label` 更名為 `Rename` 避免與 `Label` 元素產生混淆。

### 修正

- 修正 `Style` 部分 Horizontal 快捷屬性使用到 Vertical 值錯誤。


## [2.11.0] - 2024-01-23

### 新增
- Slot 現在可以同時插入多個成員。

- `Slot` 現在可以同時插入多個成員。

### 重構

- 調整 Group 風格,現在會固定在末元素的底部。
- 調整 `Group` 風格,現在會固定在末元素的底部。

## [2.10.1] - 2024-01-16

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using Naukri.InspectorMaid.Editor.Extensions;
using Naukri.InspectorMaid.Editor.Services;
using PlasticGui.Gluon.WorkspaceWindow.Views.IncomingChanges;
using UnityEditor;
using UnityEngine.UIElements;

namespace Naukri.InspectorMaid.Editor.Widgets.Stylers
{
public class LabelWidget : StylerWidgetOf<LabelAttribute>
public class RenameWidget : StylerWidgetOf<RenameAttribute>
{
public override string ClassName => "label-styler";
public override string ClassName => "rename-styler";

public override void OnStyling(IBuildContext context, VisualElement element)
{
Expand All @@ -26,7 +25,7 @@ public override void OnStyling(IBuildContext context, VisualElement element)
{
foreach (var labelElement in labelElements)
{
var labelText = labelElement.text.Replace(attribute.replaceText, attribute.label);
var labelText = labelElement.text.Replace(attribute.replaceText, attribute.text);
labelElement.text = ActualLabel(labelText);
if (attribute.minWidth != float.NaN)
{
Expand Down Expand Up @@ -58,7 +57,7 @@ public override void OnStyling(IBuildContext context, VisualElement element)

if (labelElement != null)
{
var labelText = attribute.label;
var labelText = attribute.text;

labelElement.text = ActualLabel(labelText);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ public class ButtonWidget : VisualWidgetOf<ButtonAttribute>
{
public override VisualElement Build(IBuildContext context)
{
var classWidget = ClassWidget.Of(context);
var serializedTarget = classWidget.serializedTarget;

void buttonAction()
{
if (attribute.setDirty)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Naukri.InspectorMaid.Editor.Extensions;
using Naukri.InspectorMaid.Editor.Services;
using UnityEngine.UIElements;

namespace Naukri.InspectorMaid.Editor.Widgets.Visual
{
public class LabelWidget : VisualWidgetOf<LabelAttribute>
{
public override VisualElement Build(IBuildContext context)
{
var label = new Label()
{
text = attribute.text
};

if (attribute.IsBinding())
{
context.ListenBindingValue<string>(message =>
{
label.text = message;
});
}

return label;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 4 additions & 16 deletions Packages/com.naukri.inspector-maid/Runtime/LabelAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,20 @@

namespace Naukri.InspectorMaid
{
public class LabelAttribute : StylerAttribute, IBindingDataProvider
public class LabelAttribute : ItemAttribute, IBindingDataProvider
{
public LabelAttribute(
string label = "",
string replaceText = null,
float minWidth = float.NaN,
bool useNicifyName = false,
string text = "",
string binding = null,
object[] args = null
)
{
this.label = label;
this.replaceText = replaceText;
this.minWidth = minWidth;
this.useNicifyName = useNicifyName;
this.text = text;
this.binding = binding;
this.args = args;
}

public readonly string label;

public readonly string replaceText;

public readonly float minWidth;

public readonly bool useNicifyName;
public readonly string text;

public object[] args { get; }

Expand Down
36 changes: 36 additions & 0 deletions Packages/com.naukri.inspector-maid/Runtime/RenameAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Naukri.InspectorMaid.Core;

namespace Naukri.InspectorMaid
{
public class RenameAttribute : StylerAttribute, IBindingDataProvider
{
public RenameAttribute(
string text = "",
string replaceText = null,
float minWidth = float.NaN,
bool useNicifyName = false,
string binding = null,
object[] args = null
)
{
this.text = text;
this.replaceText = replaceText;
this.minWidth = minWidth;
this.useNicifyName = useNicifyName;
this.binding = binding;
this.args = args;
}

public readonly string text;

public readonly string replaceText;

public readonly float minWidth;

public readonly bool useNicifyName;

public object[] args { get; }

public string binding { get; }
}
}
11 changes: 11 additions & 0 deletions Packages/com.naukri.inspector-maid/Runtime/RenameAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 38 additions & 3 deletions Packages/com.naukri.inspector-maid/Runtime/StyleAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public StyleAttribute(
string borderWidthAll = null,
string borderWidthVertical = null,
string borderWidthHorizontal = null,
// - BorderColor
string borderColorAll = null,
string borderColorVertical = null,
string borderColorHorizontal = null,
// - Margin
string margin = null,
string marginAll = null,
Expand Down Expand Up @@ -212,7 +216,7 @@ ref this.borderLeftWidth
}
if (borderWidthHorizontal != null)
{
var borderWidthHorizontalValue = StyleStringConverter.ToStyleFloat(borderWidthVertical);
var borderWidthHorizontalValue = StyleStringConverter.ToStyleFloat(borderWidthHorizontal);
if (borderWidthHorizontalValue != null)
{
this.borderLeftWidth = borderWidthHorizontalValue;
Expand All @@ -222,6 +226,37 @@ ref this.borderLeftWidth

#endregion -- BorderWidth --

#region -- BorderColor --

if (borderColorAll != null)
{
var borderColorAllValue = StyleStringConverter.ToStyleColor(borderColorAll);
this.borderTopColor = borderColorAllValue;
this.borderRightColor = borderColorAllValue;
this.borderBottomColor = borderColorAllValue;
this.borderLeftColor = borderColorAllValue;
}
if (borderColorVertical != null)
{
var borderColorVerticalValue = StyleStringConverter.ToStyleColor(borderColorVertical);
if (borderColorVerticalValue != null)
{
this.borderTopColor = borderColorVerticalValue;
this.borderBottomColor = borderColorVerticalValue;
}
}
if (borderColorHorizontal != null)
{
var borderColorHorizontalValue = StyleStringConverter.ToStyleColor(borderColorHorizontal);
if (borderColorHorizontalValue != null)
{
this.borderLeftColor = borderColorHorizontalValue;
this.borderRightColor = borderColorHorizontalValue;
}
}

#endregion -- BorderColor --

#region -- Margin --

if (margin != null)
Expand Down Expand Up @@ -254,7 +289,7 @@ ref this.marginLeft
}
if (marginHorizontal != null)
{
var marginHorizontalValue = StyleStringConverter.ToStyleLength(marginVertical);
var marginHorizontalValue = StyleStringConverter.ToStyleLength(marginHorizontal);
if (marginHorizontalValue != null)
{
this.marginLeft = marginHorizontalValue;
Expand Down Expand Up @@ -296,7 +331,7 @@ ref this.paddingLeft
}
if (paddingHorizontal != null)
{
var paddingHorizontalValue = StyleStringConverter.ToStyleLength(paddingVertical);
var paddingHorizontalValue = StyleStringConverter.ToStyleLength(paddingHorizontal);
if (paddingHorizontalValue != null)
{
this.paddingLeft = paddingHorizontalValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,27 @@
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.UIElements;

namespace Naukri.InspectorMaid.Samples.WidgetAttributes
{
public partial class LabelSample : AttributeSampleBehaviour
{
// Sample 1
[Target, Label("newLabel")]
public int useLabel;

[Target, Label("newLabelWithNicifyName", useNicifyName: true)]
public int useLabelWithNicifyName;

// Sample 2
[Target, Label(binding: nameof(bindingMessage))]
public string bindingMessage = "change me!";
[Label("My Label")]
public int simple;

// Sample 3
[Label("Simply rename", useNicifyName: true)]
public int renameTarget;

// Sample 3
[Label("Min", replaceText: "X", minWidth: 30)]
[Label("Max", replaceText: "Y", minWidth: 30)]
public Vector2 renameBySubString;
[Label("My Label", binding: nameof(bindingWithString))]
public string bindingWithString = "change me!";
}

[
HelpBox(@"[Label] will change lastest widget's first descendant label.
This is useful when we want to rename the target's prefix label.", HelpBoxMessageType.Info),
// Sample 1
GroupScope("01. Label"),
CardSlot(nameof(useLabel)),
CardSlot(nameof(useLabelWithNicifyName)),
EndScope,
// Sample 2
GroupScope("02. Label with binding"),
HelpBox("You can also change target's label dynamically by binding.", HelpBoxMessageType.Info),
CardSlot(nameof(bindingMessage)),
EndScope,
// Sample 3
GroupScope("03. Simpify trick"),
HelpBox(@"If there is no widget before the styler, the styler will modify the [MemberWidget] (a simple container of all widgets in this member).
So if you don't have any other widget, and only want to change the prefix label of [Target], you can simply add [Label] to the member.", HelpBoxMessageType.Info),
CardSlot(nameof(renameTarget)),
EndScope,
GroupScope("04. Rename By Sub String"),
HelpBox(@"If the Label you want to rename is not the first label, you can use 'replaceText' to define the string to replace. In this mode, any string in a label that contains the specified substring will be replaced.", HelpBoxMessageType.Info),
CardSlot(nameof(renameBySubString)),
EndScope,
HelpBox("[Label] can show any text on the inspector.", HelpBoxMessageType.Info),
// Sample 1
GroupScope("01. Label", true),
CardSlot(nameof(simple)),
EndScope,
// Sample 2
GroupScope("02. Label with binding", true),
HelpBox("[Label] can also use binding to show dynamic text.", HelpBoxMessageType.Info),
CardSlot(nameof(bindingWithString)),
EndScope,
]
partial class LabelSample { }
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bdf4d0a

Please sign in to comment.