]> O.S.I.I.S - jp/crow.git/commitdiff
debug ObservableList, new Table widget
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 15 Apr 2021 13:18:19 +0000 (15:18 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 15 Apr 2021 13:18:19 +0000 (15:18 +0200)
12 files changed:
Crow/Default.style
Crow/src/DebugUtils/DebugLogger.cs
Crow/src/ObservableList.cs
Crow/src/Widgets/Group.cs
Crow/src/Widgets/GroupBase.cs
Crow/src/Widgets/Table.cs
Crow/src/Widgets/Widget.cs
Samples/DebugLogAnalyzer/src/DebugInterfaceWidget.cs
Samples/DebugLogAnalyzer/src/Program.cs
Samples/DebugLogAnalyzer/ui/main.crow
Samples/common/ui/Interfaces/Experimental/colorTable.crow [new file with mode: 0644]
Samples/common/ui/Interfaces/Experimental/table2.crow

index f482eb0b85ab4a89c9c4992f275922cc8e89232c..6440636216ca1a940533471f8006a74dcbdc3270 100644 (file)
@@ -293,6 +293,10 @@ ColorPicker {
        Height="Fit";
        MinimumSize="200,100";  
 }
+Table {
+       Spacing="1";
+       Foreground="Grey";      
+}
 TableRow {
        Width="Stretched";
 }
index 3a65ad556fcb28bf8e3f167c701a45eae4ea6db7..058921aafe44e595fd04f8802a190cf72d587244 100644 (file)
@@ -225,8 +225,8 @@ namespace Crow
                /// <param name="iface">Iface.</param>
                public static void Save(Interface iface, string dbgLogFilePath = "debug.log") {
 #if DEBUG_LOG
-                               using (Stream stream = new FileStream (dbgLogFilePath, FileMode.Create, FileAccess.Write))
-                                       Save (iface, stream);
+                       using (Stream stream = new FileStream (dbgLogFilePath, FileMode.Create, FileAccess.Write))
+                               Save (iface, stream);
                        Console.WriteLine ($"Crow Debug Log saved to: {System.IO.Path.GetFullPath(dbgLogFilePath)}");
 #endif
                }
@@ -254,11 +254,9 @@ namespace Crow
                                                if (startingWidgetsIndex >= 0)                          
                                                        writer.WriteLine ("[Events]");
                                                saveEventList (writer, events);
+                                               startedEvents.Clear ();
+                                               events.Clear ();
                                        }
-                                       if (startedEvents.Count > 0)
-                                               Console.WriteLine ($"[DebugLogger]Warning: Started events not null when events saved!");
-                                       startedEvents.Clear ();
-                                       events.Clear ();
                                        chrono.Start();
                                }
                        }
index 8cb648064aecdc0c6fc52a820fd7519ff51eac71..b67e27b6ed55358644be8d82efc3e5b38fd2bf25 100644 (file)
@@ -56,6 +56,11 @@ namespace Crow
                        ListAdd.Raise (this, new ListChangedEventArg (this.Count - 1, elem));
                        SelectedIndex = this.Count - 1;
                }
