示例#1
0
        private void OnMouseExitDayContainer(MouseLeaveEvent mouseEvent, DayCalendarEvent e)
        {
            var editBtn = e.target.Q <Button>(DayContainerTemplateNames.EDIT_BTN);

            if (currentDayEditing != e.target) // Hide edit btn if is not editing this day
            {
                ChangeDayEditState(e.target, false, editBtn);
            }
        }
示例#2
0
        private void OnChangeValueEditMinutesInput(ChangeEvent <string> changeEvt, DayCalendarEvent e)
        {
            var inputEditMinutes = e.target.Q <TextField>(DayContainerTemplateNames.INPUT_EDIT_MINUTES);

            // Fix input value if is needed
            if (ClampDayMinutesValue(changeEvt.previousValue, changeEvt.newValue, out var fixedValue))
            {
                inputEditMinutes.value = fixedValue.ToString();
            }
        }
示例#3
0
        private void OnMouseEnterDayContainer(MouseEnterEvent mouseEvent, DayCalendarEvent e)
        {
            var editBtn = e.target.Q <Button>(DayContainerTemplateNames.EDIT_BTN);

            ChangeDayEditState(e.target, true, editBtn);
        }
示例#4
0
        void FillDateToDate(VisualElement[] daysContainers, DateTime dateSelected, int start, int end, ref int daysGenerated, bool emptyMode = false)
        {
            var dayElementTemplate = Resources.Load <VisualTreeAsset>("DayContainerTemplate");

            var displayingYear  = info?.years?.Find(y => y.year == selectedDate.Year);
            var displayingMonth = displayingYear?.months.Find(m => m.month == selectedDate.Month);

            // Generate Date elements
            for (int i = start; i < end; i++)
            {
                var date = new DateTime(dateSelected.Year, dateSelected.Month, i + 1);

                var dayContainer = daysContainers[(int)date.DayOfWeek];

                var dayElement = dayElementTemplate.CloneTree();
                dayElement.name = TimeRecorderExtras.GetDayNameFormat(i, dateSelected.Month, dateSelected.Year);

                string hoursTxt = "";

                // Control when the user focus a valid day
                if (!emptyMode)
                {
                    var focusedElement = new DayCalendarEvent {
                        target = dayElement
                    };
                    var editBtn          = dayElement.Q <Button>(DayContainerTemplateNames.EDIT_BTN);
                    var inputEditMinutes = dayElement.Q <TextField>(DayContainerTemplateNames.INPUT_EDIT_MINUTES);

                    dayElement.RegisterCallback <MouseEnterEvent, DayCalendarEvent>(OnMouseEnterDayContainer, focusedElement);
                    dayElement.RegisterCallback <MouseLeaveEvent, DayCalendarEvent>(OnMouseExitDayContainer, focusedElement);
                    inputEditMinutes.RegisterCallback <ChangeEvent <string>, DayCalendarEvent>(OnChangeValueEditMinutesInput, focusedElement);


                    // Add events to handle this element
                    editBtn.clicked += () => OnPressEditBtn(dayElement);
                }

                // Fill seleted month with sotred data
                if (displayingMonth != null && !emptyMode)
                {
                    // Get & set worked day info
                    var dayInfoIdx = displayingMonth.dates.FindIndex(d => d.date == i + 1);

                    if (dayInfoIdx != -1)
                    {
                        // Set worked time
                        var dayInfo = displayingMonth.dates[dayInfoIdx];

                        hoursTxt = GetLabel(dayInfo.timeInSeconds);
                    }
                }

                var dayLabel = dayElement.Q <Label>(DayContainerTemplateNames.LABEL_DAY);
                dayLabel.text = emptyMode ? "" : $"{i+1}";

                var hoursLabel = dayElement.Q <Label>(DayContainerTemplateNames.LABEL_HOURS);
                hoursLabel.text = hoursTxt;

                dayContainer.Add(dayElement);

                daysGenerated++;
            }
        }