コード例 #1
0
        private void ResizeInput(string text)
        {
            var fullText = inputField.text;

            var extents  = inputField.textComponent.rectTransform.rect.size;
            var settings = inputField.textComponent.GetGenerationSettings(extents);

            settings.generateOutOfBounds = false;
            var width = new TextGenerator().GetPreferredWidth(fullText, settings) + paddingRight.x + paddingLeft.x;

            if (width > inputField.textComponent.rectTransform.rect.width - paddingRight.x)
            {
                if (syncWith != null)
                {
                    onResize.Invoke(this, width);
                }
                else
                {
                    SetSizeTo(width);
                }
            }
            else if (width < inputField.textComponent.rectTransform.rect.width + paddingRight.x)
            {
                if (syncWith != null)
                {
                    onResize.Invoke(this, width);
                }
                else
                {
                    SetSizeTo(width);
                }
            }
        }
コード例 #2
0
ファイル: Screen.cs プロジェクト: MarbleGameDev/2DRPG
        public static void SetWindowDimensions(int width, int height)
        {
            WindowHeight = height;
            WindowWidth  = width;
            windowRatio  = (float)width / height;

            if (ResizeEvent != null)
            {
                ResizeEvent.Invoke();
            }
        }
コード例 #3
0
        /// <summary>
        /// Draw the day/hour grid and hour labels for the frame of the calendar
        /// </summary>
        /// <param name="pe">PaintEventArgs for drawing graphics on the control</param>
        public void DrawCalendarFrame(PaintEventArgs pe)
        {
            int width  = this.ClientRectangle.Width - leftMargin - rightMargin;
            int height = 1920;
            int left   = this.ClientRectangle.Left + leftMargin;
            int top    = this.ClientRectangle.Top + topMargin;
            int right  = left + width;
            int bottom = top + height;

            // fire the resize event with the needed positions for the day dividers
            CalendarResizedEventArgs r = new CalendarResizedEventArgs
            {
                dayStartPositions = new int[] { left, left + width / 5, left + 2 * width / 5, left + 3 * width / 5, left + 4 * width / 5, right },
            };

            ResizeEvent?.Invoke(this, r);

            Pen pen = new Pen(Color.LightGray);

            // draw horizontal divider lines of calendar
            int startX;

            for (int i = 0; i < 48; i++)
            {
                if (i % 2 == 0)
                {
                    startX = 0;
                }
                else
                {
                    startX = leftMargin;
                }
                pe.Graphics.DrawLine(pen, new Point(startX, top + 40 * i), new Point(right, top + 40 * i));
            }

            pen.Color = Color.Black;

            // draw vertical divider lines of calendar
            pe.Graphics.DrawLine(pen, new Point(left, top), new Point(left, bottom));                      // left vertical border line
            pe.Graphics.DrawLine(pen, new Point(left + width / 5, top), new Point(left + width / 5, bottom));
            pe.Graphics.DrawLine(pen, new Point(left + 2 * width / 5, top), new Point(left + 2 * width / 5, bottom));
            pe.Graphics.DrawLine(pen, new Point(left + 3 * width / 5, top), new Point(left + 3 * width / 5, bottom));
            pe.Graphics.DrawLine(pen, new Point(left + 4 * width / 5, top), new Point(left + 4 * width / 5, bottom));
            pe.Graphics.DrawLine(pen, new Point(right, top), new Point(right, bottom));                    // right vertical border line

            // draw bottom border line
            pen.Width *= 2;
            pe.Graphics.DrawLine(pen, new Point(left, bottom), new Point(right, bottom));

            // finished with pen for drawing, so dispose
            pen.Dispose();

            // prepare to draw hour divider labels (using SolidBrush)
            System.Drawing.Font         drawFont   = new System.Drawing.Font("Segoe UI", 12);
            System.Drawing.SolidBrush   brush      = new System.Drawing.SolidBrush(System.Drawing.Color.Gray);
            System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat();

            // draw label for each hour
            for (int i = 0; i < 24; i++)
            {
                pe.Graphics.DrawString(GetHourLabel(i), drawFont, brush, 5, top + 80 * i, drawFormat);
            }

            // dispose of string drawing resources
            drawFont.Dispose();
            brush.Dispose();
            drawFormat.Dispose();
        }