+               public new void Insert (int index, T elem) {
+                       base.Insert (index, elem);
+                       ListAdd.Raise (this, new ListChangedEventArg (index, elem));
+                       SelectedIndex = index;
+               }
                public new void Remove (T elem) {
                        int idx = IndexOf (elem);
                        if (idx < 0)
index 4ce70c4af57c8298ccb69849fb3f65440572d302..55cc635353d1ce4867e692c33e6410fce904561f 100644 (file)
@@ -184,7 +184,7 @@ namespace Crow
                {
                        DbgLogger.StartEvent (DbgEvtType.GOSearchLargestChild, this);
 
-                       //childrenRWLock.EnterReadLock ();
+                       childrenRWLock.EnterReadLock ();
 
                        largestChild = null;
                        contentSize.Width = 0;
@@ -206,7 +206,7 @@ namespace Crow
                        if (largestChild == null && !forceMeasure)
                                searchLargestChild (true);
 
-                       //childrenRWLock.ExitReadLock ();
+                       childrenRWLock.ExitReadLock ();
 
                        DbgLogger.EndEvent (DbgEvtType.GOSearchLargestChild);
                }
@@ -214,7 +214,7 @@ namespace Crow
                {
                        DbgLogger.StartEvent (DbgEvtType.GOSearchTallestChild, this);
 
-                       //childrenRWLock.EnterReadLock ();
+                       childrenRWLock.EnterReadLock ();
 
                        tallestChild = null;
                        contentSize.Height = 0;
@@ -236,7 +236,7 @@ namespace Crow
                        if (tallestChild == null && !forceMeasure)
                                searchTallestChild (true);
 
-                       //childrenRWLock.ExitReadLock ();
+                       childrenRWLock.ExitReadLock ();
 
                        DbgLogger.EndEvent (DbgEvtType.GOSearchTallestChild);
                }
index 0ef24bda247c221bfd81d66bcbb42eb641b35b5a..33f26001e0702f291e7cb30c2ce63bf21d0f7677 100644 (file)
@@ -118,13 +118,17 @@ namespace Crow
                public override void OnDataSourceChanged (object sender, DataSourceChangeEventArgs e)
                {
                        base.OnDataSourceChanged (this, e);
-
-                       childrenRWLock.EnterReadLock ();
-                       foreach (Widget g in Children) {
-                               if (g.localDataSourceIsNull & g.localLogicalParentIsNull)
-                                       g.OnDataSourceChanged (g, e);   
+                       try {
+                               childrenRWLock.EnterReadLock ();
+                               foreach (Widget g in Children) {
+                                       if (g.localDataSourceIsNull & g.localLogicalParentIsNull)
+                                               g.OnDataSourceChanged (g, e);   
+                               }
+                               childrenRWLock.ExitReadLock ();
+                       } catch (Exception) {
+                               childrenRWLock.ExitReadLock ();
+                               throw;
                        }
-                       childrenRWLock.ExitReadLock ();
                }
 
                public void putWidgetOnTop(Widget w)
@@ -213,12 +217,20 @@ namespace Crow
                                gr.Clip ();
                        }
 
-                       childrenRWLock.EnterReadLock ();
+                       try
+                       {
+                               childrenRWLock.EnterReadLock ();
 
-                       for (int i = 0; i < Children.Count; i++) 
-                               Children[i].Paint (gr);                 
+                               for (int i = 0; i < Children.Count; i++) 
+                                       Children[i].Paint (gr);                 
 
-                       childrenRWLock.ExitReadLock ();
+                               childrenRWLock.ExitReadLock ();
+                       }
+                       catch (System.Exception)
+                       {
+                               childrenRWLock.ExitReadLock ();
+                               throw;
+                       }
 
                        if (ClipToClientRect)
                                gr.Restore ();
index 5ddd1af8f34cb0888627e5da3bd5c7f62c7f3fb5..27cfb9636a9e5030bb6914a4de3116d10b9abcb3 100644 (file)
@@ -88,9 +88,18 @@ namespace Crow
                public override void InsertChild (int idx, Widget g) {
                        g.Width = Measure.Stretched;
                        g.Margin = RowsMargin;
-                       base.InsertChild (idx, g);                      
+                       base.InsertChild (idx, g);
+                       if (HeaderRow == null || idx == 0)
+                               return;
+                       TableRow row = g as TableRow;
+                       for (int i = 0; i < HeaderRow.Children.Count; i++) {
+                               if (row.Children.Count <= i)
+                                       continue;
+                               setRowCellWidth (row.Children[i], HeaderRow.Children[i].Slot.Width);                            
+                               row.Children[i].Slot.X = HeaderRow.Children[i].Slot.X;
+                       }
                }
-               [DefaultValue (2)]
+               [DefaultValue (1)]
                public int ColumnSpacing {
                        get => columnSpacing;
                        set {
@@ -228,7 +237,6 @@ namespace Crow
                                        if (row.Children.Count <= cIdx)
                                                continue;
                                        row.Children[cIdx].Slot.X = g.Slot.X;
-                                       row.RegisterForRedraw();
                                }
                                childrenRWLock.ExitReadLock ();
                                RegisterForRedraw ();
@@ -236,8 +244,7 @@ namespace Crow
                }
                protected void setRowCellWidth (Widget w, int newW) {
                        if (newW == w.Slot.Width)
-                               return;
-                       
+                               return;                 
                        w.Slot.Width = newW;
                        w.IsDirty = true;
                        w.OnLayoutChanges (LayoutingType.Width);
index 9f3f47810dec000547c9c87b52901e67f7d8bfdd..c38f373bd0c2fa258d71471cd5fd410a6e998f67 100644 (file)
@@ -158,9 +158,9 @@ namespace Crow
                                if (!localDataSourceIsNull)
                                        DataSource = null;
 
-                               parentRWLock.EnterWriteLock ();
+                               //parentRWLock.EnterWriteLock ();
                                parent = null;
-                               parentRWLock.ExitWriteLock ();
+                               //parentRWLock.ExitWriteLock ();
                        } else {
                                DbgLogger.AddEvent (DbgEvtType.DisposedByGC, this);
                        }
index c6920ca585f7d2b91c115056e1b4732ce8f2a0c1..2dba0601ef97f34d61178e812a5b9e60fdcb6885 100644 (file)
@@ -47,7 +47,9 @@ namespace Crow
                public CommandGroup LoggerCommands =>
                        new CommandGroup(
                                new Command("Get logs", () => getLog ()),
-                               new Command("Reset logs", () => delResetDebugger ())
+                               new Command("Reset logs", () => delResetDebugger ()),
+                               new Command("Save to file", () => saveLogToDebugLogFilePath ()),
+                               new Command("Load from file", () => loadLogFromDebugLogFilePath ())
                        );
                public string IMLSource {
                        get => imlSource;
@@ -128,7 +130,42 @@ namespace Crow
                                NotifyValueChangedAuto (DebugLogToFile);
                        }
                }
