diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2021-02-15 15:07:20 +0100 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2021-02-15 15:07:20 +0100 |
| commit | bbada8a0836b0c41350f6f9878ead8986dde9377 (patch) | |
| tree | f521aaf302294eab178799160488d675b2c470d2 | |
| parent | 0ed55f30954b5fb43ea68dc4e0e62266f7afbffb (diff) | |
unshownpostaction for visible state, Label.SetCurrentLocation bound check
| -rw-r--r-- | Crow/Templates/ContextMenu.template | 9 | ||||
| -rw-r--r-- | Crow/src/Text/CharLocation.cs | 2 | ||||
| -rw-r--r-- | Crow/src/Widgets/Label.cs | 21 | ||||
| -rw-r--r-- | Crow/src/Widgets/Widget.cs | 19 | ||||
| -rw-r--r-- | Directory.Build.props | 2 | ||||
| -rw-r--r-- | Samples/ShowCase/ShowCase.cs | 2 | ||||
| -rw-r--r-- | Samples/ShowCase/ui/showcase.crow | 8 |
7 files changed, 41 insertions, 22 deletions
diff --git a/Crow/Templates/ContextMenu.template b/Crow/Templates/ContextMenu.template index fda09d1f..5ca0f177 100644 --- a/Crow/Templates/ContextMenu.template +++ b/Crow/Templates/ContextMenu.template @@ -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> diff --git a/Crow/src/Text/CharLocation.cs b/Crow/src/Text/CharLocation.cs index 1174788e..8db2ef64 100644 --- a/Crow/src/Text/CharLocation.cs +++ b/Crow/src/Text/CharLocation.cs @@ -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); diff --git a/Crow/src/Widgets/Label.cs b/Crow/src/Widgets/Label.cs index 771d57cc..9429a516 100644 --- a/Crow/src/Widgets/Label.cs +++ b/Crow/src/Widgets/Label.cs @@ -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; } diff --git a/Crow/src/Widgets/Widget.cs b/Crow/src/Widgets/Widget.cs index 257bfac0..519d7019 100644 --- a/Crow/src/Widgets/Widget.cs +++ b/Crow/src/Widgets/Widget.cs @@ -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); } diff --git a/Directory.Build.props b/Directory.Build.props index fa3323c8..89659e1d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -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> diff --git a/Samples/ShowCase/ShowCase.cs b/Samples/ShowCase/ShowCase.cs index db91b1cf..23b7b151 100644 --- a/Samples/ShowCase/ShowCase.cs +++ b/Samples/ShowCase/ShowCase.cs @@ -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 }; diff --git a/Samples/ShowCase/ui/showcase.crow b/Samples/ShowCase/ui/showcase.crow index 6924fb54..779078fb 100644 --- a/Samples/ShowCase/ui/showcase.crow +++ b/Samples/ShowCase/ui/showcase.crow @@ -17,9 +17,15 @@ <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}" /> |