Ejemplo n.º 1
0
 void OnEnable()
 {
     if (!m_initialized)
     {
         DatePickerTimer.DelayedCall(0, UpdateDisplay, this);
     }
 }
Ejemplo n.º 2
0
 void OnValidate()
 {
     DatePickerTimer.DelayedCall(0f, () =>
     {
         FromDate = m_FromDate;
         ToDate   = m_ToDate;
     }, this);
 }
        public override void OnInspectorGUI()
        {
            var datePickerInputField = ((DatePicker_InputField)target);

            if (GUILayout.Button("Force Update"))
            {
                datePickerInputField.UpdateDisplay();
            }

            if (DrawDefaultInspector())
            {
                datePickerInputField.UpdateDisplay();
                DatePickerTimer.DelayedCall(0.005f, datePickerInputField.UpdateDisplay, datePickerInputField);
            }
        }
Ejemplo n.º 4
0
        public override void OnInspectorGUI()
        {
            var datePicker = ((DatePicker)target);

            if (GUILayout.Button("Force Update"))
            {
                datePicker.UpdateDisplay();
            }

            if (GUILayout.Button("Invalidate Button Templates"))
            {
                datePicker.InvalidateAllDayButtonTemplates();
            }

            if (DrawDefaultInspector())
            {
                datePicker.UpdateDisplay();
                DatePickerTimer.DelayedCall(0.005f, datePicker.UpdateDisplay, datePicker);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Called by the DatePicker instances
        /// </summary>
        /// <param name="date"></param>
        public void DateSelected(DateTime date)
        {
            FromDate = new SerializableDate(Ref_DatePicker_From.SelectedDate);
            ToDate   = new SerializableDate(Ref_DatePicker_To.SelectedDate);

            this.UpdateDisplay();

            DatePickerTimer.DelayedCall(0.1f,
                                        () =>
            {
                if (Config.Misc.CloseWhenDateSelected)
                {
                    // Only close if we have both from and to dates selected
                    if (FromDate.HasValue && ToDate.HasValue)
                    {
                        Hide();
                    }
                }
            },
                                        this);
        }
Ejemplo n.º 6
0
        public void Show(bool setPositionIfNecessary = true)
        {
            var canvas = FindParentOfType <Canvas>(this.gameObject);

            if (setPositionIfNecessary && Ref_InputField != null)
            {
                // Position tablelayout relative to InputField
                SetPositionAdjacentToInputFieldContainer();
                // Wait till the end of the frame, then complete Show() (this ensures that the DatePicker only becomes visible after being resized)
                DatePickerTimer.DelayedCall(0, () => Show(false), this);
                return;
            }

            Ref_DatePickerTransform.gameObject.SetActive(true);

            if (Config.Modal.IsModal && Ref_ScreenOverlay != null)
            {
                if (canvas != null)
                {
                    Ref_ScreenOverlay.transform.SetParent(canvas.transform);
                    Ref_ScreenOverlay.transform.SetAsLastSibling();
                }

                Ref_ScreenOverlay.gameObject.SetActive(true);

                Ref_ScreenOverlayAnimator.PlayAnimation(Animation.Fade, AnimationType.Show);
            }

            if (canvas != null)
            {
                Ref_DatePickerTransform.SetParent(canvas.transform);
                Ref_DatePickerTransform.SetAsLastSibling();
            }

            if (Config.Animation.ShowAnimation != Animation.None)
            {
                PlayAnimation(Config.Animation.ShowAnimation, AnimationType.Show);
            }
        }
Ejemplo n.º 7
0
        public static void MenuItem_NewDatePickerSharedCalendar()
        {
            var datePicker = DatePicker_Instantiation.InstantiatePrefab("DatePicker - Shared Calendar").GetComponent <DatePicker>();

            DatePickerTimer.DelayedCall(0.1f, datePicker.UpdateDisplay, datePicker);
        }
Ejemplo n.º 8
0
        public static void MenuItem_NewDatePickerDateRange()
        {
            var datePicker = DatePicker_Instantiation.InstantiatePrefab("DatePicker - Date Range").GetComponent <DatePicker_DateRange>();

            DatePickerTimer.DelayedCall(0.1f, datePicker.UpdateDisplay, datePicker);
        }
Ejemplo n.º 9
0
 void OnRectTransformDimensionsChange()
 {
     //UpdateDisplay();
     DatePickerTimer.DelayedCall(0f, UpdateDisplay, this);
 }
Ejemplo n.º 10
0
        private void SetPositionAdjacentToInputFieldContainer()
        {
            if (Ref_InputFieldContainer == null)
            {
                return;
            }

            var rectTransform           = Ref_DatePickerTransform;
            var inputFieldRectTransform = Ref_InputFieldContainer.transform as RectTransform;
            var inputFieldWidth         = inputFieldRectTransform.rect.width;

            if (IsSharedCalendar)
            {
                rectTransform.SetParent(inputFieldRectTransform.parent);
            }

            // Fix anchors:
            rectTransform.anchorMin = new Vector2(0, 1);
            rectTransform.anchorMax = new Vector2(1, 1);

            var widthBefore = rectTransform.rect.width;

            if (Config.Sizing.UsePreferredWidthInsteadOfInputFieldWidth)
            {
                rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Config.Sizing.PreferredWidth);
            }
            else
            {
                rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, inputFieldWidth);
            }

            if (widthBefore != rectTransform.rect.width)
            {
                ((RectTransform)Ref_DayTable.transform).SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, rectTransform.rect.width);
            }

            var pivotX = 0.5f;

            switch (Config.InputField.DatePickerAlignmentRelativeToInputField)
            {
            case Alignment.Left:
            {
                pivotX = 0f;
            }
            break;

            case Alignment.Right:
            {
                pivotX = 1f;
            }
            break;
            }

            var canvas          = GetComponentInParent <Canvas>();
            var canvasTransform = ((RectTransform)canvas.transform);

            rectTransform.pivot            = new Vector2(pivotX, 0.5f);
            rectTransform.anchoredPosition = inputFieldRectTransform.anchoredPosition;
            rectTransform.SetParent(canvasTransform);

            rectTransform.pivot             = new Vector2(pivotX, 1);
            rectTransform.anchoredPosition -= new Vector2(0, inputFieldRectTransform.rect.height);

            var spaceBelow = canvasTransform.rect.height + rectTransform.anchoredPosition.y;

            if (spaceBelow < rectTransform.rect.height)
            {
                rectTransform.pivot             = new Vector2(pivotX, 0);
                rectTransform.anchoredPosition += new Vector2(0, inputFieldRectTransform.rect.height);

                var spaceAbove = -(rectTransform.anchoredPosition.y + rectTransform.rect.height);
                if (spaceAbove < 0)
                {
                    rectTransform.anchoredPosition += new Vector2(0, spaceAbove);
                }
            }

            DatePickerTimer.DelayedCall(0.05f, () => { Ref_DayTableContainer.GetRow().NotifyTableRowPropertiesChanged(); }, this);
        }
