diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2020-04-21 15:45:23 +0200 |
|---|---|---|
| committer | j-p <jp_bruyere@hotmail.com> | 2020-05-10 00:50:02 +0200 |
| commit | df2ad1e48d1aba38e93834bc89566761d56d35ff (patch) | |
| tree | 235f96f4afcbfb226a9f8825e1d966a991a724ed | |
| parent | 6b4d2ea66d5312a2494d49beb6d868da68f11e9d (diff) | |
add facilities for using icons for EnumSelector + path parsing documentation and test
28 files changed, 395 insertions, 267 deletions
@@ -64,7 +64,7 @@ Global GlobalSection(MonoDevelopProperties) = preSolution Policies = $0 $0.StandardHeader = $1 - $1.Text = @Copyright (c) ${Year} ${AuthorName} <${AuthorEmail}>\n\nThis code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) + $1.Text = @Copyright (c) 2013-${Year} ${AuthorName} <${AuthorEmail}>\n\nThis code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) $0.DotNetNamingPolicy = $2 $0.TextStylePolicy = $3 $3.EolMarker = Unix diff --git a/Crow/Default.style b/Crow/Default.style index ba59c54f..666bfd81 100644 --- a/Crow/Default.style +++ b/Crow/Default.style @@ -206,7 +206,7 @@ ArrowBut { } HArrowBut { MouseRepeat="true"; - Focusable="true"; + Focusable="true"; Foreground="Onyx"; Background="vgradient|0:Grey|1:DimGrey"; MouseDown="{Background=vgradient|0:White|0.4:DarkBlue|1:Jet}"; @@ -232,9 +232,8 @@ HScrollBar { Orientation = "Horizontal"; } EnumSelector { - Orientation = "Vertical"; - Height = "Fit"; - Spacing = "0"; + Width = "Fit"; + Height = "Fit"; } labColor { Margin="2"; diff --git a/Crow/Templates/HScrollBar.template b/Crow/Templates/HScrollBar.template index a4ab6416..23a56cd9 100644 --- a/Crow/Templates/HScrollBar.template +++ b/Crow/Templates/HScrollBar.template @@ -2,7 +2,7 @@ <Border BorderWidth="1" Foreground="{./Foreground}" Background="{./Background}"> <GenericStack Orientation="{./Orientation}" Spacing="0"> <Shape Style="HArrowBut" MouseDown="./onScrollBack" - Margin="1" Width="6" Size="10,10" Path="M 0.5,4.5 L 9.5,0.5 L 9.5,9.5 Z"/> + Margin="1" Width="6" Size="10,10" Path="M 0.5,4.5 L 9.5,0.5 L 9.5,9.5 Z G"/> <Slider Name="Slider" Orientation="{./Orientation}" Value="{²./Value}" @@ -15,6 +15,6 @@ Background="Transparent" Foreground="{./Foreground}"/> <Shape Style="HArrowBut" MouseDown="./onScrollForth" - Margin="1" Width="6" Size="10,10" Path="M 0.5,0.5 L 9.5,4.5 L 0.5,9.5 Z"/> + Margin="1" Width="6" Size="10,10" Path="M 0.5,0.5 L 9.5,4.5 L 0.5,9.5 Z G"/> </GenericStack> </Border>
\ No newline at end of file diff --git a/Crow/Templates/ScrollBar.template b/Crow/Templates/ScrollBar.template index 158671e5..27047829 100644 --- a/Crow/Templates/ScrollBar.template +++ b/Crow/Templates/ScrollBar.template @@ -2,7 +2,7 @@ <Border BorderWidth="1" Foreground="{./Foreground}" Background="{./Background}"> <GenericStack Orientation="{./Orientation}" Spacing="0"> <Shape Style="ArrowBut" MouseDown="./onScrollBack" - Margin="1" Height="6" Size="10,10" Path="M 4.5,0.5 L 9.5,9.5 L 0.5,9.5 Z"/> + Margin="1" Height="6" Size="10,10" Path="M 4.5,0.5 L 9.5,9.5 L 0.5,9.5 Z G"/> <Slider Name="Slider" Orientation="{./Orientation}" Value="{²./Value}" @@ -15,6 +15,6 @@ Foreground="{./Foreground}" Background="Transparent"/> <Shape Style="ArrowBut" MouseDown="./onScrollForth" - Margin="1" Height="6" Size="10,10" Path="M 0.5,0.5 L 9.5,0.5 L 4.5,9.5 Z"/> + Margin="1" Height="6" Size="10,10" Path="M 0.5,0.5 L 9.5,0.5 L 4.5,9.5 Z G"/> </GenericStack> </Border>
\ No newline at end of file diff --git a/Crow/Templates/Spinner.template b/Crow/Templates/Spinner.template index 1bac0d1d..f81a128a 100644 --- a/Crow/Templates/Spinner.template +++ b/Crow/Templates/Spinner.template @@ -6,7 +6,7 @@ Text="{²./Value}" TextAlignment="Right" Margin="0"/> </Border> <VerticalStack MinimumSize="13,13" Width="16" Height="Stretched" Spacing="1" Margin="1"> - <Shape Style="ArrowBut" Height="50%" MouseDown="./onUp" Size="10,10" Path="M 4.5,0.5 L 9.5,9.5 L 0.5,9.5 Z"/> - <Shape Style="ArrowBut" Height="50%" MouseDown="./onDown" Size="10,10" Path="M 0.5,0.5 L 9.5,0.5 L 4.5,9.5 Z"/> + <Shape Style="ArrowBut" Height="50%" MouseDown="./onUp" Size="10,10" Path="M 4.5,0.5 L 9.5,9.5 L 0.5,9.5 Z G"/> + <Shape Style="ArrowBut" Height="50%" MouseDown="./onDown" Size="10,10" Path="M 0.5,0.5 L 9.5,0.5 L 4.5,9.5 Z G"/> </VerticalStack> </HorizontalStack> diff --git a/Crow/src/Enums.cs b/Crow/src/Enums.cs index 4c55d451..df741d50 100644 --- a/Crow/src/Enums.cs +++ b/Crow/src/Enums.cs @@ -1,37 +1,10 @@ -// -// Enums.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. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) namespace Crow { - public enum Orientation + public enum Orientation { Horizontal, Vertical diff --git a/Crow/src/Widgets/Container.cs b/Crow/src/Widgets/Container.cs index ce54514e..07ccfa9b 100644 --- a/Crow/src/Widgets/Container.cs +++ b/Crow/src/Widgets/Container.cs @@ -1,28 +1,6 @@ +// Copyright (c) 2013-2020 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> // -// Container.cs -// -// 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; diff --git a/Crow/src/Widgets/EnumSelector.cs b/Crow/src/Widgets/EnumSelector.cs index fa43e3b3..bac4f5f6 100644 --- a/Crow/src/Widgets/EnumSelector.cs +++ b/Crow/src/Widgets/EnumSelector.cs @@ -11,6 +11,11 @@ namespace Crow /// Convenient widget for selecting value among enum values. This is a templated control /// expecting a 'Group' widget named 'Content' inside the template to handle the enum values display. /// </summary> + /// <remarks> + /// Instanced RadioButton's names are set to enum values, and Tags are populated with a string build with + /// 'IconsPrefix+EnumValueName+IconsExtension to ease associating icons with values. + /// There's many other way to use this control, for examples see 'testEnumSelector.crow' in the samples directory. + /// </remarks> public class EnumSelector : TemplatedControl { #region CTOR @@ -31,11 +36,33 @@ namespace Crow #region private fields Enum enumValue; Type enumType; - string rbStyle; + string rbStyle, iconsPrefix, iconsExtension; IML.Instantiator radioButtonITor; #endregion #region public properties + [DefaultValue ("#Icons.")] + public string IconsPrefix { + get => iconsPrefix; + set { + if (iconsPrefix == value) + return; + iconsPrefix = value; + forceRefresh (); + NotifyValueChanged ("IconsPrefix", iconsPrefix); + } + } + [DefaultValue (".svg")] + public string IconsExtension { + get => iconsExtension; + set { + if (iconsExtension == value) + return; + iconsExtension = value; + forceRefresh (); + NotifyValueChanged ("IconsExtension", iconsExtension); + } + } /// <summary> /// Enum values are presented with RadioButton controls. Here you may specify a template to use /// for the radio buttons. @@ -48,12 +75,7 @@ namespace Crow return; rbStyle = value; radioButtonITor = null; - //force refresh to use new template if values are already displayed - if (enumValue != null) { - Enum tmp = enumValue; - enumValue = null; - EnumValue = tmp; - } + forceRefresh (); NotifyValueChanged ("RadioButtonStyle", rbStyle); } } @@ -80,12 +102,20 @@ namespace Crow RadioButton rb = radioButtonITor.CreateInstance<RadioButton> (); rb.Caption = en; rb.LogicalParent = this; + rb.Tag = $"{iconsPrefix}{en}{IconsExtension}"; if (enumValue.ToString () == en) rb.IsChecked = true; rb.Checked += (sender, e) => (((RadioButton)sender).LogicalParent as EnumSelector).EnumValue = (Enum)Enum.Parse (enumType, (sender as RadioButton).Caption); enumValueContainer.AddChild (rb); } - + + } else { + foreach (RadioButton rb in enumValueContainer.Children) { + if (rb.Caption == enumValue.ToString ()) + rb.IsChecked = true; + else if (rb.IsChecked) + rb.IsChecked = false; + } } } else enumValueContainer.ClearChildren (); @@ -96,6 +126,15 @@ namespace Crow } #endregion + //force refresh to use new template if values are already displayed + void forceRefresh () + { + if (enumValue != null) { + Enum tmp = enumValue; + enumValue = null; + EnumValue = tmp; + } + } } } diff --git a/Crow/src/Widgets/GroupBox.cs b/Crow/src/Widgets/GroupBox.cs index 2e32ddd5..0ec191ad 100644 --- a/Crow/src/Widgets/GroupBox.cs +++ b/Crow/src/Widgets/GroupBox.cs @@ -1,28 +1,6 @@ -// -// GroupBox.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; diff --git a/Crow/src/Widgets/ScrollBar.cs b/Crow/src/Widgets/ScrollBar.cs index cf6201e4..08ee5e09 100644 --- a/Crow/src/Widgets/ScrollBar.cs +++ b/Crow/src/Widgets/ScrollBar.cs @@ -55,9 +55,9 @@ namespace Crow _orientation = value; NotifyValueChanged ("Orientation", _orientation); if (_orientation == Orientation.Horizontal) - NotifyValueChanged ("ScrollBackShape", "M 1.5,3.5 L 6.5,0.5 L 6.5,6.5 Z"); + NotifyValueChanged ("ScrollBackShape", "M 1.5,3.5 L 6.5,0.5 L 6.5,6.5 Z G"); else - NotifyValueChanged ("ScrollBackShape", "M 4.5,0.5 L 9.5,9.5 L 0.5,9.5 Z"); + NotifyValueChanged ("ScrollBackShape", "M 4.5,0.5 L 9.5,9.5 L 0.5,9.5 Z G"); RegisterForGraphicUpdate (); } diff --git a/Crow/src/Widgets/Shape.cs b/Crow/src/Widgets/Shape.cs index 952c3738..ac006b82 100644 --- a/Crow/src/Widgets/Shape.cs +++ b/Crow/src/Widgets/Shape.cs @@ -10,76 +10,143 @@ using Crow.Cairo; namespace Crow { + /// <summary> + /// String Parser for drawing shape + /// </summary> + /// <remarks> + /// All fields are separated by one or more space. Each statement is composed of one letter followed by 0 to n + /// double parameters. The following list enumerate available instructions: + /// - M x y: Move to (x,y) absolute coordinate. + /// - m x y: Relative move to by x in the horizontal direction and y in the vertical. + /// - L x y: Line to (x,y) + /// - l x y: trace line from current point by moving pen by x and y in each direction. + /// - R x y w h: draw rectangle at (x,y) with width and height equal to w and h. + /// - C x1 y1 x2 y2 x3 y3: draw bezier curve with current point as first control point, and parameters as others. + /// - c x1 y1 x2 y2 x3 y3: draw bezier curve with control points relative to current position. + /// - A x y r a1 a2: draw positive arc at (x,y) with radius r from angle a1 to angle a2. + /// - N x y r a1 a2: draw negative arc at (x,y) with radius r from angle a1 to angle a2. + /// - Z: close path + /// - F: fill path. + /// - f: fill preserve. + /// - G: stroke path. + /// - g: stroke preserve. + /// - S x: set line width to x. + /// - O r g b a: set solid color as source with rgba values. + /// </remarks> public class PathParser : StringReader { - public PathParser (string str) : base (str) {} + public PathParser (string str) : base (str) { } - double readDouble () { - StringBuilder tmp = new StringBuilder(); + double readDouble () + { + StringBuilder tmp = new StringBuilder (); - while (Peek () >= 0) { - char c = (char)Read(); - if (c.IsWhiteSpaceOrNewLine()) { + while (Peek () >= 0) { + char c = (char)Read (); + if (c.IsWhiteSpaceOrNewLine ()) { if (tmp.Length == 0) continue; else break; } else if (c == ',') - break; + break; tmp.Append (c); } return double.Parse (tmp.ToString ()); } - public void Draw (Context gr) { - while (Peek () >= 0) { - char c = (char)Read (); - if (c.IsWhiteSpaceOrNewLine ()) - continue; - switch (c) { - case 'M': - gr.MoveTo (readDouble (), readDouble ()); - break; - case 'm': - gr.RelMoveTo (readDouble (), readDouble ()); - break; - case 'L': - gr.LineTo (readDouble (), readDouble ()); - break; - case 'l': - gr.RelLineTo (readDouble (), readDouble ()); - break; - case 'C': - gr.CurveTo (readDouble (), readDouble (), readDouble (), readDouble (), readDouble (), readDouble ()); - break; - case 'c': - gr.RelCurveTo (readDouble (), readDouble (), readDouble (), readDouble (), readDouble (), readDouble ()); - break; - case 'Z': - gr.ClosePath (); - break; - case 'F': - gr.Fill (); - break; - case 'G': - gr.Stroke (); - break; - default: - throw new Exception ("Invalid character in path string of Shape control"); + public void Draw (Context gr, bool measure = false) + { + try { + while (Peek () >= 0) { + char c = (char)Read (); + if (c.IsWhiteSpaceOrNewLine ()) + continue; + switch (c) { + case 'M': + gr.MoveTo (readDouble (), readDouble ()); + break; + case 'm': + gr.RelMoveTo (readDouble (), readDouble ()); + break; + case 'L': + gr.LineTo (readDouble (), readDouble ()); + break; + case 'l': + gr.RelLineTo (readDouble (), readDouble ()); + break; + case 'R': + gr.Rectangle (readDouble (), readDouble (), readDouble (), readDouble ()); + break; + case 'C': + gr.CurveTo (readDouble (), readDouble (), readDouble (), readDouble (), readDouble (), readDouble ()); + break; + case 'c': + gr.RelCurveTo (readDouble (), readDouble (), readDouble (), readDouble (), readDouble (), readDouble ()); + break; + case 'A': + gr.Arc (readDouble (), readDouble (), readDouble (), readDouble (), readDouble ()); + break; + case 'N': + gr.ArcNegative (readDouble (), readDouble (), readDouble (), readDouble (), readDouble ()); + break; + case 'Z': + gr.ClosePath (); + break; + case 'f': + if (measure) + continue; + gr.FillPreserve (); + break; + case 'g': + if (measure) + break; + gr.StrokePreserve (); + break; + case 'F': + if (measure) + break; + gr.Fill (); + break; + case 'G': + if (measure) + break; + gr.Stroke (); + break; + case 'S': + gr.LineWidth = readDouble (); + break; + case 'O': + if (measure) { + readDouble (); readDouble (); readDouble (); readDouble (); + break; + } + gr.SetSourceRGBA (readDouble (), readDouble (), readDouble (), readDouble ()); + break; + default: + throw new Exception ("Invalid character in path string of Shape control"); + } } - } + } catch (Exception ex) { + System.Diagnostics.Debug.WriteLine ($"Error parsing path: {ex.Message}"); + } } } + /// <summary> + /// Widget for drawing a shape define with a path expression as defined in the PathParser. + /// </summary> public class Shape : Widget { #region CTOR - protected Shape () : base() {} - public Shape (Interface iface) : base (iface) {} + protected Shape () : base () { } + public Shape (Interface iface) : base (iface) { } #endregion string path; double strokeWidth; - Size size; - + Size size; + /// <summary> + /// Path expression, for syntax see 'PathParser'. + /// </summary> public string Path { get { return path; } set { @@ -91,7 +158,11 @@ namespace Crow RegisterForGraphicUpdate (); } } - [DefaultValue(1.0)] + /// <summary> + /// Default stroke width, may be overriden by a 'S' command in the path string. + /// </summary> + /// <value>The width of the stoke.</value> + [DefaultValue (1.0)] public double StokeWidth { get { return strokeWidth; } set { @@ -103,70 +174,66 @@ namespace Crow RegisterForGraphicUpdate (); } } - [DefaultValue("0,0")] - public Size Size - { - get { return size; } - set - { - if (size == value) - return; - size = value; - contentSize = default(Size); - NotifyValueChanged("Size", size); - RegisterForLayouting(LayoutingType.Sizing); - } - } - protected override void onDraw(Context gr) - { + /// <summary> + /// View box + /// </summary> + /// <value>The size.</value> + [DefaultValue ("0,0")] + public Size Size { + get { return size; } + set { + if (size == value) + return; + size = value; + contentSize = default (Size); + NotifyValueChanged ("Size", size); + RegisterForLayouting (LayoutingType.Sizing); + } + } + protected override void onDraw (Context gr) + { + base.onDraw (gr); - if (string.IsNullOrEmpty(path)) - return; + if (string.IsNullOrEmpty (path)) + return; - gr.Save(); + gr.Save (); - Rectangle r = ClientRectangle; + Rectangle r = ClientRectangle; - double sx = (double)r.Width / (double)(contentSize.Width == 0? size.Width : contentSize.Width); - double sy = (double)r.Height / (double)(contentSize.Height == 0 ? size.Height : contentSize.Height); + double sx = (double)r.Width / (double)(contentSize.Width == 0 ? size.Width : contentSize.Width); + double sy = (double)r.Height / (double)(contentSize.Height == 0 ? size.Height : contentSize.Height); - gr.Translate(r.Left, r.Top); - gr.Scale (sx,sy); + gr.Translate (r.Left, r.Top); + gr.Scale (sx, sy); - using (PathParser parser = new PathParser (path)) - parser.Draw (gr); - - Background.SetAsSource (gr, r); - gr.FillPreserve (); gr.LineWidth = strokeWidth; Foreground.SetAsSource (gr, r); - gr.Stroke (); - gr.Restore(); + + using (PathParser parser = new PathParser (path)) + parser.Draw (gr); + + gr.Restore (); } protected override int measureRawSize (LayoutingType lt) { if ((lt == LayoutingType.Width && contentSize.Width == 0) || (lt == LayoutingType.Height && contentSize.Height == 0)) { - if (size != default(Size)) - contentSize = size; - else - { - using (Surface drawing = new ImageSurface(Format.A1, 1, 1)) - { - using (Context ctx = new Context(drawing)) - { - using (PathParser parser = new PathParser (path)) - parser.Draw (ctx); - Rectangle r = ctx.StrokeExtents(); - contentSize = new Size(r.Right, r.Bottom); - } - } - } + if (size != default (Size)) + contentSize = size; + else { + using (Context ctx = new Context (IFace.surf)) { + using (PathParser parser = new PathParser (path)) + parser.Draw (ctx, true); + Rectangle r = ctx.StrokeExtents (); + contentSize = new Size (r.Right, r.Bottom); + } + } } return lt == LayoutingType.Width ? - contentSize.Width + 2 * Margin: contentSize.Height + 2 * Margin; + contentSize.Width + 2 * Margin : contentSize.Height + 2 * Margin; } } } diff --git a/Directory.Build.props b/Directory.Build.props index 66bf8132..4ef561d4 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -7,8 +7,8 @@ <Authors>Jean-Philippe Bruyère</Authors> <LangVersion>7.2</LangVersion> - <CrowVersion>0.8.8</CrowVersion> + <CrowVersion>0.8.9</CrowVersion> <CrowPackageVersion>$(CrowVersion)-beta</CrowPackageVersion> - <CrowStbSharp>true</CrowStbSharp> + <CrowStbSharp>true</CrowStbSharp> </PropertyGroup> </Project> diff --git a/Samples/BasicTests/BasicTests.cs b/Samples/BasicTests/BasicTests.cs index 8d76b31e..90917302 100644 --- a/Samples/BasicTests/BasicTests.cs +++ b/Samples/BasicTests/BasicTests.cs @@ -32,8 +32,9 @@ namespace tests //testFiles = new string [] { @"Interfaces/Experimental/testDock.crow" }; //testFiles = new string [] { @"Interfaces/Divers/welcome.crow" }; //testFiles = new string [] { @"Interfaces/TemplatedGroup/3.crow" }; - //testFiles = new string [] { @"Interfaces/Divers/perfMeasures.crow" }; - testFiles = new string [] { @"Interfaces/Divers/colorPicker2.crow" }; + //testFiles = new string [] { @"Interfaces/Divers/testShape.crow" }; + testFiles = new string [] { @"Interfaces/TemplatedControl/testEnumSelector.crow" }; + //testFiles = new string [] { @"Interfaces/Divers/colorPicker2.crow" }; testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/GraphicObject", "*.crow")).ToArray (); testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Container", "*.crow")).ToArray (); testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Group", "*.crow")).ToArray (); @@ -126,6 +127,16 @@ namespace tests NotifyValueChanged ("IntValue", intValue); } } + VerticalAlignment currentVAlign; + public VerticalAlignment CurrentVAlign { + get => currentVAlign; + set { + if (currentVAlign == value) + return; + currentVAlign = value; + NotifyValueChanged ("CurrentVAlign", currentVAlign); + } + } void onSpinnerValueChange (object sender, ValueChangeEventArgs e) { if (e.MemberName != "Value") diff --git a/Samples/BasicTests/BasicTests.csproj b/Samples/BasicTests/BasicTests.csproj index 813b9b66..71a7a829 100644 --- a/Samples/BasicTests/BasicTests.csproj +++ b/Samples/BasicTests/BasicTests.csproj @@ -15,6 +15,9 @@ <ProjectReference Include="..\..\Crow\Crow.csproj" /> </ItemGroup> <ItemGroup> + <EmbeddedResource Remove="..\common\ui\templates\test.style" /> + </ItemGroup> + <ItemGroup> <Datas Include="..\data\**\*.*"> <Link>data\%(RecursiveDir)%(Filename)%(Extension)</Link> </Datas> @@ -29,5 +32,14 @@ <LogicalName>ui.%(Filename)%(Extension)</LogicalName> <Link>Templates\%(Filename)%(Extension)</Link> </EmbeddedResource> - </ItemGroup> + <EmbeddedResource Include="..\common\samples.style" /> + <EmbeddedResource Include="..\common\ui\images\**\*.*"> + <LogicalName>images.%(Filename)%(Extension)</LogicalName> + <Link>Images\%(Filename)%(Extension)</Link> + </EmbeddedResource> + <EmbeddedResource Include="..\common\ui\Icons\*.*"> + <LogicalName>Icons.%(Filename)%(Extension)</LogicalName> + <Link>Icons\%(Filename)%(Extension)</Link> + </EmbeddedResource> + </ItemGroup> </Project>
\ No newline at end of file diff --git a/Samples/ShowCase/main.cs b/Samples/ShowCase/main.cs index d780c511..ac103290 100644 --- a/Samples/ShowCase/main.cs +++ b/Samples/ShowCase/main.cs @@ -206,5 +206,11 @@ namespace tests } - + public static class Extensions + { + public static Fill GetIcon (this Alignment align) + { + return (Crow.Fill)Fill.Parse ("#images.valign.svg"); + } + } }
\ No newline at end of file diff --git a/Samples/common/samples.style b/Samples/common/samples.style new file mode 100644 index 00000000..ff956325 --- /dev/null +++ b/Samples/common/samples.style @@ -0,0 +1,67 @@ +FpsLabel { + Width = "30"; + Font = "droid, 10"; + Margin = "0"; + TextAlignment = "Center"; +} +FpsDisp { + Font = "droid bold, 10"; + Width = "60"; + Margin = "0"; + CornerRadius = "3"; + TextAlignment = "Center"; + Background = "MediumSeaGreen"; +} +HStackMeasure { + Margin = "2"; + Width = "Fit"; + Height = "Fit"; + Background = "DimGrey"; +} +CheckBox2 { + Template= "Interfaces/CheckBox2.imlt"; + Background = "Jet"; + Checked="{Background=MediumSeaGreen}"; + Unchecked = "{Background=Jet}"; +} +CheckBox3 { + Template= "Interfaces/CheckBox2.imlt"; + Background = "Jet"; + Width = "Stretched"; + Height = "Fit"; + CornerRadius = "5"; + Checked="{Background=MediumSeaGreen}"; + Unchecked = "{Background=Jet}"; +} +labPerf { + Font = "droid, 8"; + Width = "50%"; +} +labPerfVal{ + Font = "droid, 8"; + Width = "50%"; +} +DbgLogViewer{ + Background = "Onyx"; + Font = "mono, 8"; + Foreground = "LightGrey"; + Focusable = "true"; +} +DockWindow{ + Background = "0.1,0.1,0.1,0.5"; +} + +valignStyle { + Template="#ui.enumSingleSVG.itmp"; + Checked="{Background=MediumSeaGreen}"; + Unchecked = "{Background=Black}"; + //Initialized="GetDrawModeIcon"; + //Initialized="{Background=Blue}"; +} +valignStyle2 { + Template="#ui.enumGetIcons.itmp"; + Checked="{Background=MediumSeaGreen}"; + Unchecked = "{Background=Black}"; + //Initialized="GetDrawModeIcon"; + //Initialized="{Background=Blue}"; +}
\ No newline at end of file diff --git a/Samples/common/ui/Icons/Bottom.svg b/Samples/common/ui/Icons/Bottom.svg new file mode 100644 index 00000000..38e5fa62 --- /dev/null +++ b/Samples/common/ui/Icons/Bottom.svg @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Generated by IcoMoon.io --> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"> +<rect fill="#00000000" stroke="#444444" stroke-width="1" x="0.5" y="0.5" width="15" height="15"/> +<line id="Bottom" fill="#00000000" stroke="#444444" stroke-width="4" x1="1.5" y1="12.5" x2="14.5" y2="12.5" /> +</svg> diff --git a/Samples/common/ui/Icons/Center.svg b/Samples/common/ui/Icons/Center.svg new file mode 100644 index 00000000..ac2efdb8 --- /dev/null +++ b/Samples/common/ui/Icons/Center.svg @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Generated by IcoMoon.io --> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"> +<rect fill="#00000000" stroke="#444444" stroke-width="1" x="0.5" y="0.5" width="15" height="15"/> +<line id="Center" fill="#00000000" stroke="#444444" stroke-width="4" x1="1.5" y1="8" x2="14.5" y2="8" /> +</svg> diff --git a/Samples/common/ui/Icons/Top.svg b/Samples/common/ui/Icons/Top.svg new file mode 100644 index 00000000..01d11d52 --- /dev/null +++ b/Samples/common/ui/Icons/Top.svg @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Generated by IcoMoon.io --> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"> +<rect fill="#00000000" stroke="#444444" stroke-width="1" x="0.5" y="0.5" width="15" height="15"/> +<line id="Top" fill="#00000000" stroke="#444444" stroke-width="4" x1="1.5" y1="3.5" x2="14.5" y2="3.5" /> +</svg> diff --git a/Samples/common/ui/Interfaces/Divers/0.crow b/Samples/common/ui/Interfaces/Divers/0.crow index 8850e26d..c98d6410 100644 --- a/Samples/common/ui/Interfaces/Divers/0.crow +++ b/Samples/common/ui/Interfaces/Divers/0.crow @@ -64,10 +64,10 @@ </VerticalStack> <Splitter /> <VerticalStack Width="50%"> - <RadioButton Style="RadioButton2" /> - <RadioButton Style="RadioButton2" /> - <RadioButton Style="RadioButton2" /> - <RadioButton Style="RadioButton2" /> + <RadioButton Style="CheckBox2" /> + <RadioButton Style="CheckBox2" /> + <RadioButton Style="CheckBox2" /> + <RadioButton Style="CheckBox2" /> </VerticalStack> </HorizontalStack> </GroupBox> diff --git a/Samples/common/ui/Interfaces/Divers/testShape.crow b/Samples/common/ui/Interfaces/Divers/testShape.crow index 99b89b07..14af0f21 100644 --- a/Samples/common/ui/Interfaces/Divers/testShape.crow +++ b/Samples/common/ui/Interfaces/Divers/testShape.crow @@ -1,6 +1,5 @@ <?xml version="1.0"?> -<Container Fit="true" Background="Red" Tooltip="test tooltip" > - <Shape Foreground="Transparent" Background="DimGrey" Size="11,11" Path="M 5.5,0.5 L 10.5,10.5 L 0.5,10.5 Z" - MouseEnter="{Background=hgradient|0:DimGrey|0.5:RoyalBlue|1:Black}" - MouseLeave="{Background=DimGrey}"/> -</Container>
\ No newline at end of file +<VerticalStack> + <TextBox Text="{²../shape.Path}"/> + <Shape Margin="0" Width="400" Height="400" Name="shape" Foreground="Blue" Background="DimGrey" Size="100,100" Path="M 5.5,0.5 L 10.5,10.5 L 0.5,10.5 Z G"/> +</VerticalStack>
\ No newline at end of file diff --git a/Samples/common/ui/Interfaces/GraphicObject/5.crow b/Samples/common/ui/Interfaces/GraphicObject/5.crow index 0e0560fc..8fdf887d 100644 --- a/Samples/common/ui/Interfaces/GraphicObject/5.crow +++ b/Samples/common/ui/Interfaces/GraphicObject/5.crow @@ -1,5 +1,5 @@ <?xml version="1.0"?> -<HorizontalStack Width="Stretched" Height="Fit" Margin="5" Background="Mantis"> +<HorizontalStack Width="Stretched" Height="Fit" Margin="5" Background="RoyalBlue"> <Widget Background="Carmine" Width="10%" Height="20"/> <Widget Background="Carmine" Width="Stretched" Height="20"/> <Widget Background="Carmine" Width="10%" Height="20"/> diff --git a/Samples/common/ui/Interfaces/TemplatedControl/testEnumSelector.crow b/Samples/common/ui/Interfaces/TemplatedControl/testEnumSelector.crow new file mode 100644 index 00000000..303f5432 --- /dev/null +++ b/Samples/common/ui/Interfaces/TemplatedControl/testEnumSelector.crow @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<VerticalStack Spacing="5" Margin="5"> + <Image Path="#images.valign.svg" Fit="True" Background="White" Margin="5" SvgSub="{²CurrentVAlign}"/> + <Border Height="100" Width="Fit" Background="Jet"> + <Label Margin="5" Text="vertical aligned text" VerticalAlignment="{CurrentVAlign}" Background="DarkBlue"/> + </Border> + <EnumSelector Name="valign" Caption="Vertical Alignment" EnumValue="{²CurrentVAlign}" /> + <EnumSelector RadioButtonStyle="CheckBox3" Name="valign" Caption="Vertical Alignment" EnumValue="{²CurrentVAlign}" > + <Template> + <VerticalStack Name="Content" Width="100"/> + </Template> + </EnumSelector> + <EnumSelector RadioButtonStyle="CheckBox2" Name="valign" Caption="Vertical Alignment" EnumValue="{²CurrentVAlign}" /> + <EnumSelector RadioButtonStyle="valignStyle" Name="valign1" Caption="Vertical Alignment" EnumValue="{²CurrentVAlign}" /> + <EnumSelector RadioButtonStyle="valignStyle2" Name="valign2" Caption="Vertical Alignment" EnumValue="{²CurrentVAlign}" /> +</VerticalStack>
\ No newline at end of file diff --git a/Samples/common/ui/images/valign.svg b/Samples/common/ui/images/valign.svg new file mode 100644 index 00000000..b24cf26b --- /dev/null +++ b/Samples/common/ui/images/valign.svg @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Generated by IcoMoon.io --> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"> +<rect fill="#00000000" stroke="#444444" stroke-width="1" x="0.5" y="0.5" width="15" height="15"/> +<line id="Top" fill="#00000000" stroke="#444444" stroke-width="4" x1="1.5" y1="3.5" x2="14.5" y2="3.5" /> +<line id="Center" fill="#00000000" stroke="#444444" stroke-width="4" x1="1.5" y1="8" x2="14.5" y2="8" /> +<line id="Bottom" fill="#00000000" stroke="#444444" stroke-width="4" x1="1.5" y1="12.5" x2="14.5" y2="12.5" /> +</svg> diff --git a/Samples/common/ui/templates/CheckBox2.imlt b/Samples/common/ui/templates/CheckBox2.imlt index c2bfe8da..048d495b 100644 --- a/Samples/common/ui/templates/CheckBox2.imlt +++ b/Samples/common/ui/templates/CheckBox2.imlt @@ -1,4 +1,4 @@ -<Label Font="{./Font}" Text="{./Caption}" Height="{./HeightPolicy}" Width="{./WidthPolicy}" +<Label Font="{./Font}" Text="{./Caption}" CornerRadius="{./CornerRadius}" Margin="3" Background="{./Background}" Foreground="DimGrey" diff --git a/Samples/common/ui/templates/enumGetIcons.itmp b/Samples/common/ui/templates/enumGetIcons.itmp index 048d495b..63f6fdbd 100644 --- a/Samples/common/ui/templates/enumGetIcons.itmp +++ b/Samples/common/ui/templates/enumGetIcons.itmp @@ -1,7 +1,4 @@ -<Label Font="{./Font}" Text="{./Caption}" CornerRadius="{./CornerRadius}" - Margin="3" - Background="{./Background}" - Foreground="DimGrey" - TextAlignment="Center" - MouseEnter="{Foreground=White}" - MouseLeave="{Foreground=DimGrey}"/>
\ No newline at end of file +<Border Foreground="Grey" MouseEnter="{Foreground=White}" MouseLeave="{Foreground=Grey}"> + <Image Path="{./Tag}" Fit="True" Margin="1" CornerRadius="{./CornerRadius}" + Background="{./Background}"/> +</Border>
\ No newline at end of file diff --git a/Samples/common/ui/templates/enumSingleSVG.itmp b/Samples/common/ui/templates/enumSingleSVG.itmp new file mode 100644 index 00000000..83bcfa33 --- /dev/null +++ b/Samples/common/ui/templates/enumSingleSVG.itmp @@ -0,0 +1,4 @@ +<Border Foreground="Grey" MouseEnter="{Foreground=White}" MouseLeave="{Foreground=Grey}"> + <Image Path="#images.valign.svg" Fit="True" Margin="1" SvgSub="{./Caption}" CornerRadius="{./CornerRadius}" + Background="{./Background}"/> +</Border>
\ No newline at end of file diff --git a/Samples/common/ui/templates/test.style b/Samples/common/ui/templates/test.style index 6f5dc8fb..5f282702 100644 --- a/Samples/common/ui/templates/test.style +++ b/Samples/common/ui/templates/test.style @@ -1,49 +1 @@ -FpsLabel { - Width = "30"; - Font = "droid, 10"; - Margin = "0"; - TextAlignment = "Center"; -} -FpsDisp { - Font = "droid bold, 10"; - Width = "60"; - Margin = "0"; - CornerRadius = "3"; - TextAlignment = "Center"; - Background = "MediumSeaGreen"; -} -HStackMeasure { - Margin = "2"; - Width = "Fit"; - Height = "Fit"; - Background = "DimGrey"; -} -CheckBox2 { - Template= "Interfaces/CheckBox2.imlt"; - Background = "Jet"; - Checked="{Background=MediumSeaGreen}"; - Unchecked = "{Background=Jet}"; -} -RadioButton2 { - Template="Interfaces/CheckBox2.imlt"; - Background = "Jet"; - Checked = "{Background=MediumSeaGreen}"; - Unchecked = "{Background=Jet}"; -} -labPerf { - Font = "droid, 8"; - Width = "50%"; -} -labPerfVal{ - Font = "droid, 8"; - Width = "50%"; -} -DbgLogViewer{ - Background = "Onyx"; - Font = "mono, 8"; - Foreground = "LightGrey"; - Focusable = "true"; -} -DockWindow{ - Background = "0.1,0.1,0.1,0.5"; -} +
\ No newline at end of file |