+               public string DebugLogFilePath {
+                       get => Configuration.Global.Get<string> ("DebugLogFilePath");
+                       set {
+                               if (DebugLogFilePath == value)
+                                       return;
+                               Configuration.Global.Set ("DebugLogFilePath", value);
+                               NotifyValueChangedAuto (value);
+                       }
+               }
+               int firstWidgetIndexToSave, lastWidgetIndexToSave;
+               public int FirstWidgetIndexToSave {
+                       get => firstWidgetIndexToSave;
+                       set {
+                               if (firstWidgetIndexToSave == value)
+                                       return;
+                               if (value > lastWidgetIndexToSave)
+                                       firstWidgetIndexToSave = lastWidgetIndexToSave;
+                               else
+                                       firstWidgetIndexToSave = value;
 
+                               NotifyValueChangedAuto (firstWidgetIndexToSave);
+                       }
+               }
+               public int LastWidgetIndexToSave {
+                       get => lastWidgetIndexToSave;
+                       set {
+                               if (lastWidgetIndexToSave == value)
+                                       return;
+                               if (lastWidgetIndexToSave > widgets.Count)
+                                       lastWidgetIndexToSave = widgets.Count;
+                               else
+                                       lastWidgetIndexToSave = value;
+
+                               NotifyValueChangedAuto (lastWidgetIndexToSave);
+                       }
+               }
 
                protected override void onInitialized(object sender, EventArgs e)
                {
@@ -373,8 +410,6 @@ namespace Crow
                                widgets = new List<DbgWidgetRecord>();
                                events = new List<DbgEvent>();
                                miSave.Invoke(null, new object[] {dbgIFace, stream, firstWidgetIndexToGet, true});
-                               //debuggerType.GetMethod("Save", new Type[] {dbgIfaceType, typeof(string)}).Invoke(null, new object[] {dbgIFace, "debug.log"});
-                               //delSaveDebugLog(dbgIFace, "debug.log");
                                stream.Seek(0, SeekOrigin.Begin);
                                DbgLogger.Load (stream, events, widgets);
 
@@ -401,6 +436,12 @@ namespace Crow
                        foreach (DbgEvent e in evt.Events) 
                                updateWidgetEvents (widgets, e);                        
                }
+               void saveLogToDebugLogFilePath () {
+
+               }
+               void loadLogFromDebugLogFilePath () {
+
+               }
 
                public virtual object GetScreenCoordinates () => ScreenCoordinates(Slot).TopLeft;
        }
index a2711dda7fc75a826321c8d527cbbde0f2c1fafe..9c2e71174e92794a82436cf0223cec0c0f29d2ad 100644 (file)
@@ -125,10 +125,6 @@ namespace DebugLogAnalyzer
 
                }
 
