]> O.S.I.I.S - jp/crow.git/commitdiff
unshownpostaction for visible state, Label.SetCurrentLocation bound check
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 15 Feb 2021 14:07:20 +0000 (15:07 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 15 Feb 2021 14:07:20 +0000 (15:07 +0100)
Crow/Templates/ContextMenu.template
Crow/src/Text/CharLocation.cs
Crow/src/Widgets/Label.cs
Crow/src/Widgets/Widget.cs
Directory.Build.props
Samples/ShowCase/ShowCase.cs
Samples/ShowCase/ui/showcase.crow

index fda09d1f444ce4eaae671c155f4432c57b901e11..5ca0f17752b5092256e6483c8d573b13d408b35f 100644 (file)
@@ -3,9 +3,8 @@
        IsOpened ="true" Visible="{/IsOpened}" Background="Red">
        <Template>
                <HorizontalStack>
-                       <Border Background="DimGrey" Foreground="DimGrey" CornerRadius="5">
-                       <GenericStack Orientation="{./Orientation}" Name="ItemsContainer"
-                               Margin="2"/>
+                       <Border Background="DarkGrey" Foreground="Black" CornerRadius="0">
+                       <GenericStack Orientation="{./Orientation}" Name="ItemsContainer" Margin="2"/>
                        </Border>
                </HorizontalStack>
        </Template>
@@ -17,7 +16,7 @@
                                        IsPopped="{²./IsOpened}" PopWidth="{./PopWidth}" PopHeight="{./PopHeight}">
                                        <Template>
                                                <Border Name="border1"
-                                                               CornerRadius="2"
+                                                               CornerRadius="0"
                                                                MouseEnter="{Foreground=vgradient|0:White|0.2:Grey|0.9:Grey|1:Black}"
                                                                MouseLeave="{Foreground=Transparent}"
                                                                MouseDown="{Foreground=vgradient|0:Black|0.05:Grey|0.85:Grey|1:White}"
@@ -27,7 +26,7 @@
                                                                Background="{./Background}">
                                                                <Label Text="{./Caption}"
                                                                        Foreground="{./Foreground}"
-                                                                       Margin="3" HorizontalAlignment="Left"
+                                                                       Margin="1" HorizontalAlignment="Left"
                                                                        Font="{./Font}" />
                                                </Border>
                                        </Template>
index 1174788ec465aaa3ba4d6f166c5b385d2ca80933..8db2ef64ad799454ac2a7dccbb1cd2d7b1335f17 100644 (file)
@@ -18,7 +18,7 @@ namespace Crow.Text
                        Column = column;
                        VisualCharXPosition = visualX;
                }
-               public bool HasVisualX => Column >= 0 && VisualCharXPosition >= 0;
+               public bool HasVisualX => Column >= 0 && VisualCharXPosition >= 0;              
                public void ResetVisualX () => VisualCharXPosition = -1;
                public static bool operator == (CharLocation a, CharLocation b)
                        => a.Equals (b);
index 771d57ccbfb9eaae5de74fe4ff40cd6dbfc20101..9429a516d3b73303a402fd52ce18e624ea81f820 100644 (file)
@@ -53,7 +53,7 @@ namespace Crow
                                        return;
                                currentLoc = value;
                                NotifyValueChanged ("CurrentLine", CurrentLine);
