-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
233 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Packages/com.naukri.inspector-maid/Editor/Widgets/Visual/LabelWidget.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Packages/com.naukri.inspector-maid/Editor/Widgets/Visual/LabelWidget.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
Packages/com.naukri.inspector-maid/Runtime/RenameAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
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.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 15 additions & 42 deletions
57
Packages/com.naukri.inspector-maid/Samples/01. Widget's Attributes/Scripts/LabelSample.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { } | ||
} |
2 changes: 1 addition & 1 deletion
2
...ges/com.naukri.inspector-maid/Samples/01. Widget's Attributes/Scripts/LabelSample.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.