-
-               
-
-                       
                public string CrowDbgAssemblyLocation {
                        get => Configuration.Global.Get<string>("CrowDbgAssemblyLocation");
                        set {
@@ -156,35 +152,6 @@ namespace DebugLogAnalyzer
                                NotifyValueChanged (nameof (Widgets), widgets);
                        }
                }
-               /*IEnumerable<DbgWidgetEvent> widgetEvents (DbgWidgetRecord wr, DbgEvent evt) {
-                       if (evt is DbgWidgetEvent we && we.InstanceIndex == wr.InstanceIndex)
-                               yield return we;
-                       if (evt.Events != null) {
-                               foreach (DbgEvent e in evt.Events)
-                                       foreach (DbgWidgetEvent ye in widgetEvents (wr, e))                             
-                                               yield return ye;
-                       }
-               }
-               IEnumerable<DbgWidgetEvent> currentWidgetEvents;
-
-               public IEnumerable<DbgWidgetEvent> CurrentWidgetEvents {
-                       get => currentWidgetEvents;
-                       set {
-                               currentWidgetEvents = value;
-                               NotifyValueChanged (currentWidgetEvents);
-                               curWidget.Events = new List<DbgEvent> (currentWidgetEvents);
-                       }
-               }
-               IEnumerable<DbgWidgetEvent> getCurrentWidgetEvents () {
-                       if (CurrentWidget == null)
-                               yield return null;
-                       else {
-                               foreach (DbgEvent evt in Events)
-                                       foreach (DbgWidgetEvent dwe in widgetEvents (CurrentWidget, evt))
-                                               yield return dwe;
-                       }
-               }*/
-
                 
                public DbgEvent CurrentEvent {
                        get => curEvent;
@@ -277,7 +244,7 @@ namespace DebugLogAnalyzer
                                NotifyValueChanged(DebugLogToFile);
                        }
                }
