From bbada8a0836b0c41350f6f9878ead8986dde9377 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Mon, 15 Feb 2021 15:07:20 +0100 Subject: [PATCH] unshownpostaction for visible state, Label.SetCurrentLocation bound check --- Crow/Templates/ContextMenu.template | 9 ++++----- Crow/src/Text/CharLocation.cs | 2 +- Crow/src/Widgets/Label.cs | 21 ++++++++++++++++----- Crow/src/Widgets/Widget.cs | 19 +++++++++++-------- Directory.Build.props | 2 +- Samples/ShowCase/ShowCase.cs | 2 +- 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"> @@ -17,7 +16,7 @@ IsPopped="{²./IsOpened}" PopWidth="{./PopWidth}" PopHeight="{./PopHeight}"> 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 /// /// Absolute character position in text. 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 @@ Jean-Philippe Bruyère 7.3 - 0.9.3 + 0.9.4 $(CrowVersion)-beta true 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 @@