ScrollBlock
This component allows to display infinite list of strings.
It is used by DateScroller, DateTimeScroller, TimeScroller.
Each item represents an integer index which can be converted to the string representation with the
Value
property.Item at center always have index
0
, items before it have indices with step -1
, items after it have indices with step +1
.Options
Value
Func<int, string>
Convert integer value to the string representation.
Increase
Action
Increase value by 1.
Decrease
Action
Decrease value by 1.
AllowIncrease
Func<bool>
Check if the value can be increased. Values higher than the current one will not be displayed.
AllowDecrease
Func<bool>
Check if the value can be decreased. Values lower than the current one will not be displayed.
IsInteractable
Func<bool>
Is
ScrollBlock
interactable?
Usage
namespace UIWidgets.Examples
{
using System;
using UIWidgets;
using UnityEngine;
public class MinutesScroll : MonoBehaviour
{
TimeSpan Time = new TimeSpan(12, 10, 20);
void Start()
{
MinutesScrollBlock.Value = Value;
MinutesScrollBlock.Decrease = DecreaseMinutes;
MinutesScrollBlock.Increase = IncreaseMinutes;
}
string Value(int steps)
{
// date used only for convenient conversion of minutes to string
var date = new DateTime(2000, 1, 2);
date += IncreaseMinutes(steps) - date.TimeOfDay;
return date.ToString("mm");
}
string IncreaseMinutes(int steps) => Time + new TimeSpan(0, steps, 0);
string DecreaseMinutes(int steps) => IncreaseMinutes(-steps);
}
}