using UnityEngine;
using UnityEngine.UI;
using EnhancedUI.EnhancedScroller;
namespace EnhancedScrollerDemos.KeyControl
{
///
/// This is the view of our cell which handles how the cell looks.
///
public class CellView : EnhancedScrollerCellView
{
///
/// The underlying data source
///
private Data _data;
///
/// The background image to show the highlight if selected
///
public Image backgroundImage;
///
/// A reference to the UI Text element to display the cell data
///
public Text someTextText;
///
/// The color to show when the cell is selected
///
public Color selectedColor;
///
/// The color to show when the cell is not selected
///
public Color unselectedColor;
///
/// This function just takes the Demo data and displays it
///
///
public void SetData(Data data)
{
// set the underlying data source. This is used when
// we need to refresh the cell view
_data = data;
// update the UI text with the cell data
someTextText.text = _data.someText;
// call the refresh method which just sets the selection highlight
RefreshCellView();
}
///
/// Called when the selected cell index is changed in the controller
///
public override void RefreshCellView()
{
// highlight the cell if necessary
backgroundImage.color = _data.isSelected ? selectedColor : unselectedColor;
}
}
}