コード例 #1
0
        public static string Textbox(Rect rect, string label, string text)
        {
            Window window = GetCurrentWindow();

            if (window.SkipItems)
            {
                return(text);
            }

            var id = window.GetID(label);

            // style
            var style = GUIStyle.Basic;

            style.Save();
            style.ApplySkin(GUIControlName.TextBox);

            // rect
            rect = window.GetRect(rect);

            // interact
            InputTextContext context;

            text = GUIBehavior.TextBoxBehavior(id, rect, text, out bool hovered, out bool active, out context);

            // render
            var state = active ? GUIState.Active : hovered ? GUIState.Hover : GUIState.Normal;

            GUIAppearance.DrawTextBox(rect, id, text, context, state);

            style.Restore();

            return(text);
        }
コード例 #2
0
ファイル: TextBox.cs プロジェクト: zwcloud/ImGui
        /// <summary>
        /// Create a single-line text box.
        /// </summary>
        /// <param name="label">label</param>
        /// <param name="width">width</param>
        /// <param name="text">text</param>
        /// <param name="flags">filter flags</param>
        /// <param name="checker">custom checker per char</param>
        /// <returns>(modified) text</returns>
        public static string TextBox(string label, double width, string text, InputTextFlags flags, Func <char, bool> checker, LayoutOptions?options)
        {
            Window window = GetCurrentWindow();

            if (window.SkipItems)
            {
                return(text);
            }

            var  id        = window.GetID(label);
            var  container = window.RenderTree.CurrentContainer;
            Node node      = container.GetNodeById(id);

            label = Utility.FindRenderedText(label);
            if (node == null)
            {
                //create node
                node             = new Node(id, $"{nameof(TextBox)}<{label}>");
                node.UseBoxModel = true;
                node.RuleSet.Replace(GUISkin.Current[GUIControlName.TextBox]);
                var size = node.RuleSet.CalcContentBoxSize(text, GUIState.Normal);
                node.AttachLayoutEntry(size);
            }
            container.AppendChild(node);
            node.RuleSet.ApplyOptions(options);
            node.ActiveSelf = true;

            // rect
            Rect rect = window.GetRect(id);

            // interact
            InputTextContext context;

            text = GUIBehavior.TextBoxBehavior(id, rect, text, out bool hovered, out bool active, out context, flags, checker);
            var state = active ? GUIState.Active : hovered ? GUIState.Hover : GUIState.Normal;

            // last item state
            window.TempData.LastItemState = state;

            // render
            if (flags.HaveFlag(InputTextFlags.Password))
            {
                var dotText = new string('*', text.Length);//FIXME bad performance
                GUIAppearance.DrawTextBox(node, id, dotText, context, state);
            }
            else
            {
                GUIAppearance.DrawTextBox(node, id, text, context, state);
            }

            return(text);
        }
コード例 #3
0
        /// <summary>
        /// Create a single-line text box.
        /// </summary>
        /// <param name="label">label</param>
        /// <param name="width">width</param>
        /// <param name="text">text</param>
        /// <param name="flags">filter flags</param>
        /// <param name="checker">custom checker per char</param>
        /// <returns>(modified) text</returns>
        public static string TextBox(string label, double width, string text, InputTextFlags flags, Func <char, bool> checker, LayoutOptions?options)
        {
            Window window = GetCurrentWindow();

            if (window.SkipItems)
            {
                return(text);
            }

            int id = window.GetID(label);

            // style apply
            var style = GUIStyle.Basic;

            style.Save();
            style.ApplySkin(GUIControlName.TextBox);
            style.ApplyOption(options);

            // rect
            var  height = style.GetLineHeight();
            var  size   = new Size(width, height);
            Rect rect   = window.GetRect(id, size);

            // interact
            InputTextContext context;

            text = GUIBehavior.TextBoxBehavior(id, rect, text, out bool hovered, out bool active, out context, flags, checker);

            // render
            var d     = window.DrawList;
            var state = active ? GUIState.Active : hovered ? GUIState.Hover : GUIState.Normal;

            if (flags.HaveFlag(InputTextFlags.Password))
            {
                var dotText = new string('*', text.Length);//FIXME bad performance
                GUIAppearance.DrawTextBox(rect, id, dotText, context, state);
            }
            else
            {
                GUIAppearance.DrawTextBox(rect, id, text, context, state);
            }

            style.Restore();

            return(text);
        }
