diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2020-06-04 18:14:36 +0200 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2020-06-04 18:14:36 +0200 |
| commit | 0eb0a6932d5bd58d874face8b0aeb7dc41f7c81c (patch) | |
| tree | 764b6a0e3f26cc1c15f734bb219e3fa3a5d5add1 | |
| parent | 89ef03b5bf7a317a290c5161d5e5cc1c6df8bc1d (diff) | |
SearchExtMethod in CrowAssemblies, textbox xtranslation following cursor
| -rw-r--r-- | Crow/Templates/DirectoryView.template | 2 | ||||
| -rw-r--r-- | Crow/src/Cairo/CairoHelpers.cs | 8 | ||||
| -rw-r--r-- | Crow/src/ExtensionsMethods.cs | 9 | ||||
| -rw-r--r-- | Crow/src/IML/CompilerServices.cs | 26 | ||||
| -rw-r--r-- | Crow/src/IML/MemberAddress.cs | 9 | ||||
| -rw-r--r-- | Crow/src/Mono.Cairo/Context.cs | 2 | ||||
| -rw-r--r-- | Crow/src/Widgets/Border.cs | 20 | ||||
| -rw-r--r-- | Crow/src/Widgets/ColorSlider.cs | 4 | ||||
| -rw-r--r-- | Crow/src/Widgets/DirectoryView.cs | 4 | ||||
| -rw-r--r-- | Crow/src/Widgets/FileDialog.cs | 31 | ||||
| -rw-r--r-- | Crow/src/Widgets/HueSelector.cs | 4 | ||||
| -rw-r--r-- | Crow/src/Widgets/Label.cs | 47 | ||||
| -rw-r--r-- | Crow/src/Widgets/SaturationValueSelector.cs | 4 | ||||
| -rw-r--r-- | Crow/src/Widgets/TextBox.cs | 13 | ||||
| -rw-r--r-- | Samples/ShowCase/ShowCase.cs | 7 | ||||
| -rw-r--r-- | Samples/ShowCase/ui/showcase.crow | 8 |
16 files changed, 112 insertions, 86 deletions
diff --git a/Crow/Templates/DirectoryView.template b/Crow/Templates/DirectoryView.template index d2193338..36f042cf 100644 --- a/Crow/Templates/DirectoryView.template +++ b/Crow/Templates/DirectoryView.template @@ -12,7 +12,7 @@ </HorizontalStack> </Border> </ItemTemplate> - <ItemTemplate DataType="System.IO.DirectoryInfo" Data="GetFileSystemInfos"> + <ItemTemplate DataType="System.IO.DirectoryInfo" Data="GetFileSystemInfosOrdered"> <Expandable Caption="{Name}" MouseDoubleClick="/onClickForExpand"> <Template> <VerticalStack> diff --git a/Crow/src/Cairo/CairoHelpers.cs b/Crow/src/Cairo/CairoHelpers.cs index d5263df3..a2e036ac 100644 --- a/Crow/src/Cairo/CairoHelpers.cs +++ b/Crow/src/Cairo/CairoHelpers.cs @@ -101,13 +101,13 @@ namespace Crow gr.Save(); r.Inflate((int)-width / 2, (int)-width / 2); gr.LineWidth = width; - gr.SetSourceColor(Colors.White); + gr.SetSource(Colors.White); gr.MoveTo(r.BottomLeft); gr.LineTo(r.TopLeft); gr.LineTo(r.TopRight); gr.Stroke(); - gr.SetSourceColor(Colors.DarkGrey); + gr.SetSource(Colors.DarkGrey); gr.MoveTo(r.TopRight); gr.LineTo(r.BottomRight); gr.LineTo(r.BottomLeft); @@ -120,12 +120,12 @@ namespace Crow gr.Save(); r.Inflate((int)-width / 2, (int)-width / 2); gr.LineWidth = width; - gr.SetSourceColor(Colors.DarkGrey); + gr.SetSource(Colors.DarkGrey); gr.MoveTo(r.BottomLeft); gr.LineTo(r.TopLeft); gr.LineTo(r.TopRight); gr.Stroke(); - gr.SetSourceColor(Colors.White); + gr.SetSource(Colors.White); gr.MoveTo(r.TopRight); gr.LineTo(r.BottomRight); gr.LineTo(r.BottomLeft); diff --git a/Crow/src/ExtensionsMethods.cs b/Crow/src/ExtensionsMethods.cs index 69edfe8e..0ac07c11 100644 --- a/Crow/src/ExtensionsMethods.cs +++ b/Crow/src/ExtensionsMethods.cs @@ -3,6 +3,8 @@ // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; +using System.IO; +using System.Linq; using System.Linq.Expressions; namespace Crow @@ -132,10 +134,6 @@ namespace Crow ctx.Stroke (); } - public static void SetSourceColor(this Cairo.Context ctx, Color c) - { - ctx.SetSourceRGBA(c.R,c.G,c.B,c.A); - } public static void AddColorStop(this Cairo.Gradient grad, double offset, Color c) { grad.AddColorStop (offset, c); @@ -192,6 +190,9 @@ namespace Crow return null; } + + public static FileSystemInfo [] GetFileSystemInfosOrdered (this DirectoryInfo di) + => di.GetFileSystemInfos ().OrderBy (f => f.Attributes).ThenBy (f => f.Name).ToArray (); } } diff --git a/Crow/src/IML/CompilerServices.cs b/Crow/src/IML/CompilerServices.cs index cf3ee73f..ea25e9bb 100644 --- a/Crow/src/IML/CompilerServices.cs +++ b/Crow/src/IML/CompilerServices.cs @@ -382,19 +382,27 @@ namespace Crow.IML //System.Diagnostics.Debug.WriteLine ($"*** search extension method: {t};{methodName} => key={key}"); MethodInfo mi = null; - mi = GetExtensionMethods (Assembly.GetEntryAssembly (), t, methodName); - if (mi == null) - mi = GetExtensionMethods (t.Module.Assembly, t, methodName); + if (!TryGetExtensionMethods (Assembly.GetEntryAssembly (), t, methodName, out mi)) { + if (!TryGetExtensionMethods (t.Module.Assembly, t, methodName, out mi)) { + foreach (Assembly a in Interface.crowAssemblies) { + if (TryGetExtensionMethods (a, t, methodName, out mi)) + break; + } + if (mi == null) + TryGetExtensionMethods (Assembly.GetExecutingAssembly (), t, methodName, out mi);//crow Assembly + } + } //add key even if mi is null to prevent searching again and again for propertyless bindings knownExtMethods.Add (key, mi); return mi; } - public static MethodInfo GetExtensionMethods (Assembly assembly, Type extendedType, string methodName) + public static bool TryGetExtensionMethods (Assembly assembly, Type extendedType, string methodName, out MethodInfo foundMI) { + foundMI = null; if (assembly == null) - return null; + return false; foreach (Type t in assembly.GetTypes ().Where (ty => ty.IsDefined (typeof (ExtensionAttribute), false))) { foreach (MethodInfo mi in t.GetMethods @@ -403,14 +411,16 @@ namespace Crow.IML m.GetParameters ().Length == 1)) { Type curType = extendedType; while (curType != null) { - if (mi.GetParameters () [0].ParameterType == curType) - return mi; + if (mi.GetParameters () [0].ParameterType == curType) { + foundMI = mi; + return true; + } curType = curType.BaseType; } } } - return null; + return false; } /// <summary> /// retrieve event handler in class or ancestors diff --git a/Crow/src/IML/MemberAddress.cs b/Crow/src/IML/MemberAddress.cs index 365a1994..6797e8ea 100644 --- a/Crow/src/IML/MemberAddress.cs +++ b/Crow/src/IML/MemberAddress.cs @@ -101,13 +101,8 @@ namespace Crow.IML Type t = Address.LastOrDefault ().CrowType; member = t.GetMember (memberName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).FirstOrDefault (); -#region search for extensions methods if member not found in type - if (member == null && !string.IsNullOrEmpty (memberName)) { - Assembly a = Assembly.GetExecutingAssembly (); - string mn = memberName; - member = CompilerServices.GetExtensionMethods (a, t, mn); - } -#endregion + if (member == null && !string.IsNullOrEmpty (memberName)) + member = CompilerServices.SearchExtMethod (t, memberName); return member != null; } diff --git a/Crow/src/Mono.Cairo/Context.cs b/Crow/src/Mono.Cairo/Context.cs index 9be56c02..7ed5e62c 100644 --- a/Crow/src/Mono.Cairo/Context.cs +++ b/Crow/src/Mono.Cairo/Context.cs @@ -324,7 +324,7 @@ namespace Crow.Cairo { get { return NativeMethods.cairo_get_reference_count (handle); } } - public void SetSourceColor (Color color) + public void SetSource (Color color) { NativeMethods.cairo_set_source_rgba (handle, color.R / 255.0, color.G / 255.0, color.B / 255.0, color.A / 255.0); } diff --git a/Crow/src/Widgets/Border.cs b/Crow/src/Widgets/Border.cs index 51758cd0..cc331e78 100644 --- a/Crow/src/Widgets/Border.cs +++ b/Crow/src/Widgets/Border.cs @@ -137,7 +137,7 @@ namespace Crow double radius = CornerRadius; if ((radius > rBack.Height / 2.0) || (radius > rBack.Width / 2.0)) radius = Math.Min (rBack.Height / 2.0, rBack.Width / 2.0); - gr.SetSourceColor (sunkenColor); + gr.SetSource (sunkenColor); gr.MoveTo (0.5 + rBack.Left, -0.5 + rBack.Bottom - radius); gr.ArcNegative (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius, Math.PI, Math.PI * 0.75); gr.MoveTo (0.5 + rBack.Left, -0.5 + rBack.Bottom - radius); @@ -156,7 +156,7 @@ namespace Crow gr.Arc (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius - 1.0, Math.PI / 2.0, Math.PI * 0.75); gr.Stroke (); - gr.SetSourceColor (raisedColor); + gr.SetSource (raisedColor); gr.MoveTo (1.5 + rBack.Left, -1.5 + rBack.Bottom - radius); gr.ArcNegative (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius - 1.0, Math.PI, Math.PI * 0.75); gr.MoveTo (1.5 + rBack.Left, -1.5 + rBack.Bottom - radius); @@ -166,7 +166,7 @@ namespace Crow gr.Arc (-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius - 1.0, Math.PI * 1.5, Math.PI * 1.75); } else { gr.Stroke (); - gr.SetSourceColor (raisedColor); + gr.SetSource (raisedColor); } gr.MoveTo (-0.5 + rBack.Right, 0.5 + rBack.Top + radius); gr.ArcNegative (-0.5 + rBack.Right - radius, 0.5 + rBack.Top + radius, radius, 0, -Math.PI * 0.25); @@ -177,7 +177,7 @@ namespace Crow gr.Arc (0.5 + rBack.Left + radius, -0.5 + rBack.Bottom - radius, radius, Math.PI / 2.0, Math.PI * 0.75); gr.Stroke (); } else { - gr.SetSourceColor (sunkenColor); + gr.SetSource (sunkenColor); gr.MoveTo (0.5 + rBack.Left, rBack.Bottom); gr.LineTo (0.5 + rBack.Left, 0.5 + rBack.Y); gr.LineTo (rBack.Right, 0.5 + rBack.Y); @@ -186,13 +186,13 @@ namespace Crow gr.LineTo (-1.5 + rBack.Right, -1.5 + rBack.Bottom); gr.LineTo (2.0 + rBack.Left, -1.5 + rBack.Bottom); gr.Stroke (); - gr.SetSourceColor (raisedColor); + gr.SetSource (raisedColor); gr.MoveTo (1.5 + rBack.Left, -1.0 + rBack.Bottom); gr.LineTo (1.5 + rBack.Left, 1.5 + rBack.Y); gr.LineTo (rBack.Right, 1.5 + rBack.Y); } else { gr.Stroke (); - gr.SetSourceColor (raisedColor); + gr.SetSource (raisedColor); } gr.MoveTo (-0.5 + rBack.Right, 1.5 + rBack.Y); gr.LineTo (-0.5 + rBack.Right, -0.5 + rBack.Bottom); @@ -220,16 +220,16 @@ namespace Crow Foreground.SetAsSource (gr, rBack); else { if (BorderStyle == BorderStyle.Sunken) - gr.SetSourceColor (raisedColor); + gr.SetSource (raisedColor); else - gr.SetSourceColor (sunkenColor); + gr.SetSource (sunkenColor); CairoHelpers.CairoRectangle (gr, rBack, crad, bw); if (BorderStyle == BorderStyle.Sunken) - gr.SetSourceColor (sunkenColor); + gr.SetSource (sunkenColor); else - gr.SetSourceColor (raisedColor); + gr.SetSource (raisedColor); bw /= 2.0; rBack.Width -= (int)Math.Round(bw); diff --git a/Crow/src/Widgets/ColorSlider.cs b/Crow/src/Widgets/ColorSlider.cs index fe2b78dc..1e4029dc 100644 --- a/Crow/src/Widgets/ColorSlider.cs +++ b/Crow/src/Widgets/ColorSlider.cs @@ -221,10 +221,10 @@ namespace Crow break; } - gr.SetSourceColor (Colors.Black); + gr.SetSource (Colors.Black); gr.LineWidth = 2.0; gr.StrokePreserve (); - gr.SetSourceColor (Colors.White); + gr.SetSource (Colors.White); gr.LineWidth = 1.0; gr.Stroke (); } diff --git a/Crow/src/Widgets/DirectoryView.cs b/Crow/src/Widgets/DirectoryView.cs index c664f517..8768d65f 100644 --- a/Crow/src/Widgets/DirectoryView.cs +++ b/Crow/src/Widgets/DirectoryView.cs @@ -94,8 +94,8 @@ namespace Crow if (showFiles && !string.IsNullOrEmpty(fileMask)) fi.AddRange(di.GetFiles(fileMask)); return showHidden ? - fi.ToArray() : - fi.Where(f=>!f.Attributes.HasFlag (FileAttributes.Hidden)).ToArray(); + fi.OrderBy(f=>f.Attributes).ThenBy(f=>f.Name).ToArray() : + fi.Where(f=>!f.Attributes.HasFlag (FileAttributes.Hidden)).OrderBy (f => f.Attributes).ThenBy (f => f.Name).ToArray(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine (ex.ToString ()); return null; diff --git a/Crow/src/Widgets/FileDialog.cs b/Crow/src/Widgets/FileDialog.cs index db66ae9e..4a095e1f 100644 --- a/Crow/src/Widgets/FileDialog.cs +++ b/Crow/src/Widgets/FileDialog.cs @@ -1,37 +1,10 @@ -// -// FileDialog.cs +// Copyright (c) 2013-2020 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> // -// Author: -// Jean-Philippe Bruyère <jp.bruyere@hotmail.com> -// -// Copyright (c) 2013-2017 Jean-Philippe Bruyère -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; -using System.Xml.Serialization; using System.ComponentModel; using System.IO; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text.RegularExpressions; namespace Crow { diff --git a/Crow/src/Widgets/HueSelector.cs b/Crow/src/Widgets/HueSelector.cs index 50b52ae7..3e761b30 100644 --- a/Crow/src/Widgets/HueSelector.cs +++ b/Crow/src/Widgets/HueSelector.cs @@ -131,10 +131,10 @@ namespace Crow break; } - gr.SetSourceColor (Colors.Black); + gr.SetSource (Colors.Black); gr.LineWidth = 2.0; gr.StrokePreserve (); - gr.SetSourceColor (Colors.White); + gr.SetSource (Colors.White); gr.LineWidth = 1.0; gr.Stroke (); } diff --git a/Crow/src/Widgets/Label.cs b/Crow/src/Widgets/Label.cs index 34a2d69e..e500b98f 100644 --- a/Crow/src/Widgets/Label.cs +++ b/Crow/src/Widgets/Label.cs @@ -173,8 +173,44 @@ namespace Crow { else _currentCol = value; NotifyValueChanged ("CurrentColumn", _currentCol); + + Rectangle cb = ClientRectangle; + + if (Width == Measure.Fit || cb.Width >= cachedTextSize.Width) { + xTranslation = 0; + return; + } + int xpos = xposition; + if (xTranslation + xpos > cb.Width) + xTranslation = cb.Width - xpos; + else if (xpos < -xTranslation) + xTranslation = -xpos; + RegisterForRedraw (); } } + int xTranslation = 0; + int xposition { + get { + using (Context gr = new Context (IFace.surf)) { + //Cairo.FontFace cf = gr.GetContextFontFace (); + gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); + gr.SetFontSize (Font.Size); + gr.FontOptions = Interface.FontRenderingOptions; + gr.Antialias = Interface.Antialias; + try { + string l = lines [_currentLine]; + if (_currentCol < l.Length) + l = l.Remove (Math.Min (_currentCol, l.Length)); + l = l.Replace ("\t", new String (' ', Interface.TAB_SIZE)); + return (int)Math.Ceiling (gr.TextExtents (l).XAdvance); + } catch { + System.Diagnostics.Debug.WriteLine ("xpos measuring fault in label"); + return 0; + } + } + } + } + [DefaultValue(0)] public int CurrentLine{ get { return _currentLine; } @@ -258,7 +294,6 @@ namespace Crow { [XmlIgnore]public string SelectedText { get { - if (SelRelease < 0 || SelBegin < 0) return ""; if (selectionStart.Y == selectionEnd.Y) @@ -453,6 +488,9 @@ namespace Crow { gr.FontOptions = Interface.FontRenderingOptions; gr.Antialias = Interface.Antialias; + gr.Save (); + gr.Translate (xTranslation, 0); + rText = new Rectangle(new Size( measureRawSize(LayoutingType.Width), measureRawSize(LayoutingType.Height))); rText.Width -= 2 * Margin; @@ -609,7 +647,7 @@ namespace Crow { if (Selectable) { if (SelRelease >= 0 && i >= selectionStart.Y && i <= selectionEnd.Y) { - gr.SetSourceColor (selBackground); + gr.SetSource (selBackground); Rectangle selRect = lineRect; @@ -632,7 +670,7 @@ namespace Crow { gr.FillPreserve (); gr.Save (); gr.Clip (); - gr.SetSourceColor (SelectionForeground); + gr.SetSource (SelectionForeground); gr.MoveTo (lineRect.X, rText.Y + fe.Ascent + (fe.Ascent+fe.Descent) * i); gr.ShowText (l); gr.Fill (); @@ -640,12 +678,15 @@ namespace Crow { } } } + + gr.Restore (); } #endregion #region Mouse handling void updatemouseLocalPos(Point mpos){ mouseLocalPos = mpos - ScreenCoordinates(Slot).TopLeft - ClientRectangle.TopLeft; + mouseLocalPos.X -= xTranslation; if (mouseLocalPos.X < 0) mouseLocalPos.X = 0; if (mouseLocalPos.Y < 0) diff --git a/Crow/src/Widgets/SaturationValueSelector.cs b/Crow/src/Widgets/SaturationValueSelector.cs index 09c194cd..9732878b 100644 --- a/Crow/src/Widgets/SaturationValueSelector.cs +++ b/Crow/src/Widgets/SaturationValueSelector.cs @@ -69,10 +69,10 @@ namespace Crow gr.Arc (mousePos.X, mousePos.Y, 3.5, 0, Math.PI * 2.0); - gr.SetSourceColor (Colors.Black); + gr.SetSource (Colors.Black); gr.LineWidth = 2.0; gr.StrokePreserve (); - gr.SetSourceColor (Colors.White); + gr.SetSource (Colors.White); gr.LineWidth = 1.0; gr.Stroke (); } diff --git a/Crow/src/Widgets/TextBox.cs b/Crow/src/Widgets/TextBox.cs index 3f166d42..60b43f45 100644 --- a/Crow/src/Widgets/TextBox.cs +++ b/Crow/src/Widgets/TextBox.cs @@ -12,11 +12,6 @@ namespace Crow #region CTOR protected TextBox() {} public TextBox(Interface iface, string style = null) : base (iface, style) { } -// public TextBox(string _initialValue) -// : base(_initialValue) -// { -// -// } #endregion #region GraphicObject overrides @@ -32,15 +27,12 @@ namespace Crow protected override void onDraw (Context gr) { base.onDraw (gr); - FontExtents fe = gr.FontExtents; } #endregion #region Keyboard handling public override void onKeyDown (object sender, KeyEventArgs e) { - base.onKeyDown (sender, e); - Key key = e.Key; switch (key) @@ -170,8 +162,9 @@ namespace Crow default: break; } - - RegisterForGraphicUpdate(); + e.Handled = true; + base.onKeyDown (sender, e); + RegisterForGraphicUpdate (); } public override void onKeyPress (object sender, KeyPressEventArgs e) { diff --git a/Samples/ShowCase/ShowCase.cs b/Samples/ShowCase/ShowCase.cs index 8f3c70ec..daab96e2 100644 --- a/Samples/ShowCase/ShowCase.cs +++ b/Samples/ShowCase/ShowCase.cs @@ -32,6 +32,13 @@ namespace ShowCase NotifyValueChanged ("CurrentDir",CurrentDir); } } + public void goUpDirClick (object sender, MouseButtonEventArgs e) + { + string root = Directory.GetDirectoryRoot (CurrentDir); + if (CurrentDir == root) + return; + CurrentDir = Directory.GetParent (CurrentDir).FullName; + } protected override void OnInitialized () { diff --git a/Samples/ShowCase/ui/showcase.crow b/Samples/ShowCase/ui/showcase.crow index 319021bf..ae8912fe 100644 --- a/Samples/ShowCase/ui/showcase.crow +++ b/Samples/ShowCase/ui/showcase.crow @@ -1,6 +1,12 @@ <?xml version="1.0"?> <HorizontalStack Background="DarkGrey" Margin="2"> - <DirectoryView Name="dv" CurrentDirectory="Interfaces" Width="25%" SelectedItemChanged="Dv_SelectedItemChanged"/> + <VerticalStack Width="25%"> + <HorizontalStack Height="Fit"> + <Image Margin="2" Width="14" Height="14" Path="#Crow.Icons.level-up.svg" MouseClick="./goUpDirClick"/> + <TextBox Text="{²CurrentDir}" Margin="2"/> + </HorizontalStack> + <DirectoryView Name="dv" CurrentDirectory="{CurrentDir}" SelectedItemChanged="Dv_SelectedItemChanged"/> + </VerticalStack> <Splitter Width="6"/> <VerticalStack> <Container Name="CrowContainer" Height="60%" Background="Black"/> |