-                               NotifyValueChanged ("CurrentCollumn", CurrentColumn);
+                               NotifyValueChanged ("CurrentColumn", CurrentColumn);
             }
         }
                public int CurrentLine {
@@ -79,7 +79,9 @@ namespace Crow
                /// </summary>
                /// <param name="position">Absolute character position in text.</param>
                public void SetCursorPosition (int position) {
-                       CurrentLoc = lines.GetLocation (position);
+                       CharLocation loc = lines.GetLocation (position);
+                       loc.Column = Math.Min (loc.Column, lines[loc.Line].Length);
+                       CurrentLoc = loc;
                }
 
                protected LineCollection lines;
@@ -362,7 +364,11 @@ namespace Crow
                        bool selectionNotEmpty = false;
 
                        if (HasFocus) {
-                               updateLocation (gr, cb.Width, ref currentLoc);
+                               if (currentLoc?.Column < 0) {
+                                       updateLocation (gr, cb.Width, ref currentLoc);
+                                       NotifyValueChanged ("CurrentColumn", CurrentColumn);
+                               } else
+                                       updateLocation (gr, cb.Width, ref currentLoc);
                                if (selectionStart.HasValue) {
                                        updateLocation (gr, cb.Width, ref selectionStart);
                                        if (CurrentLoc.Value != selectionStart.Value)
@@ -490,8 +496,13 @@ namespace Crow
                                ctx.SetFontSize (Font.Size);
                                ctx.FontOptions = Interface.FontRenderingOptions;
                                ctx.Antialias = Interface.Antialias;
-                               lock (linesMutex)
-                                       updateLocation (ctx, ClientRectangle.Width, ref currentLoc);
+                               lock (linesMutex) {                                     
+                                       if (currentLoc?.Column < 0) {
+                                               updateLocation (ctx, ClientRectangle.Width, ref currentLoc);
+                                               NotifyValueChanged ("CurrentColumn", CurrentColumn);
+                                       } else
+                                               updateLocation (ctx, ClientRectangle.Width, ref currentLoc);
+                               }
                                textCursor = null;
                        }
 
index 257bfac07003f5ac59d3cb26d9a7016aed4de8b4..519d7019c1fc9bfaebf4c628c92443b3849ed8cb 100644 (file)
@@ -889,14 +889,10 @@ namespace Crow
 
                                isVisible = value;
 
-                               RegisterForLayouting (LayoutingType.Sizing);
-
-                               if (!isVisible && IFace.HoverWidget != null) {                                  
-                                       if (IFace.HoverWidget.IsOrIsInside (this)) {
-                                               //IFace.HoverWidget = null;
-                                               IFace.OnMouseMove (IFace.MousePosition.X, IFace.MousePosition.Y);
-                                       }
-                               }
+                               if (Visible)
+                                       RegisterForLayouting (LayoutingType.Sizing);
+                               else
+                                       unshownPostActions ();
 
                                NotifyValueChangedAuto (isVisible);
                        }
@@ -2102,6 +2098,13 @@ namespace Crow
                        }
                        if (IFace.HoverWidget != null) {
                                if (IFace.HoverWidget.IsOrIsInside (this)) {
+                                       Widget w = IFace.HoverWidget;
+                                       MouseMoveEventArgs e = new MouseMoveEventArgs (IFace.MousePosition.X, IFace.MousePosition.Y, 0, 0);
+                                       while (w != this) {
+                                               w.onMouseLeave (this, e);
+                                               w = w.FocusParent;
+                                       }
+                                       this.onMouseLeave (this, e);
                                        IFace.HoverWidget = null;
                                        IFace.OnMouseMove (IFace.MousePosition.X, IFace.MousePosition.Y);
                                }
index fa3323c8c401060b918c8b3018df3dbc54e974e2..89659e1d463c1acbb0296f1818d2327deedcb3e9 100644 (file)
@@ -7,7 +7,7 @@
                <Authors>Jean-Philippe Bruyère</Authors>           
                <LangVersion>7.3</LangVersion>
                
-               <CrowVersion>0.9.3</CrowVersion>
+               <CrowVersion>0.9.4</CrowVersion>
                <CrowPackageVersion>$(CrowVersion)-beta</CrowPackageVersion>
                <CrowStbSharp>true</CrowStbSharp>
        </PropertyGroup>
index db91b1cfd72239c96e4e0a3ddbb898b65d16c019..23b7b151a344e5478b88e131a30896bd26ae619f 100644 (file)
@@ -78,7 +78,7 @@ namespace ShowCase
                public static Picture IcoPaste = new SvgPicture ("#Icons.paste-on-document.svg");
 
                public Command CMDNew, CMDSave, CMDSaveAs, CMDUndo, CMDRedo, CMDCut, CMDCopy, CMDPaste;
-
+               public CommandGroup ContextCommands => new CommandGroup (CMDNew, CMDSave, CMDSaveAs);
                void initCommands ()
                {
                        CMDNew = new Command (new Action (onNewFile)) { Caption = "New", Icon = "#Icons.blank-file.svg", CanExecute = true };
index 6924fb540851a0f7cb7dce1b07c8ca65a379d44a..779078fb47c5e8e884c9d4d487fe548a4d97da77 100644 (file)
                                <Button Style="IcoButton" Command="{CMDNew}" />
                                <Button Style="IcoButton" Command="{CMDSave}" />
                                <Button Style="IcoButton" Command="{CMDSaveAs}" />
+                               <Widget Width="Stretched"/>
+                               <Label Text="Line:" Foreground="Grey"/>
+                               <Label Text="{../../tb.CurrentLine}"  Margin="2"/>
+                               <Label Text="Col:" Foreground="Grey"/>
+                               <Label Text="{../../tb.CurrentColumn}" Margin="2"/>
                        </HorizontalStack>
                        <HorizontalStack>
-                               <TextBox Name="tb" Text="{²Source}" Multiline="true" Font="consolas, 12" Focusable="true" Height="Stretched" Width="Stretched" />
+                               <TextBox Name="tb" Text="{²Source}" Multiline="true" Font="consolas, 12" Focusable="true" Height="Stretched" Width="Stretched"
+                                                ContextCommands="{ContextCommands}"/>
                                <ScrollBar Value="{²../tb.ScrollY}"
                                                LargeIncrement="{../tb.PageHeight}" SmallIncrement="1"
                                                CursorRatio="{../tb.ChildHeightRatio}" Maximum="{../tb.MaxScrollY}" />