]> O.S.I.I.S - jp/crow.git/commitdiff
Textbox and Label: insert linebreak, update size if Fit
authorjpbruyere <jp.bruyere@hotmail.com>
Fri, 5 Feb 2016 17:36:22 +0000 (18:36 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Fri, 5 Feb 2016 17:36:22 +0000 (18:36 +0100)
src/GraphicObjects/Label.cs
src/GraphicObjects/TextBox.cs

index ee7dd0459ee8a4fa9e303129567b1af410995d54..d8d214c75948bb1ea9aeeab6dc9cb756986cf0cb 100644 (file)
@@ -271,7 +271,17 @@ namespace Crow
                        CurrentColumn += str.Length;
                        NotifyValueChanged ("Text", Text);
                }
-
+               /// <summary>
+               /// Insert a line break.
+               /// </summary>
+               protected void InsertLineBreak()
+               {
+                       lines.Insert(CurrentLine + 1, lines[CurrentLine].Substring(CurrentColumn));
+                       lines [CurrentLine] = lines [CurrentLine].Substring (0, CurrentColumn);
+                       CurrentLine++;
+                       CurrentColumn = 0;
+                       NotifyValueChanged ("Text", Text);
+               }
                #region GraphicObject overrides
                [XmlAttributeAttribute()][DefaultValue(-1)]
                public override int Width {
index d9003b615ad024712fd8f2e09c26ea990c2eeb9a..143d148f8e1a3dfb9c7e5095bde768ace8efe5d1 100644 (file)
@@ -97,7 +97,10 @@ namespace Crow
                                break;
                        case Key.Enter:
                        case Key.KeypadEnter:
-                               OnTextChanged(this,new TextChangeEventArgs(Text));
+                               if (Multiline)
+                                       this.InsertLineBreak ();
+                               else
+                                       OnTextChanged(this,new TextChangeEventArgs(Text));
                                break;
                        case Key.Escape:
                                Text = "";
@@ -195,6 +198,10 @@ namespace Crow
 
                                break;
                        }
+                       if (Width < 0)
+                               RegisterForLayouting ((int)LayoutingType.Width);
+                       if (Height < 0)
+                               RegisterForLayouting ((int)LayoutingType.Height);
                        registerForGraphicUpdate();
                }
         #endregion