Ejemplo n.º 11
0
 void Start()
 {
     //UpdateDisplay();
     DatePickerTimer.DelayedCall(0, UpdateDisplay, this);
 }
Ejemplo n.º 12
0
        private void SetPositionAdjacentToInputFieldContainer()
        {
            if (Ref_InputFieldContainer == null)
            {
                return;
            }

            var rectTransform           = Ref_DatePickerTransform;
            var inputFieldRectTransform = Ref_InputFieldContainer.transform as RectTransform;
            var inputFieldWidth         = inputFieldRectTransform.rect.width;

            if (Config.Sizing.UsePreferredWidthInsteadOfInputFieldWidth)
            {
                rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Config.Sizing.PreferredWidth);
            }
            else
            {
                rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, inputFieldWidth);
            }


            var pivotX = 0.5f;

            switch (Config.InputField.DatePickerAlignmentRelativeToInputField)
            {
            case Alignment.Left:
            {
                pivotX = 0f;
            }
            break;

            case Alignment.Right:
            {
                pivotX = 1f;
            }
            break;
            }

            var canvasTransform = ((RectTransform)GetComponentInParent <Canvas>().transform);

            Vector3[] canvasCorners = new Vector3[4], inputFieldCorners = new Vector3[4];
            canvasTransform.GetWorldCorners(canvasCorners);
            inputFieldRectTransform.GetWorldCorners(inputFieldCorners);

            var distanceFromCanvasBottom = Mathf.Abs(canvasCorners[3].y - inputFieldCorners[3].y);

            var actualHeight = Vector2.Scale(rectTransform.rect.size, rectTransform.lossyScale).x;

            calculatedPosition = actualHeight > distanceFromCanvasBottom ? DatePickerPosition.Above : DatePickerPosition.Below;

            if (calculatedPosition == DatePickerPosition.Above)
            {
                rectTransform.pivot            = new Vector2(pivotX, 0);
                rectTransform.anchoredPosition = inputFieldRectTransform.anchoredPosition;

                // if, in the Above position, we're so high that we go above the top of the canvas, then apply an offset to correct this
                var offsetY = canvasTransform.rect.height - (inputFieldCorners[2].y + rectTransform.rect.height);
                if (offsetY < 0)
                {
                    rectTransform.position = new Vector3(rectTransform.position.x, rectTransform.position.y + offsetY, rectTransform.position.z);
                }
            }
            else
            {
                rectTransform.pivot            = new Vector2(pivotX, 1);
                rectTransform.anchoredPosition = inputFieldRectTransform.anchoredPosition;
                rectTransform.position         = new Vector3(rectTransform.position.x, rectTransform.position.y - inputFieldRectTransform.rect.height, rectTransform.position.z);
            }

            DatePickerTimer.DelayedCall(0.05f, () => { Ref_DayTableContainer.GetRow().NotifyTableRowPropertiesChanged(); }, this);
        }