From: Jean-Philippe Bruyère Date: Thu, 4 Jun 2020 21:16:35 +0000 (+0200) Subject: search default template with Interface.GetStreamFromPath, add LoadStyle public method... X-Git-Tag: v0.9.5-beta~113^2~13 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=d88c47659d248dbf5b4ec2b071906fafe013011e;p=jp%2Fcrow.git search default template with Interface.GetStreamFromPath, add LoadStyle public method in iface --- diff --git a/Crow/src/IML/Instantiator.cs b/Crow/src/IML/Instantiator.cs index 9668a8c2..c1a11f03 100644 --- a/Crow/src/IML/Instantiator.cs +++ b/Crow/src/IML/Instantiator.cs @@ -298,6 +298,7 @@ namespace Crow.IML { bool inlineTemplate = false; reader.Read (); + string templatePath = reader.GetAttribute ("Template"); string itemTemplatePath = reader.GetAttribute ("ItemTemplate"); diff --git a/Crow/src/Interface.cs b/Crow/src/Interface.cs index 9757e76e..77360f3e 100644 --- a/Crow/src/Interface.cs +++ b/Crow/src/Interface.cs @@ -152,7 +152,6 @@ namespace Crow Glfw3.SetCharCallback (hWin, HandleCharDelegate); Glfw3.SetWindowSizeCallback (hWin, HandleWindowSizeDelegate); - //Glfw3.SetWindowTitle (hWin, "FPS: " + fps.ToString ()); switch (Environment.OSVersion.Platform) { case PlatformID.MacOSX: break; @@ -208,6 +207,9 @@ namespace Crow #endregion + public string WindowTitle { + set => Glfw3.SetWindowTitle (hWin, value); + } public bool Running { get => !Glfw3.WindowShouldClose (hWin); @@ -482,9 +484,18 @@ namespace Crow .GetManifestResourceNames () .Where (r => r.EndsWith (".style", StringComparison.OrdinalIgnoreCase))) { using (StyleReader sr = new StyleReader (assembly.GetManifestResourceStream (s))) - sr.Parse (this.StylingConstants, this.Styling, s); + sr.Parse (StylingConstants, Styling, s); } } + public void LoadStyle (string stylePath) { + using (Stream s = new FileStream (stylePath, FileMode.Open)) + LoadStyle (s, stylePath); + + } + public void LoadStyle (Stream stream, string resId) { + using (StyleReader sr = new StyleReader (stream)) + sr.Parse (StylingConstants, Styling, resId); + } #endregion diff --git a/Crow/src/Widgets/TemplatedControl.cs b/Crow/src/Widgets/TemplatedControl.cs index 614bc1ac..ae2967d0 100644 --- a/Crow/src/Widgets/TemplatedControl.cs +++ b/Crow/src/Widgets/TemplatedControl.cs @@ -118,9 +118,7 @@ namespace Crow if (!IFace.DefaultTemplates.ContainsKey (mdTok)) { string defTmpId = this.GetType ().FullName + ".template"; - Stream s = Assembly.GetEntryAssembly ()?.GetManifestResourceStream (defTmpId); - if (s == null) - s = Assembly.GetAssembly (this.GetType ()).GetManifestResourceStream (defTmpId); + Stream s = Interface.GetStreamFromPath ("#" + defTmpId); if (s == null) throw new Exception (string.Format ("No default template found for '{0}'", this.GetType ().FullName)); IFace.DefaultTemplates [mdTok] = new IML.Instantiator (IFace, s, defTmpId); diff --git a/Crow/src/Widgets/Widget.cs b/Crow/src/Widgets/Widget.cs index de079e15..96f4ce7b 100644 --- a/Crow/src/Widgets/Widget.cs +++ b/Crow/src/Widgets/Widget.cs @@ -1708,8 +1708,8 @@ namespace Crow else if (LastPaintedSlot.Width != Slot.Width || LastPaintedSlot.Height != Slot.Height) bmp.SetSize (Slot.Width, Slot.Height);*/ bmp?.Dispose (); - //bmp = IFace.surf.CreateSimilar (Content.ColorAlpha, Slot.Width, Slot.Height); - bmp = new ImageSurface(Format.Argb32, Slot.Width, Slot.Height); + bmp = IFace.surf.CreateSimilar (Content.ColorAlpha, Slot.Width, Slot.Height); + //bmp = new ImageSurface(Format.Argb32, Slot.Width, Slot.Height); using (Context gr = new Context (bmp)) { gr.Antialias = Interface.Antialias; diff --git a/Crow/src/styling/StyleReader.cs b/Crow/src/styling/StyleReader.cs index 96b79b9e..84839890 100644 --- a/Crow/src/styling/StyleReader.cs +++ b/Crow/src/styling/StyleReader.cs @@ -66,7 +66,7 @@ namespace Crow line = 1; curState = States.classNames; - string styleKey = resId.Substring (0, resId.Length - 6); + //string styleKey = resId.Substring (0, resId.Length - 6); string token = ""; List targetsClasses = new List (); string currentProperty = ""; diff --git a/Samples/BasicTests/BasicTests.cs b/Samples/BasicTests/BasicTests.cs index e32b6080..13c0758c 100644 --- a/Samples/BasicTests/BasicTests.cs +++ b/Samples/BasicTests/BasicTests.cs @@ -37,7 +37,8 @@ namespace tests //testFiles = new string [] { @"Interfaces/TemplatedGroup/3.crow" }; //testFiles = new string [] { @"Interfaces/Divers/testShape.crow" }; //testFiles = new string [] { @"Interfaces/TemplatedControl/testEnumSelector.crow" }; - testFiles = new string [] { @"Interfaces/Divers/all.crow" }; + //testFiles = new string [] { @"Interfaces/Divers/all.crow" }; + testFiles = new string [] { @"Interfaces/Divers/templateInStyle.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 (); diff --git a/Samples/common/ui/Interfaces/Divers/templateInStyle.crow b/Samples/common/ui/Interfaces/Divers/templateInStyle.crow new file mode 100644 index 00000000..159aa10d --- /dev/null +++ b/Samples/common/ui/Interfaces/Divers/templateInStyle.crow @@ -0,0 +1,2 @@ + + \ No newline at end of file