Search Unity

New UI Widgets

Discussion in 'Assets and Asset Store' started by ilih, Feb 11, 2015.

  1. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    Wrong order or missed gameobject in SteamSpyComponent.ObjectsToResize
    ObjectsToResize should return gameobjects in original order.
    Code (CSharp):
    1.         public GameObject[] ObjectsToResize {
    2.             get {
    3.                 return new GameObject[] {
    4.                     Name.transform.parent.gameObject,
    5.                     Flag.transform.parent.gameObject,// should be in second place, if first screenshot with original order
    6.                     ScoreRank.transform.parent.gameObject,
    7.                     Owners.transform.parent.gameObject,
    8.                     Players.transform.parent.gameObject,
    9.                     PlayersIn2Week.transform.parent.gameObject,
    10.                     TimeIn2Week.transform.parent.gameObject,
    11.                 };
    12.             }
    13.         }
     
  2. Aston-Martin

    Aston-Martin

    Joined:
    Jul 5, 2012
    Posts:
    64
    Spend a few hours and couldn't find the fault.
    You post have solved the issue. thank you!
     
  3. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    I have a request. I like the buttons you have in the example scene. Can you add them to the list as "UIWidget Button" so I can just drop them down as needed?
     
  4. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    I have another request. I own UniFileBrowser. I would love to have a New UI Widgets version to go along with my other dialogs using you asset.
     
  5. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    Ok.

    I'm not sure that this is possible - UniFileBrowser probably use legacy GUI which cannot be used together with current UI System.
    But I have plans add own file browser.
     
    Last edited: Feb 4, 2016
  6. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    That's what I meant. I want a replacement for it. I meant that I would like at least the same functionality, but using your framework. I'm glad to hear you are planning on it. Thanks.
     
  7. johanneskopf

    johanneskopf

    Joined:
    Feb 16, 2015
    Posts:
    81
    Hey,
    Is there a script that makes Elements fit into the frame?
    So take e.g. the Harbor Shop Template, and if I change the size of the buttons at the end, is there something that automatically makes the listview smaller so that they fit? So if I have one container with a fixed size, and one container with a variable size, I want to change the fixed size one and the variable sized should change automatically.

    And if I change the size e.g. for the buttons at the end. I have to reselect their parent (with the EasyLayout on it) so that it's updating the layout. Isn't there a behavior that's updating immediately after changes - I want to see what my changes are doing without having to click on the parent each time.

    Edit:
    Something else that occured while implementing the Harbor Shop:
    The Slider are at the beginning at the wrong position. Maybe I made some mistakes in my code? How to update them on init? Currently the slider position only gets updatet when I move them for the first time. (In the picture, the first on is currently selected and moved, therefore at the right position).

    And if I change the steps value on the centered slider, it ignores this. I want to slide 1, 10 or 100 at once, but it's always sliding only 1.

    Thanks in advance, John
     

    Attached Files:

    Last edited: Feb 5, 2016
  8. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    Add LayoutElement to each, for fixed size specify MinWidth and FlexibleWidth=0, for variable size specify Flexible width = 9999 (or any other big number). EasyLayout should have Children Width = Fit Container

    It should be updated immediately. What Unity version? Horizontal and Vertical Layout Groups updated immediately?

    Fix:
    CenteredSliderBase.cs
    • Replace line 10:
      Code (CSharp):
      1.     public abstract class CenteredSliderBase<T> : UIBehaviour, IPointerClickHandler
    • Add function
      Code (CSharp):
      1.         protected override void OnRectTransformDimensionsChange()
      2.         {
      3.             UpdateHandle();
      4.             UpdateFill();
      5.         }

    Enable "Whole number of steps", by default step only applied when handle moved with keyboard or gamepad.
     
    johanneskopf likes this.
  9. johanneskopf

    johanneskopf

    Joined:
    Feb 16, 2015
    Posts:
    81
    Thanks for the answers!

    Slider is working fine with that changes, great!! Big thanks! :D

    Made a new project, put only your asset into it, opened the example scene, selected the "Harbor Shop content", enabled it, and tried resizing the "TradeContainer" by changing it's height. The (easy) layout only gets updated when I select the parent named "Content".
    I am using Unity 5.3.2f1 and the latest version of your UI Widgets.

    Edit: When I change the layout element's min width inside the Horizontal Layout Group (="Header" for instance with it's child layout elements "Name", "SellPrice" and so) it is updating itself as it should.

    Edit 2: Added capture, showing the result of trying to do what you said, but done with "height" insead of width.
    So i set at the parent the fit-container in the easy layout and added a Layout Element to every child, then set the min/flexible height to 0. This ends up like you see in the caputre.png.
    Tried changed the flexbile height to 50 (min height isn't changing anything here), then this elements get a little bit bigger, but nowhere to a size of 50. It then has a height of 5 instead of 1. Maybe this is due to the flexible height of 9999 of the listview?
    Oh.. just got it: the sum of all flexible heights together (of the child elments) is the overall percentage of the height each element gets. So if I give the listview a flexible height of 6 and another child a flex. height of 4, then they have 60% and 40% of the height of the container.
    Is this right? Because if I set the minimal height and flexible height to 0, it's not possible for me to change the height, because it's grayed out. Therefore it's this way to go?

    Edit 3: Tried to add another child with a Layout Element, same settings (eg. flex/min height = 1), then this element gets bigger if i change the font size. (But it should be always the same percentage, if it's working like I thought).

    And this error is occuring now very often:
    Code (CSharp):
    1. Trying to add (Layout Rebuilder for) ScrollRect (UnityEngine.RectTransform) for layout rebuild while we are already inside a layout rebuild loop. This is not supported.
    2. UnityEngine.RectTransform:SetSizeWithCurrentAnchors(Axis, Single)
    3. EasyLayout.EasyLayout:ResizeChild(RectTransform) (at Assets/Plugins/UIWidgets/Standart Assets/EasyLayout/EasyLayout.cs:973)
    4. System.Collections.Generic.List`1:ForEach(Action`1)
    5. EasyLayout.EasyLayout:ResizeElements(List`1) (at Assets/Plugins/UIWidgets/Standart Assets/EasyLayout/EasyLayout.cs:815)
    6. EasyLayout.EasyLayout:GetUIElements() (at Assets/Plugins/UIWidgets/Standart Assets/EasyLayout/EasyLayout.cs:1015)
    7. EasyLayout.EasyLayout:GroupUIElements() (at Assets/Plugins/UIWidgets/Standart Assets/EasyLayout/EasyLayout.cs:1072)
    8. EasyLayout.EasyLayout:RepositionUIElements() (at Assets/Plugins/UIWidgets/Standart Assets/EasyLayout/EasyLayout.cs:552)
    9. EasyLayout.EasyLayout:SetLayoutHorizontal() (at Assets/Plugins/UIWidgets/Standart Assets/EasyLayout/EasyLayout.cs:439)
    10. UnityEditor.DockArea:OnGUI()

    Please help me figuring this. :)
     

    Attached Files:

    Last edited: Feb 5, 2016
  10. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    Made some tests - Unity updates layout when RectTransform changed only if gameobject have Graphic (or maybe ICanvasElement) component. So layout not updated when RectTransform changed on empty gameobject.
    Workaround - add image with transparent color.

    Only if MinHeight=0 and PreferredHeight=0 for each element.
    Usually it mean 60% and 40% of free space = height of the container - sum(max(preferred height, min height))

    Found misprint in EasyLayout.cs
    Replace GetPreferredWidth on GetPreferredHeight. in GetMaxPreferredHeight.
    Code (CSharp):
    1.         float GetMaxPreferredHeight(List<RectTransform> column)
    2.         {
    3.             return column.Max<RectTransform,float>(GetPreferredHeight);
    4.         }
    It's bug in Unity 5.3, should be fixed in 5.3.2p1 (I'm not check it yet).
     
    johanneskopf likes this.
  11. johanneskopf

    johanneskopf

    Joined:
    Feb 16, 2015
    Posts:
    81
    Got everything corresponding the layout working now as expected, thanks for that! Really like your EasyLayout stuff!! :cool:
    Unity should have this functionality built-in! It's great!
    Installed the patch release, and haven't seen the error again, perfect. ;)

    Three question left:

    Changing the value of the slider in the harbor shop is not possible with clicking, but in the Slider and Spinner Demo it is.
    It's only possible through dragging. Maybe a problem with the focus?

    How to init the data again and don't update the scroll sliders position?
    Each day in game I want to update my prices/amount -> the list view data, and this shouldn't change the slider values.
    Only problem I see upcoming is that if there's less amount avaible after set the new data, then the slider's value has to degree as well. :confused:

    Is there a way to let the double-sided-slider only travel as far as one can afford? So if there are 100 pieces in stock, and I can afford only 60, let the slider only travel till 60?
     
    Last edited: Feb 5, 2016
  12. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    IPointerDownHandler (DefaultItem) have more priority than IPointerClickHandler (Slider) and this is reason why click don't work.
    Fix:
    CenteredSliderBase.cs
    • Replace line 10:
      Code (CSharp):
      1.     public abstract class CenteredSliderBase<T> : UIBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler
      2.  
    • Add functions
      Code (CSharp):
      1.         public void OnPointerDown (PointerEventData eventData)
      2.         {
      3.         }
      4.  
      5.         public void OnPointerUp (PointerEventData eventData)
      6.         {
      7.         }

    I see two ways to do this:
    • Save scroll position and restore it after update:
      Code (CSharp):
      1.             var position = (TradeView.Container as RectTransform).anchoredPosition;
      2.             // update prices/amount
      3.             (TradeView.Container as RectTransform).anchoredPosition = position;
      4.  
    • Or convert prices and amount to properties, add OnChange event, attach listener to OnChange from component.
      But this way cannot work with removing or adding items to list.
      Something like this:
      HarborOrderLine.cs
      Code (CSharp):
      1.         [SerializeField]
      2.         [UnityEngine.Serialization.FormerlySerializedAs("SellPrice")]
      3.         int sellPrice;
      4.  
      5.         public int SellPrice {
      6.             get {
      7.                 return sellPrice;
      8.             }
      9.             set {
      10.                 sellPrice = value;
      11.                 Changed();
      12.             }
      13.         }
      14.  
      15.         public OnChange OnChange;
      16.  
      17.         void Changed()
      18.         {
      19.             if (OnChange!=null)
      20.             {
      21.                 OnChange();
      22.             }
      23.         }
      HarborListViewComponent.cs
      Code (CSharp):
      1.        HarborOrderLine orderLine;
      2.  
      3.         public HarborOrderLine OrderLine {
      4.             get {
      5.                 return orderLine;
      6.             }
      7.             set {
      8.                 if (orderLine!=null)
      9.                 {
      10.                     orderLine.OnChange -= UpdateData;
      11.                 }
      12.                 orderLine = value;
      13.                 if (orderLine!=null)
      14.                 {
      15.                     orderLine.OnChange += UpdateData;
      16.                 }
      17.             }
      18.         }
      19.  
      20.         public void UpdateData()
      21.         {
      22.             SellPrice.text = orderLine.SellPrice.ToString();
      23.         }

    For now it's possible with CenteredSlider.OnValuesChange event.
    HarborListViewComponent.cs
    Code (CSharp):
    1.         void ChangeCount(int value)
    2.         {
    3.             int max = OrderLine.MaxBuy;//60
    4.             if (value > max)
    5.             {
    6.                 Count.Value = max;
    7.             }
    8.             else
    9.             {
    10.                 OrderLine.Count = value;
    11.             }
    12.         }
     
    johanneskopf likes this.
  13. johanneskopf

    johanneskopf

    Joined:
    Feb 16, 2015
    Posts:
    81
    That sliders are now working like a charme! :D
    Thanks again for your fast and great answer! Sorry to bother you again:

    That first way you mentioned for saving the scroll position is for the vertical scroll I see.
    But I meant the sliders current position. And for sure your 2nd method will work. But while changing my code, I got stuck here:

    When using your ObservableList, it's showing an error when looping through it using foreach.
    Using a normal for-loop seems to fix that, but I have used foreach nearly everywhere in my code, maybe you can fix this?
    Code (CSharp):
    1. // working
    2. public List<StockPlace> StockPlaces;
    3. // not working
    4. public UIWidgets.ObservableList<StockPlace> StockPlaces;
    5.  
    6. public void DoStuff()
    7. {
    8.   foreach (var st in StockPlaces)
    9.     CalculateNextDayliAmount(st, steps);
    10. }
    Showing this error:
    Code (CSharp):
    1. Assets/Script/WorldBehavior/IslandBehavior.cs(53,13): error CS1503: Argument `#1' cannot convert `object' expression to type `StockPlace'
    So it's getting object's in the foreach. Is the IEnumerator of ObservableList returning them wrong?

    And it's not necessary that in ObservableList.cs it is having the interface IList<T>, because IObservableList<T> is already implementing that. Is that right?

    Layout specific:
    I tried to add an icon and resize the listview's default item. In the editor it's showing as an item that needs 2 lines (attached picture), although it should fit (the first item is the flexible item, and I can change it's min width to what I want, nevertheless it's putting it in the second line.
    If I start the game, it's showing fine, maybe something is smaller then?
     

    Attached Files:

  14. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    I think should be more errors. not only CS1503.
    What is line 53?
    Try foreach with specified type:
    Code (CSharp):
    1. foreach (StockPlace st in StockPlaces)
    Missed new can cause error:
    Code (CSharp):
    1.         StockPlaces.Add(StockPlace());
    2.         CalculateNextDayliAmount(StockPlace(), steps);
    Yes.

    Text (and some other elements) have own Layout Properties. Probably Text.PreferredWidth more than LayoutElement.MinWidth.
    Set LayoutElement.PreferredWidth = 0 or same as MinWidth
     
    johanneskopf likes this.
  15. tapticc

    tapticc

    Joined:
    Jan 16, 2014
    Posts:
    379
    Hi, I'm having trouble finding a nice looking GUI asset which I can easily create a series of sliders with values from say 0-100, with the sliders in a scrollable list and where you can use a controller to scroll up and down the list, left and right to amend slider values.

    The slider screenshot has a min and max range, I'm assuming you can have a single value slider?

    Would your asset be able to create a scrollable list of sliders (thinking upto maybe 50 sliders but you can only view 10 at once within a panel so need to be able to scroll)?

    thanks :)
     
  16. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    No, Unity already have Slider.

    Yes, but for controller support you need to override DefaultItem Component.OnMove, otherwise scroll up and down will not work.

    Something like this:
    Code (CSharp):
    1. using UnityEngine.UI;
    2. using UnityEngine.EventSystems;
    3. using UIWidgets;
    4.  
    5. namespace UIWidgetsSamples {
    6.     public class ListViewSliderComponent : ListViewItem {
    7.         public Slider Slider;
    8.  
    9.         public void SetData(ListViewSliderItem item)
    10.         {
    11.             Slider.value = item.Value;
    12.         }
    13.  
    14.         public override void OnMove(AxisEventData eventData)
    15.         {
    16.             switch (eventData.moveDir)
    17.             {
    18.                // left and right to change slider values
    19.                 case MoveDirection.Left:
    20.                 case MoveDirection.Right:
    21.                     Slider.OnMove(eventData);
    22.                     break;
    23.                // up and down to scroll list
    24.                 default:
    25.                     base.OnMove(eventData);
    26.                     break;
    27.             }
    28.         }
    29.     }
    30. }
     
    tapticc likes this.
  17. tapticc

    tapticc

    Joined:
    Jan 16, 2014
    Posts:
    379
    Thanks for this :)
     
  18. johanneskopf

    johanneskopf

    Joined:
    Feb 16, 2015
    Posts:
    81
    Hey,
    Thanks again for a great answer from you! :)
    That did the trick for me:
    Code (CSharp):
    1.     foreach (StockPlace st in StockPlaces)
    2.  
    But do you know why "var" is not possible (why the foreach is returning objects)?

    Now I understand how the layout works. Maybe this is something you should mention in the docs, how the layout is working.

    Was it intended that the slider's of the listview-items forget their value if you scroll down enough that they are not visible and scroll up again?
    This can be tested by opening the samples, changing the height of the DefaultItem of the HarborListView, and do what i said.
    If not, here is the line of code to change:

    HarborListViewComponent.cs

    Code (CSharp):
    1. public void SetData(HarborOrderLine orderLine)
    2.         {
    3.             OrderLine = orderLine;
    4.            
    5.             Name.text = OrderLine.Item.Name;
    6.  
    7.             BuyPrice.text = OrderLine.BuyPrice.ToString();
    8.             SellPrice.text = OrderLine.SellPrice.ToString();
    9.  
    10.             AvailableBuyCount.text = OrderLine.BuyCount.ToString();
    11.             AvailableSellCount.text = OrderLine.SellCount.ToString();
    12.  
    13.             // not working
    14.             //Count.Value = 0;
    15.             // working
    16.             Count.Value = OrderLine.Count
    17.             Count.LimitMin = -OrderLine.SellCount;
    18.             Count.LimitMax = OrderLine.BuyCount;
    19.         }
     
  19. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    I don't know, maybe some problem in Mono with type inference.

    Ok, try to add it in documentation.

    It's a bug. Thanks.
     
  20. johanneskopf

    johanneskopf

    Joined:
    Feb 16, 2015
    Posts:
    81
    That would be great. You're a good programmer and you created a good software. Therefore it deserves a fantastic documentation, to use it like it's intended to be used.

    Found another one. It's nearly the same as the previous. If you buy something, then set the slider to a negative value (sell), then scroll down and up again, the slider position is set the zero again.
    How to prevent it this time? I wasn't able to figure that out.

    And is this correct even for the two sided Slider (it gets a negative count, or?):
    Item.cs
    Code (CSharp):
    1.         public int Count {
    2.             get {
    3.                 return count;
    4.             }
    5.             set {
    6.                 if (count==-1)
    7.                 {
    8.                     Changed();
    9.                     return ;
    10.                 }
    11.                 count = value;
    12.                 Changed();
    13.             }
    14.         }
     
  21. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    First set slider limits and then value
    Code (CSharp):
    1.             Count.LimitMin = -OrderLine.SellCount;
    2.             Count.LimitMax = OrderLine.BuyCount;
    3.             Count.Value = OrderLine.Count;
    Here -1 used to define infinite count, so any changes for Count will not be applied if it infinity.
     
    johanneskopf likes this.
  22. johanneskopf

    johanneskopf

    Joined:
    Feb 16, 2015
    Posts:
    81
    That introduces another bug for me. The slider (once sold/bought) is set to the remaining sell/buy count.
    This fixes that:
    Code (csharp):
    1.         Count.Value = OrderLine.Count;
    2.         Count.LimitMin = -OrderLine.SellCount;
    3.         Count.LimitMax = OrderLine.BuyCount;
    4.         Count.Value = OrderLine.Count;
    Thanks for the explanation!
     
  23. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    Strange, I see only bug with Total value, not slider.
    It should be fixed this way:
    HarborShop.cs
    Code (CSharp):
    1.         void Trade()
    2.         {
    3.             var order = new HarborOrder(TradeView.DataSource);
    4.            
    5.             if (Player.CanBuy(order))
    6.             {
    7.                 Harbor.Sell(order);
    8.                 Player.Buy(order);
    9.  
    10.                 UpdateTotal();// add this line
    11.             }
    12.             else
    13.             {
    14.                ...
    15.             }
    16.         }
     
  24. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,943
    @ilih
    Please make SetButtonName in Tab Control virtual so we can override it and replace Unity UI Text with TextMeshPro or others.
     
  25. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    Ok.
     
  26. bocs

    bocs

    Joined:
    May 9, 2009
    Posts:
    413
    Tested on Unity 5.2.4f4 and 5.3.2.p3...
    New projects, import UI Widgets directly from Asset Store.

    I get an error opening any dialog in the sample scenes..and can't drag the windows.
     
  27. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    Fix:
    Draggable.cs, replace line 35
    Old line:
    Code (CSharp):
    1. SetHandle(handle ?? gameObject);
    New line:
    Code (CSharp):
    1. SetHandle(handle!=null ? handle : gameObject);
     
  28. Aston-Martin

    Aston-Martin

    Joined:
    Jul 5, 2012
    Posts:
    64
    hi,

    Need help with the tile view sample. Spend an hour still can't figure out how to .....
    (1) How-to add items from program ? (instead of configured datasource)
    (2) How-to select item, display a debug message and remove ?

    thank you!

    Br,
    Aston
     
  29. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    Code (CSharp):
    1. TileView.DataSource.Add(...)
    or
    Code (CSharp):
    1. var data = new ObservableList<TileViewItemSample>();
    2. TileView.DataSource = data;


    Code (CSharp):
    1. TileView.Select(tileIndex);


    Probably you mean this
    Code (CSharp):
    1. Debug.Log(TileView.SelectedIndex);
    2. Debug.Log(string.Join(",", TileView.SelectedIndicies.Select(x => x.ToString()).ToArray()));


    Code (CSharp):
    1. TileView.DataSource.Remove(tile);
    2. TileView.DataSource.RemoveAt(tileIndex);


    TileView can be used same way as ListViewIcons or ListViewCustom.
    Most important properties and functions
    .SelectedIndex - when Multiple enabled return last selected index.
    .SelectedIndicies
    .SelectedItem - same as TileView.DataSource[TileView.SelectedIndex]
    .SelectedItems
    .Select()
    .Deselect()
    .DataSource - ObservableList<T> with same interface as List<T>.
    .DataSource.Comparison - Comparison<T>, control how items will be sorted.
     
  30. Aston-Martin

    Aston-Martin

    Joined:
    Jul 5, 2012
    Posts:
    64
    Thanks for the reply.
    Ok, got it working...Q1 solved.

    Q2: correction, not selected from program. But the selection is from the UI mouse click.

    Where to insert above 4 lines of code to handle the mouse onSelect event ?
     
  31. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    Use OnSelectObject or OnSelect:
    Code (CSharp):
    1.        void Start()
    2.         {
    3.             TileView.Start();
    4.             TileView.OnSelect.AddListener(ItemSelected);                          
    5.             TileView.OnSelectObject.AddListener(ItemSelected);
    6.         }
    7.  
    8.         void ItemSelected(int index, ListViewItem component)
    9.         {
    10.             if (component!=null)
    11.             {
    12.                 //(component as TileViewComponentSample).DoSomething();
    13.             }
    14.             Debug.Log(index);
    15.             Debug.Log(DataSource[index].Name);
    16.         }
    17.  
    18.         void ItemSelected(int index)
    19.         {
    20.             Debug.Log(index);
    21.             Debug.Log(TileView.DataSource[index].Name);
    22.         }
     
  32. Aston-Martin

    Aston-Martin

    Joined:
    Jul 5, 2012
    Posts:
    64
    Ok, got it working, Q2 solved. Thank u!
     
  33. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,943
    @ilih

    Getting following errors in CustomHeightList
    I tried to follow documentation exactly, but same error



    Code (CSharp):
    1. Ex [HTTPRequest]: CallCallback - Message: Object reference not set to an instance of an object  StackTrace:   at UIWidgets.ListViewCustom`2[TComponent,TItem].GetItemSize () [0x00000] in /Users/jgate/Documents/Apps/Projects/Unity/APA/Assets/UIWidgets/Standart Assets/ListView/ListViewCustom.cs:963
    2.   at UIWidgets.ListViewCustom`2[TComponent,TItem].GetItemPosition (Int32 index) [0x00000] in /Users/jgate/Documents/Apps/Projects/Unity/APA/Assets/UIWidgets/Standart Assets/ListView/ListViewCustom.cs:789
    3.   at UIWidgets.ListViewCustom`2[TComponent,TItem].GetItemPositionBottom (Int32 index) [0x00000] in /Users/jgate/Documents/Apps/Projects/Unity/APA/Assets/UIWidgets/Standart Assets/ListView/ListViewCustom.cs:799
    4.   at UIWidgets.ListViewCustom`2[TComponent,TItem].UpdateView () [0x001bb] in /Users/jgate/Documents/Apps/Projects/Unity/APA/Assets/UIWidgets/Standart Assets/ListView/ListViewCustom.cs:1151
    5.   at UIWidgets.ListViewCustom`2[TComponent,TItem].SetNewItems (UIWidgets.ObservableList`1 newItems) [0x000b6] in /Users/jgate/Documents/Apps/Projects/Unity/APA/Assets/UIWidgets/Standart Assets/ListView/ListViewCustom.cs:1203
    6.   at UIWidgets.ListViewCustomHeight`2[TComponent,TItem].SetNewItems (UIWidgets.ObservableList`1 newItems) [0x0000e] in /Users/jgate/Documents/Apps/Projects/Unity/APA/Assets/UIWidgets/Standart Assets/ListView/ListViewCustomHeight.cs:256
    7.   at UIWidgets.ListViewCustom`2[TComponent,TItem].set_DataSource (UIWidgets.ObservableList`1 value) [0x00000] in /Users/jgate/Documents/Apps/Projects/Unity/APA/Assets/UIWidgets/Standart Assets/ListView/ListViewCustom.cs:63
     
  34. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    Probably ListView not yet started, try to call Start() before using DataSource.
    Code (CSharp):
    1. CustomHeightList.Start();
    2. CustomHeightList.DataSource = data;
     
  35. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    Most likely CustomHeightList.Container gameobject does not have one of supported layout components.
    Supported layouts: EasyLayout, Horizontal Layout Group, VerticalLayoutGroup.
     
  36. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,943
    Tried doing it, but its raising error now matter what.
    Funny thing is it is working fine in other unity project
     
  37. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,943
    Worked, Layout was somehow missing, Thanks
     
  38. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,943
    CustomHeightList doesnt show all the items, but when i go back to scene view (in playmode) and slightly resize the list then it shows all the items
     
  39. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    Probably Item.Height contain incorrect value - it's not equal real height.
    Modify SetData() in item component class to keep current item
    Code (CSharp):
    1. ListViewImagesItem Item;
    2.  
    3.         public void SetData(ListViewImagesItem item)
    4.         {
    5.             // save item so later we can fix Item.Height to actual value
    6.             Item = item;
    7.  
    8.             //...
    9.         }
    And add following function to fix Item.Height:
    Code (CSharp):
    1.         protected override void OnRectTransformDimensionsChange()
    2.         {
    3.               Item.Height = (transform as RectTransform).rect.height;
    4.         }
     
  40. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,943
  41. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    It does not required anymore. In current version height calculated automatically, but cannot automatically process size changes and required additional code to support it. This problem fixed in next version.
     
    Last edited: Feb 28, 2016
    jGate99 likes this.
  42. par-002

    par-002

    Joined:
    Jul 4, 2012
    Posts:
    52
    Hello,

    I purchased this excellent "New UI Widgets" Asset and am having quite a bit of success getting things to work the way I want. Unfortunately, I have run into an issue with a ListViewCustom inside of a Tab.

    I am utilizing a UI/Tab object with 2 internal tabs. The first (default and always first to be enabled) tab contains a customized ListViewCustom object that I populate in my UI Controller's Start() method. This list tab's list is not only populated correctly but it also is sorted correctly and has my overridden SetData() method called correctly in my custom ListViewItem class.

    For the second tab, I copied the entire ListViewCustom GameObject tree from the first Tab and updated all my references in my UI Controller (yes, I have triple checked that all of my references are correct). The list in this second tab is populated correctly with the dynamic information I load in Start() but unfortunately the list is not sorted nor does it look as if my overridden SetData() method is called.

    Here is the call in my UI Controller:

    Code (CSharp):
    1. public void initializePlayerSpellsAndAbilities() {
    2.         List<Spell> inherentSpells = gameBoardMainThread.playerController.localPlayer.inherentSpells;
    3.         List<Spell> masterySpells = gameBoardMainThread.playerController.localPlayer.masterySpells;
    4.  
    5.         // playerInherentSpellsAndAbilities and playerMasterySpellsAndAbilities are created as:
    6.         //    public class SpellsAndAbilitiesListView : ListViewCustom<SpellsAndAbilitiesItem,
    7.         //                                              SpellsAndAbilitiesItemDescription> {
    8.         playerInherentSpellsAndAbilities.Clear();
    9.         foreach(Spell inherent in inherentSpells) {
    10.             playerInherentSpellsAndAbilities.Set(
    11.                       new SpellsAndAbilitiesItemDescription(inherent.name, inherent.displayName,
    12.                                  inherent.spellCost.airCost, inherent.spellCost.earthCost,
    13.                                  inherent.spellCost.fireCost, inherent.spellCost.waterCost), true);
    14.         }
    15.         playerInherentSpellsAndAbilities.UpdateItems();
    16.  
    17.         playerMasterySpellsAndAbilities.Clear();
    18.         foreach(Spell mastery in masterySpells) {
    19.             playerMasterySpellsAndAbilities.Set(
    20.                       new SpellsAndAbilitiesItemDescription(mastery.name, mastery.displayName,
    21.                                  mastery.spellCost.airCost, mastery.spellCost.earthCost,
    22.                                  mastery.spellCost.fireCost, mastery.spellCost.waterCost), true);
    23.         }
    24.         playerMasterySpellsAndAbilities.UpdateItems();
    25.     }


    I found that ListViewCustom.Set() is the method to use when dynamically adding items to the list as the .Add() method does not seem to call the item's SetData() method. Since I am doing the exact same thing for both ListView's, why would the first one work flawlessly but second one be broken? Also, why would the second one be populated but not... initialized? Not sure how else to describe it.

    Is there some other kind of update method I can forcibly call to make sure that the second list is initialized correctly? I tried the UpdateItems() method but it doesn't seem to have an effect as I have tried calling it in the UI Controller (code above) as well as in a Tab change event.

    ** edit **
    Well, after mucking around a bit the issue I have has nothing to do w/ the Tabs. I completely removed the second List out and just put it in the middle of my scene and it exhibits the same issue there as well. For the life of me I cannot figure out why, when the code is exactly the same, that this list is not working correctly. Do you have any good documentation and/or example code on dynamically generating your UI Widgets?

    Thank you!
     
    Last edited: Mar 1, 2016
  43. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    ListView does not sort items by default and I cannot see any sort definitions, so items displayed same order as the original lists where first list sorted and second not.

    So code should be like this:
    Code (CSharp):
    1.             var dataSource = playerInherentSpellsAndAbilities.DataSource;
    2.  
    3.             // Use sort
    4.             dataSource.Comparison = (x, y) => x.name.CompareTo(y.Name);
    5.  
    6.             // Without BeginUpdate() ListView will be redrawed with each change in DataSource
    7.             dataSource.BeginUpdate();
    8.  
    9.             dataSource.Clear();
    10.             foreach(Spell inherent in inherentSpells)
    11.             {
    12.                 dataSource.Add(new SpellsAndAbilitiesItemDescription(inherent.name, inherent.displayName,
    13.                     inherent.spellCost.airCost, inherent.spellCost.earthCost,
    14.                     inherent.spellCost.fireCost, inherent.spellCost.waterCost));
    15.             }
    16.  
    17.             // Redraw ListView, if any changes made.
    18.             dataSource.EndUpdate();
    .Set() used only when you need add item and select it immediately.
    .UpdateItems() does not needed in almost all cases, it called automatically after changes in DataSource or DataSource.EndUpdate() call.

    You can check documenation on ListViewIcons and UIWidgets/Sample Assets/Table/SteamSpyView.cs
     
    Last edited: Mar 1, 2016
  44. par-002

    par-002

    Joined:
    Jul 4, 2012
    Posts:
    52
    Excellent! Thank you so much for clarifying how to add new items. Your code change fixed my issue and all is well.

    Thanks again!
     
  45. Aston-Martin

    Aston-Martin

    Joined:
    Jul 5, 2012
    Posts:
    64
    hi ilih,

    Need help here....How to disable sorting for ComboboxIcons drop down list?
    (Trying to figure out a way to display the dropdown list in as sequence as defined in the Inspector->listviewicons->custom items)

    Br,
    Aston
     
  46. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    From inspector it's was not available, here fix:
    Replace code in UIWidgets/Editor/ListViewIconsEditor.cs
    Code (CSharp):
    1.  
    2. using UnityEditor;
    3.  
    4. namespace UIWidgets
    5. {
    6.     [CanEditMultipleObjects]
    7.     [CustomEditor(typeof(ListViewIcons), true)]
    8.     public class ListViewIconsEditor : ListViewCustomBaseEditor
    9.     {
    10.         public ListViewIconsEditor()
    11.         {
    12.             Properties.Insert(1, "sort");
    13.         }
    14.     }
    15. }
    From script:
    Code (CSharp):
    1. ComboboxIcons.ListView.Sort = false;
    Should be used before ComboboxIcons.Start() or DataSource.
     
  47. Aston-Martin

    Aston-Martin

    Joined:
    Jul 5, 2012
    Posts:
    64
    Step 1 - ListVireIconsEditor OK

    namespace UIWidgets
    {
    [CanEditMultipleObjects]
    //[CustomEditor(typeof(ListViewIcons),true)]
    public class ListViewIconsEditor : ListViewCustomEditor
    {
    //moddisablesort
    public ListViewIconsEditor()
    {
    Properties.Insert(1, "sort");
    }
    }
    }​

    Step 2 - Add to ComboboxCustom.cs

    void Awake()
    {
    ListView.Sort = false;//<---mod disable sort
    Start();​
    }​

    The combo list still get sorted ;-(
     
  48. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412

    Wrong, line "//[CustomEditor(typeof(ListViewIcons),true)]" should be uncommented and class should be derived from ListViewCustomBaseEditor, not ListViewCustomEditor.
    Then you can disable sort in Inspector window.


    This is not necessary if you already modify ListViewIconsEditor.
    Instead modifying existing class, better create special class and use Edit/Project Settings/Script Execution Order to execute this script first.
    Code (CSharp):
    1. using UnityEngine;
    2. using UIWidgets;
    3.  
    4. namespace UIWidgetsSamples
    5. {
    6.     public class ComboboxIconsDisableSort
    7.     {
    8.         [SerializeField]
    9.         ComboboxIcons comboboxIcons;
    10.        
    11.         public void Awake()
    12.         {
    13.             comboboxIcons.ListView.Sort = false;
    14.         }
    15.     }
    16. }
     
  49. par-002

    par-002

    Joined:
    Jul 4, 2012
    Posts:
    52
    Again, thank you for an excellent package!

    I am having issues w/ the ListView's and keeping things sized correctly when changing aspect ratios. After quite a bit of work, I got my entire UI resizing correctly when I change Aspect Ratio's (just testing with 16:9 and 4:3) except for the ListView components. I am using all of the suggested techniques of getting UI elements to resize correctly including the Canvas "Scale with Screen Size" and the anchor helper "uGUITools.cs".

    Because I'm using some detailed text placement I must use the AspectRatioFitter script. But this script seems to get overridden for the "Default Item" ListViewItem class that is inside the ListView. When I change ratio's, everything but the items inside the ListViewItem class resize correctly.

    But unfortunately, when I actually run the program, I think the resizing of the elements dynamically is fouling up the ListView code as the child elements are all over the screen. So I cannot explicitly pinpoint what the issue is other than "Using the suggested techniques for supporting a change of aspect ratios isn't working".

    Do you have any suggestions on how to work with supporting Aspect Ratio changes with your components?

    Thank you!
     
  50. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,412
    Is it look like this https://ilih.ru/unity-assets/video/UIWidgets/ListView-CanvasScaler-RelativeSize.mp4 ?
    In this case problem with ListView.DefaultItem.Text settings - rendered text size more than Text.RectTransform size. I suppose some rounding problem cause this.
    Possible solutions:
    • Change Vertical Overflow from Truncate to Overflow
    • Or decrease Font Size
    • Or increase RectTransform height