コード例 #4
0
ファイル: TextBox.cs プロジェクト: zwcloud/ImGui
        //TODO multiple/single line TextBox
        public static string TextBox(Rect rect, string label, string text, LayoutOptions?options)
        {
            Window window = GetCurrentWindow();

            if (window.SkipItems)
            {
                return(text);
            }

            var  id        = window.GetID(label);
            var  container = window.AbsoluteVisualList;
            Node node      = (Node)container.Find(visual => visual.Id == id);

            label = Utility.FindRenderedText(label);
            if (node == null)
            {
                //create node
                node             = new Node(id, $"{nameof(TextBox)}<{label}>");
                node.UseBoxModel = true;
                node.RuleSet.Replace(GUISkin.Current[GUIControlName.TextBox]);
                container.Add(node);
            }
            node.RuleSet.ApplyOptions(options);
            node.ActiveSelf = true;

            // rect
            node.Rect = window.GetRect(rect);

            // interact
            InputTextContext context;

            text = GUIBehavior.TextBoxBehavior(id, rect, text, out bool hovered, out bool active, out context);
            var state = active ? GUIState.Active : hovered ? GUIState.Hover : GUIState.Normal;

            // last item state
            window.TempData.LastItemState = state;

            // render
            GUIAppearance.DrawTextBox(node, id, text, context, state);

            return(text);
        }
コード例 #5
0
ファイル: TextBox.cs プロジェクト: ibrahim-elsakka/ImGui-1
        /// <summary>
        /// Create a multi-line text box of fixed size.
        /// </summary>
        /// <param name="str_id">id</param>
        /// <param name="size">fixed size</param>
        /// <param name="text">text</param>
        /// <returns>(modified) text</returns>
        public static string TextBox(string str_id, Size size, string text, LayoutOptions?options)
        {
            Window window = GetCurrentWindow();

            if (window.SkipItems)
            {
                return(text);
            }

            var container = window.RenderTree.CurrentContainer;

            var  id   = window.GetID(str_id);
            Node node = container.GetNodeById(id);

            if (node == null)
            {
                //create node
                node             = new Node(id, $"{nameof(TextBox)}<{str_id}>");
                node.UseBoxModel = true;
                node.RuleSet.Replace(GUISkin.Current[GUIControlName.TextBox]);
                node.AttachLayoutGroup(true);
                node.RuleSet.ApplyOptions(GUILayout.Width(size.Width).Height(size.Height));
            }

            var textNodeId = window.GetID($"{nameof(TextBox)}<{str_id}>_Text");
            var textNode   = node.GetDirectNodeById(textNodeId);

            if (textNode == null)
            {
                textNode = new Node(textNodeId);
            }
            var textSize = node.RuleSet.CalcContentBoxSize(text, node.State);

            textNode.RuleSet.Replace(GUISkin.Current[GUIControlName.TextBox]);
            textNode.ContentSize = textSize;
            textNode.ActiveSelf  = true;
            node.AppendChild(textNode);

            container.AppendChild(node);
            node.RuleSet.ApplyOptions(options);
            node.ActiveSelf = true;

            // rect
            node.Rect     = window.GetRect(node.Id);
            textNode.Rect = window.GetRect(textNode.Id);

            // interact
            text = GUIBehavior.TextBoxBehavior(textNode.Id, textNode.Rect, text,
                                               out bool hovered, out bool active, out var context);

            // render
            var state = active ? GUIState.Active : hovered ? GUIState.Hover : GUIState.Normal;

            GUIAppearance.DrawTextBox(textNode, textNode.Id, text, context, state);

            // draw the box
            var dc = node.RenderOpen();

            dc.DrawBoxModel(node.RuleSet, node.Rect);
            dc.Close();

            // do GUI logic for possible scroll-bars
            node.OnGUI();

            return(text);
        }