Example #1
0
        public virtual void Draw(Rect canvas, float fieldWidth)
        {
            // create rects
            Rect labelRect = canvas, fieldRect = canvas;

            labelRect.xMax -= fieldWidth;
            fieldRect.xMin  = canvas.width - fieldWidth;

            // draw tooltip
            if (!tip.NullOrEmpty())
            {
                TooltipHandler.TipRegion(canvas, tip);
            }

            // draw stuff
            GUI.SetNextControlName(_fieldName);
            CCL_Widgets.Label(labelRect, label, color, font, anchor, tip);
            _current = GUI.TextField(fieldRect, _current);

            // if field doesn't have focus, or enter is pressed, validate the input
            if (GUI.GetNameOfFocusedControl() != _fieldName || Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter)
            {
                Validate();
            }
        }
Example #2
0
        public override void Draw(Rect canvas, float fieldWidth)
        {
            // get maximum allowable size for preview rect.
            float previewSize = Mathf.Min(canvas.height - 6f, fieldWidth);

            // create rects
            Rect previewRect = new Rect(canvas.xMax - previewSize - 3f, canvas.yMin + 3f, previewSize, previewSize);
            Rect labelRect   = canvas;

            labelRect.xMax -= previewSize + 6f;

            // draw tooltip
            if (!tip.NullOrEmpty())
            {
                TooltipHandler.TipRegion(canvas, tip);
            }

            // draw things
            CCL_Widgets.Label(labelRect, label, color, font, anchor, tip);
            CCL_Widgets.DrawBackground(previewRect, newValue);

            // open Colorpicker when preview is clicked
            if (Widgets.ButtonInvisible(previewRect))
            {
                Find.WindowStack.Add(new ColorPicker.Dialog_ColorPicker(_wrapper, () => newValue = _wrapper.Color, false, true)
                {
                    layer = WindowLayer.Super, closeOnClickedOutside = true
                });
            }
        }