1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-02-11 17:48:46 +08:00

Fixed menu item naming

Added min/maxwidth options
This commit is contained in:
Kailey Joanette 2021-12-26 15:07:00 -05:00
parent 3666509002
commit 840eb7818d

View File

@ -8,6 +8,9 @@ namespace XNodeEditor
{ {
public class AdvancedGenericMenu : AdvancedDropdown public class AdvancedGenericMenu : AdvancedDropdown
{ {
public static float? DefaultMinWidth = 200f;
public static float? DefaultMaxWidth = 300f;
private class AdvancedGenericMenuItem : AdvancedDropdownItem private class AdvancedGenericMenuItem : AdvancedDropdownItem
{ {
private MenuFunction func; private MenuFunction func;
@ -67,13 +70,13 @@ namespace XNodeEditor
{ {
item = items.FirstOrDefault( x => x != null && x.name == paths[0] ); item = items.FirstOrDefault( x => x != null && x.name == paths[0] );
if ( item == null ) if ( item == null )
items.Add( item = new AdvancedGenericMenuItem( name ) ); items.Add( item = new AdvancedGenericMenuItem( paths[0] ) );
} }
else else
{ {
item = currentRoot.children.OfType<AdvancedGenericMenuItem>().FirstOrDefault( x => x.name == paths[0] ); item = currentRoot.children.OfType<AdvancedGenericMenuItem>().FirstOrDefault( x => x.name == paths[0] );
if ( item == null ) if ( item == null )
currentRoot.AddChild( item = new AdvancedGenericMenuItem( name ) ); currentRoot.AddChild( item = new AdvancedGenericMenuItem( paths[0] ) );
} }
if ( paths.Length > 1 ) if ( paths.Length > 1 )
@ -179,6 +182,8 @@ namespace XNodeEditor
// The position at which to show the menu. // The position at which to show the menu.
public void DropDown( Rect position ) public void DropDown( Rect position )
{ {
position.width = Mathf.Clamp( position.width, DefaultMinWidth.HasValue ? DefaultMinWidth.Value : 1f, DefaultMaxWidth.HasValue ? DefaultMaxWidth.Value : Screen.width );
Show( position ); Show( position );
} }