-               public string DebugLogFilePath {
+               /*public string DebugLogFilePath {
                        get => Configuration.Global.Get<string> (nameof (DebugLogFilePath));
                        set {
                                if (CurrentFile == value)
@@ -285,7 +252,7 @@ namespace DebugLogAnalyzer
                                Configuration.Global.Set (nameof (DebugLogFilePath), value);
                                NotifyValueChanged (DebugLogFilePath);
                        }
-               }
+               }*/
                public bool DebugLogRecording {
                        get => debugLogRecording;
                        set {
index 22d0920de11a5da9344045474408e628379425d5..16973e119fbb1a7e20a94bb3cbc777b3a4905660 100644 (file)
@@ -1,8 +1,8 @@
 <?xml version="1.0"?>
 <VerticalStack Background="DarkGrey">
        <HorizontalStack >
-               <HorizontalStack Width="25%" >
-                       <VerticalStack Width="50%" Name="Explorer" Background="Onyx">
+               <TabView Width="25%" >
+                       <VerticalStack Name="Explorer" Background="Onyx">
                                <HorizontalStack Height="Fit" Margin="2" >
                                        <Image Margin="2" Width="16" Height="16" Path="#Crow.Icons.level-up.svg" MouseClick="goUpDirClick"
                                                                 Background="Jet" MouseEnter="{Background=Grey}" MouseLeave="{Background=Jet}" />                       
@@ -60,8 +60,7 @@
                                        </Template>             
                                </DirectoryView>
                        </VerticalStack>
-                       <Splitter/>
-                       <VerticalStack Name="DebugLogger" Margin="5" IsVisible="true" Background="Onyx">
+                       <VerticalStack Name="DebugLogger" Margin="5" IsVisible="false" Background="Onyx">
                                <HorizontalStack Height="Fit">
                                        <Image Width="30" Height="20" Path="#Crow.Icons.IconAlerte.svg" Visible="{../../../../dbgIfaceWidget.CrowDebuggerNOK}"/>
                                        <Label Fit="true" Text="Crow debug assembly path:"/>
                                </HorizontalStack>
                                <Label Background="Red" Foreground="White" Margin="5" Width="Stretched" Text="{../../../dbgIfaceWidget.CrowDebuggerErrorMessage}"
                                        IsVisible="{../../../dbgIfaceWidget.CrowDebuggerNOK}"/>
-                               <CheckBox Name="cbFile" Caption="Record to file" IsChecked="{²DebugLogToFile}" Background="Onyx"/>
+                               <!--<CheckBox Name="cbFile" Caption="Record to file" IsChecked="{²DebugLogToFile}" Background="Onyx"/>-->
                                <HorizontalStack Height="Fit" Width="Stretched" IsEnabled="{../cbFile.IsChecked}" Background="Onyx" Margin="5">
                                        <Label Text="Debug log output file:" Fit="true"/>
-                                       <TextBox Text="{²DebugLogFilePath}"  />
+                                       <TextBox Text="{²../../../../dbgIfaceWidget.DebugLogFilePath}"  />
                                </HorizontalStack>
                                <EnumSelector RadioButtonStyle="CheckBox2" Template="#Dbg.EnumSelector.template"
                                                Background="Grey"
                                        </Menu>                                 
                                </HorizontalStack>                                      
                        </VerticalStack>                        
-               </HorizontalStack>
+               </TabView>
                <Splitter Width="6" />
                <VerticalStack>
                        <DebugInterfaceWidget Name="dbgIfaceWidget" Height="60%" Background="Black" Focusable="true"
diff --git a/Samples/common/ui/Interfaces/Experimental/colorTable.crow b/Samples/common/ui/Interfaces/Experimental/colorTable.crow
new file mode 100644 (file)
index 0000000..6da2b04
--- /dev/null
@@ -0,0 +1,12 @@
+<ListBox Data="{TestList}" >
+       <Template>
+               <Table Name="ItemsContainer" Columns="name,Stretched;color,100"/> 
+       </Template>
+       <ItemTemplate>
+               <TableRow>
+                       <Label Text="{}" Margin="5" />
+                       <Widget Background="{}" Width="50" Height="10"/>
+               </TableRow>
+       </ItemTemplate>
+
+</ListBox>
\ No newline at end of file
index 5416897c6de2468007e712a6956b310ca5916d91..4aa3eebb3a66edef92d93d252de69e8aa2f4429d 100644 (file)
@@ -1,18 +1,20 @@
-<Table Foreground="White" Columns="test,Fit;test,Fit" Background="White" Width="Fit" Height="Fit" Margin="1" Spacing="1" > 
-       <TableRow Height="Fit"  Spacing="1" Margin="0"
-                       MouseEnter="{Background=RoyalBlue}"
-                       MouseLeave="{Background=Transparent}">
-               <Label Text="col1qsf" Margin="5" Background="0.3,0.3,0.3,0.8"/>
-               <Label Text="col1qsf" Margin="5" Background="0.3,0.3,0.3,0.8"/>
-               <Label Text="col1qsf" Margin="5" Background="0.3,0.3,0.3,0.8"/>
-       </TableRow>
-       <TableRow Height="Fit" Spacing="0" Margin="0"
-                       MouseEnter="{Background=RoyalBlue}"
-                       MouseLeave="{Background=Transparent}">
-               <Label Text="col1qsf" Margin="5" Background="0.3,0.3,0.3,0.8"/>
-               <Label Text="col1qsf" Margin="5" Background="0.3,0.3,0.3,0.8"/>
-               <Label Text="col1qsf" Margin="5" Background="0.3,0.3,0.3,0.8"/>
-       </TableRow>
-       
-
-</Table>
\ No newline at end of file
+<List Data="{TestList}">
+       <Table Foreground="White" Columns="test,Fit;test,Fit" Width="Fit" Height="Fit"
+               Spacing="1" ColumnSpacing="1"
+               VerticalLineWidth="1" Margin="0" RowsMargin="0"> 
+               <TableRow
+                               MouseEnter="{Background=RoyalBlue}"
+                               MouseLeave="{Background=Transparent}">
+                       <Label Text="col1qsf" Margin="5" />
+                       <Label Text="col1qsf" Margin="5" />
+                       <Label Text="col1qsf" Margin="5" />
+               </TableRow>
+               <TableRow 
+                               MouseEnter="{Background=RoyalBlue}"
+                               MouseLeave="{Background=Transparent}">
+                       <Label Text="col1qsf" Margin="5"/>
+                       <Label Text="col1qsfsdqfdqsfdqsfdqsf" Margin="5"/>
+                       <Label Text="col1qsfdsqfdqsf" Margin="5"/>
+               </TableRow>
+       </Table>
+</List>
\ No newline at end of file