using Newtonsoft.Json; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; using UnityEngine.UIElements; public class SessionsListView : MonoBehaviour { #region PROPERTIES #endregion #region VARIABLES [SerializeField] private UIDocument uiDocument; private StatsMenuController _statsController; #endregion #region EVENTS private void OnButtonClick(SessionData sessionData) { _statsController.OnSessionSelected(sessionData); } #endregion #region METHODS #endregion #region LIFECYCLE private void Awake() { _statsController = StatsMenuController.Instance; } private void Start() { var sessionDataList = _statsController.Sessions; var root = uiDocument.rootVisualElement; var listView = root.Q("ListViewSessions"); listView.itemsSource = sessionDataList; listView.makeItem = () => new Button(); listView.bindItem = (element, index) => { var button = element as Button; var sessionData = sessionDataList[index]; button.text = $"Session {sessionData.SessionNumber} | {sessionData.Date.ToString("ddd, dd MMM yyy")}"; button.AddToClassList("list-button"); button.style.backgroundColor = new Color(0, 0, 0, 0.2f); button.style.height = 50; button.style.marginLeft = 10; button.style.marginRight = 10; button.style.marginBottom = 2; button.style.color = Color.white; // Ajouter un callback pour lorsque le bouton est cliqu� button.clicked += () => OnButtonClick(sessionData); }; listView.fixedItemHeight = 52; listView.selectionType = SelectionType.Single; listView.style.flexGrow = 1.0f; listView.Rebuild(); } #endregion }