You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
823 B
39 lines
823 B
using UnityEngine; |
|
using UnityEngine.UI; |
|
using UIWidgets; |
|
|
|
namespace UIWidgetsSamples { |
|
public class ListViewVariableHeightComponent : ListViewItem/*, IListViewItemHeight*/ { |
|
[SerializeField] |
|
public Text Name; |
|
|
|
[SerializeField] |
|
public Text Text; |
|
|
|
public float Height { |
|
get { |
|
return CalculateHeight(); |
|
} |
|
} |
|
|
|
// Displaying item data |
|
public void SetData(ListViewVariableHeightItemDescription item) |
|
{ |
|
Name.text = item.Name; |
|
Text.text = item.Text.Replace("\\n", "\n"); |
|
} |
|
|
|
float CalculateHeight() |
|
{ |
|
float default_total_height = 58; |
|
float default_name_height = 21; |
|
float default_text_height = 17; |
|
|
|
var base_height = default_total_height - default_name_height - default_text_height; |
|
|
|
var h = base_height + Name.preferredHeight + Text.preferredHeight; |
|
|
|
return h; |
|
} |
|
} |
|
} |