public LogWindow() : base("Log") { X = 0; Y = 1; Width = Dim.Percent(60); Height = Dim.Fill(); Add(items = new ListView(keys) { X = 0, Y = 0, Width = Dim.Sized(20), Height = Dim.Fill(), CanFocus = true, }); items.SelectedChanged += () => { Console.WriteLine("CHANGE!"); }; logView = new TextView() { X = 20, Y = 0, Width = Dim.Fill(), Height = Dim.Fill(), CanFocus = false }; Add(logView); keys.Add("Test"); }
public void Dim_Validation_Do_Not_Throws_If_NewValue_Is_DimAbsolute_And_OldValue_Is_Another_Type_After_Sets_To_LayoutStyle_Absolute() { Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true))); var t = Application.Top; var w = new Window("w") { Width = Dim.Fill(0), Height = Dim.Sized(10) }; var v = new View("v") { Width = Dim.Width(w) - 2, Height = Dim.Percent(10) }; w.Add(v); t.Add(w); t.Ready += () => { v.LayoutStyle = LayoutStyle.Absolute; Assert.Equal(2, v.Width = 2); Assert.Equal(2, v.Height = 2); }; Application.Iteration += () => Application.RequestStop(); Application.Run(); Application.Shutdown(); }
public void Sized_Equals() { int n1 = 0; int n2 = 0; var dim1 = Dim.Sized(n1); var dim2 = Dim.Sized(n2); Assert.Equal(dim1, dim2); n1 = n2 = 1; dim1 = Dim.Sized(n1); dim2 = Dim.Sized(n2); Assert.Equal(dim1, dim2); n1 = n2 = -1; dim1 = Dim.Sized(n1); dim2 = Dim.Sized(n2); Assert.Equal(dim1, dim2); n1 = 0; n2 = 1; dim1 = Dim.Sized(n1); dim2 = Dim.Sized(n2); Assert.NotEqual(dim1, dim2); }
protected virtual void UpdateWidth() { if (Control == null || Element == null) { return; } Control.Width = Dim.Sized(Element.Width > 0 ? Convert.ToInt32(Element.Width) : 0); }
protected virtual void UpdateHeight() { if (Control == null || Element == null) { return; } Control.Height = Dim.Sized(Element.Height > 0 ? Convert.ToInt32(Element.Height) : 0); }
static Label CreateCenteredLabel() { return(new Label(GetTimerText()) { X = Pos.Center(), Y = Pos.Center(), Width = Dim.Sized(24), Height = Dim.Sized(3), }); }
public static Window Init() { _window.Add(content); _window.Width = Dim.Sized(52); _window.Height = Dim.Sized(8); _window.X = Pos.Center(); _window.Y = Pos.Center(); _window.Add(save, quit); return(_window); }
public void ArrangeSubviews() { Layout.IsInNativeLayout = true; for (var i = 0; i < ElementController.LogicalChildren.Count; i++) { if (!(ElementController.LogicalChildren[i] is VisualElement child)) { continue; } IVisualElementRenderer renderer = Platform.GetRenderer(child); if (renderer == null) { continue; } Rectangle bounds = child.Bounds; View nativeView = renderer.GetNativeElement(); // Set child size var height = Convert.ToInt32(Math.Max(0, bounds.Height / SizeConverter)); if (height <= 0) { height = 1; } nativeView.Height = Dim.Sized(height); var width = Convert.ToInt32(Math.Max(0, bounds.Width / SizeConverter)); if (width <= 0) { width = 1; } nativeView.Width = Dim.Sized(width); // Set child position int x = Convert.ToInt32(bounds.X / SizeConverter); int y = Convert.ToInt32(bounds.Y / SizeConverter); nativeView.X = Pos.At(x); nativeView.Y = Pos.At(y); } Layout.IsInNativeLayout = false; }
public void Sized_SetsValue() { var dim = Dim.Sized(0); Assert.Equal("Dim.Absolute(0)", dim.ToString()); int testVal = 5; dim = Dim.Sized(testVal); Assert.Equal($"Dim.Absolute({testVal})", dim.ToString()); testVal = -1; dim = Dim.Sized(testVal); Assert.Equal($"Dim.Absolute({testVal})", dim.ToString()); }
public IpRangeView() { Width = Dim.Fill(); Height = Dim.Sized(1); // Dim.Fill(); var firstIpLabel = new Label("First Ip "); var firstIpText = new TextField("") { X = Pos.Right(firstIpLabel), Width = 15 }; var lastIpLabel = new Label(" Last ") { X = Pos.Right(firstIpText) }; var lastIpText = new TextField("") { X = Pos.Right(lastIpLabel), Width = 15 }; var scanButton = new Button("Scan"); scanButton.X = Pos.AnchorEnd() - (Pos.Right(scanButton) - Pos.Left(scanButton)); Add(firstIpLabel, lastIpLabel, firstIpText, lastIpText, scanButton); }
private static View CreaDetailsView(int posY) { var Details_View = new FrameView("Details") { X = 0, Y = posY, Width = Dim.Fill(), Height = 15 }; var LblId = new Label("ID:") { X = 0, Y = 0, Width = Dim.Sized(4), Height = Dim.Fill() }; var TxtId = new TextField("") { X = Pos.Right(LblId), Y = 0, Width = Dim.Sized(10), Height = Dim.Fill(), ReadOnly = true }; var LblDescrizione = new Label(" Descrizione:") { X = Pos.Right(TxtId), Y = 0, Width = Dim.Sized(13), Height = Dim.Fill() }; var TxtDescrizione = new TextField("") { X = Pos.Right(LblDescrizione), Y = 0, Width = Dim.Sized(70), Height = Dim.Fill() }; var LblMarca = new Label(" Marca:") { X = Pos.Right(TxtDescrizione), Y = 0, Width = Dim.Sized(7), Height = Dim.Fill() }; var TxtMarca = new TextField("") { X = Pos.Right(LblMarca), Y = 0, Width = Dim.Sized(40), Height = Dim.Fill() }; var LblUnita = new Label("Unita Misura:") { X = 0, Y = 2, Width = Dim.Sized(13), Height = Dim.Fill() }; var TxtUnita = new TextField("") { X = Pos.Right(LblUnita), Y = 2, Width = Dim.Sized(10), Height = Dim.Fill() }; var LblGiacenza = new Label(" Giacenza:") { X = Pos.Right(TxtUnita), Y = 2, Width = Dim.Sized(10), Height = Dim.Fill() }; var TxtGiacenza = new TextField("") { X = Pos.Right(LblGiacenza), Y = 2, Width = Dim.Sized(5), Height = Dim.Fill() }; var LblGiacenzaMin = new Label(" Giacenza MIN:") { X = Pos.Right(TxtGiacenza), Y = 2, Width = Dim.Sized(14), Height = Dim.Fill() }; var TxtGiacenzaMin = new TextField("") { X = Pos.Right(LblGiacenzaMin), Y = 2, Width = Dim.Sized(5), Height = Dim.Fill() }; var LblPrezzoUni = new Label(" Prezzo Unitario(€):") { X = Pos.Right(TxtGiacenzaMin), Y = 2, Width = Dim.Sized(20), Height = Dim.Fill() }; var TxtPrezzoUni = new TextField("") { X = Pos.Right(LblPrezzoUni), Y = 2, Width = Dim.Sized(10), Height = Dim.Fill() }; var LblIva = new Label(" IVA:") { X = Pos.Right(TxtPrezzoUni), Y = 2, Width = Dim.Sized(5), Height = Dim.Fill() }; var TxtIva = new TextField("") { X = Pos.Right(LblIva), Y = 2, Width = Dim.Sized(5), Height = Dim.Fill() }; var LblPrezzoTot = new Label(" PrezzoTot:") { X = Pos.Right(TxtIva), Y = 2, Width = Dim.Sized(11), Height = Dim.Fill() }; var TxtPrezzoTot = new TextField("") { X = Pos.Right(LblPrezzoTot), Y = 2, Width = Dim.Sized(10), Height = Dim.Fill() }; var LblFornitore = new Label(" Fornitore:") { X = Pos.Right(TxtPrezzoTot), Y = 2, Width = Dim.Sized(11), Height = Dim.Fill() }; var TxtFornitore = new TextField("") { X = Pos.Right(LblFornitore), Y = 2, Width = Dim.Sized(40), Height = Dim.Fill() }; var LblNote = new Label("Note:") { X = 0, Y = 4, Width = Dim.Sized(5), Height = Dim.Fill() }; var TxtNote = new TextView() { X = Pos.Right(LblNote), Y = 4, Width = 150, Height = 10 }; // var sendButton = new Button("Send", true) // { // X = Pos.Right(chatMessage), // Y = 0, // Width = Dim.Fill(), // Height = Dim.Fill() // }; // sendButton.Clicked += () => // { // Application.MainLoop.Invoke(() => // { // // _messages.Add($"{_username}: {chatMessage.Text}"); // // chatView.SetSource(_messages); // // chatMessage.Text = ""; // }); // }; Details_View.Add(LblId); Details_View.Add(TxtId); Details_View.Add(LblDescrizione); Details_View.Add(TxtDescrizione); Details_View.Add(LblMarca); Details_View.Add(TxtMarca); Details_View.Add(LblUnita); Details_View.Add(TxtUnita); Details_View.Add(LblGiacenza); Details_View.Add(TxtGiacenza); Details_View.Add(LblGiacenzaMin); Details_View.Add(TxtGiacenzaMin); Details_View.Add(LblPrezzoUni); Details_View.Add(TxtPrezzoUni); Details_View.Add(LblIva); Details_View.Add(TxtIva); Details_View.Add(LblPrezzoTot); Details_View.Add(TxtPrezzoTot); Details_View.Add(LblFornitore); Details_View.Add(TxtFornitore); Details_View.Add(LblNote); Details_View.Add(TxtNote); TxtDescrizione.Text = "CAZZONE"; return(Details_View); }
protected override void DrawWidget() { Title = settings.CpuRamWidgetTitle; // CPU part Label cpuTitle = new Label("CPU : ") { X = 1, Y = 1 }; Add(cpuTitle); _cpuBar = new Bar(settings.CpuRamWidgetBarColor, settings.MainBackgroundColor) { X = Pos.Right(cpuTitle), Y = 1, Width = Dim.Percent(75), Height = Dim.Sized(1) }; Add(_cpuBar); // Memory part Label ramTitle = new Label("RAM : ") { X = 1, Y = 3 }; Add(ramTitle); _ramBar = new Bar(settings.CpuRamWidgetRamBarColor, settings.MainBackgroundColor) { X = Pos.Right(ramTitle), Y = 3, Width = Dim.Percent(30), Height = Dim.Sized(1) }; Add(_ramBar); _ramDetails = new Label(string.Empty) { X = Pos.Right(_ramBar), Y = 3 }; Add(_ramDetails); Label swapTitle = new Label("Swap: ") { X = 1, Y = 4 }; Add(swapTitle); _swapBar = new Bar(settings.CpuRamWidgetSwapBarColor, settings.MainBackgroundColor) { X = Pos.Right(swapTitle), Y = 4, Width = Dim.Percent(30), Height = Dim.Sized(1) }; Add(_swapBar); _swapDetails = new Label(string.Empty) { X = Pos.Right(_swapBar), Y = 4 }; Add(_swapDetails); }
protected override void DrawWidget() { this.Title = settings.DiskWidgetTitle; // Disk activity Label titleWrite = new Label("Write (kB/sec): ") { X = 1, Y = 1 }; Add(titleWrite); _write = new Label(string.Empty) { X = Pos.Right(titleWrite), Y = 1 }; _write.TextColor = Terminal.Gui.Attribute.Make(settings.DiskWidgetWriteTextColor, settings.MainBackgroundColor); Add(_write); Label titleRead = new Label("Read (kB/sec) : ") { X = 1, Y = Pos.Bottom(titleWrite) }; Add(titleRead); _read = new Label(string.Empty) { X = Pos.Right(_write), Y = Pos.Bottom(_write) }; _read.TextColor = Terminal.Gui.Attribute.Make(settings.DiskWidgetReadTextColor, settings.MainBackgroundColor); Add(_read); // Disk usage var diskCount = systemInfo.DiskCount; _disksView = new View() { X = 1, Y = 4, Width = Dim.Fill(), Height = Dim.Fill() }; Add(_disksView); _disksName = new Label[diskCount]; _disksUsage = new Bar[diskCount]; int offset = 1; for (var i = 0; i < diskCount; i++) { _disksUsage[i] = new Bar(settings.DiskWidgetUsageBarColor, settings.MainBackgroundColor) { X = 1, Y = offset, Width = Dim.Percent(40), Height = Dim.Sized(1) }; _disksName[i] = new Label(string.Empty) { X = Pos.Right(_disksUsage[i]), Y = offset }; offset++; } _disksView.Add(_disksName); _disksView.Add(_disksUsage); }
public void New_Initializes() { // Parameterless var r = new View(); Assert.NotNull(r); Assert.Equal(LayoutStyle.Computed, r.LayoutStyle); Assert.Equal("View()({X=0,Y=0,Width=0,Height=0})", r.ToString()); Assert.False(r.CanFocus); Assert.False(r.HasFocus); Assert.Equal(new Rect(0, 0, 0, 0), r.Bounds); Assert.Equal(new Rect(0, 0, 0, 0), r.Frame); Assert.Null(r.Focused); Assert.Null(r.ColorScheme); Assert.Equal(Dim.Sized(0), r.Width); Assert.Equal(Dim.Sized(0), r.Height); // FIXED: Pos needs equality implemented Assert.Equal(Pos.At(0), r.X); Assert.Equal(Pos.At(0), r.Y); Assert.False(r.IsCurrentTop); Assert.Empty(r.Id); Assert.Empty(r.Subviews); Assert.False(r.WantContinuousButtonPressed); Assert.False(r.WantMousePositionReports); Assert.Null(r.SuperView); Assert.Null(r.MostFocused); Assert.Equal(TextDirection.LeftRight_TopBottom, r.TextDirection); // Empty Rect r = new View(Rect.Empty); Assert.NotNull(r); Assert.Equal(LayoutStyle.Absolute, r.LayoutStyle); Assert.Equal("View()({X=0,Y=0,Width=0,Height=0})", r.ToString()); Assert.False(r.CanFocus); Assert.False(r.HasFocus); Assert.Equal(new Rect(0, 0, 0, 0), r.Bounds); Assert.Equal(new Rect(0, 0, 0, 0), r.Frame); Assert.Null(r.Focused); Assert.Null(r.ColorScheme); Assert.NotNull(r.Width); // All view Dim are initialized now, Assert.NotNull(r.Height); // avoiding Dim errors. Assert.NotNull(r.X); // All view Pos are initialized now, Assert.NotNull(r.Y); // avoiding Pos errors. Assert.False(r.IsCurrentTop); Assert.Empty(r.Id); Assert.Empty(r.Subviews); Assert.False(r.WantContinuousButtonPressed); Assert.False(r.WantMousePositionReports); Assert.Null(r.SuperView); Assert.Null(r.MostFocused); Assert.Equal(TextDirection.LeftRight_TopBottom, r.TextDirection); // Rect with values r = new View(new Rect(1, 2, 3, 4)); Assert.NotNull(r); Assert.Equal(LayoutStyle.Absolute, r.LayoutStyle); Assert.Equal("View()({X=1,Y=2,Width=3,Height=4})", r.ToString()); Assert.False(r.CanFocus); Assert.False(r.HasFocus); Assert.Equal(new Rect(0, 0, 3, 4), r.Bounds); Assert.Equal(new Rect(1, 2, 3, 4), r.Frame); Assert.Null(r.Focused); Assert.Null(r.ColorScheme); Assert.NotNull(r.Width); Assert.NotNull(r.Height); Assert.NotNull(r.X); Assert.NotNull(r.Y); Assert.False(r.IsCurrentTop); Assert.Empty(r.Id); Assert.Empty(r.Subviews); Assert.False(r.WantContinuousButtonPressed); Assert.False(r.WantMousePositionReports); Assert.Null(r.SuperView); Assert.Null(r.MostFocused); Assert.Equal(TextDirection.LeftRight_TopBottom, r.TextDirection); // Initializes a view with a vertical direction r = new View("Vertical View", TextDirection.TopBottom_LeftRight); Assert.NotNull(r); Assert.Equal(LayoutStyle.Computed, r.LayoutStyle); Assert.Equal("View()({X=0,Y=0,Width=1,Height=13})", r.ToString()); Assert.False(r.CanFocus); Assert.False(r.HasFocus); Assert.Equal(new Rect(0, 0, 1, 13), r.Bounds); Assert.Equal(new Rect(0, 0, 1, 13), r.Frame); Assert.Null(r.Focused); Assert.Null(r.ColorScheme); Assert.NotNull(r.Width); // All view Dim are initialized now, Assert.NotNull(r.Height); // avoiding Dim errors. Assert.NotNull(r.X); // All view Pos are initialized now, Assert.NotNull(r.Y); // avoiding Pos errors. Assert.False(r.IsCurrentTop); Assert.Empty(r.Id); Assert.Empty(r.Subviews); Assert.False(r.WantContinuousButtonPressed); Assert.False(r.WantMousePositionReports); Assert.Null(r.SuperView); Assert.Null(r.MostFocused); Assert.Equal(TextDirection.TopBottom_LeftRight, r.TextDirection); }
/// <summary> /// Start the application /// </summary> public static void StartApp() { // Use injection to send the driver implementation to the core ServiceCollection serviceCollection = new ServiceCollection(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { serviceCollection.AddSingleton <ISystemInfo, WindowsDriver>(); } else { // Other drivers not implemented yet throw new NotImplementedException("This wttop version only supports Windows. Linux & OSX will come."); } // Add the settings configuration serviceCollection.AddSingleton <Settings>(); // Build the provider var serviceProvider = serviceCollection.BuildServiceProvider(); // Get the settings for what can be done here var settings = new Settings(); try { Application.Init(); } catch (Exception ex) { Console.WriteLine($"Error - could not initialize the application. The inner exception is {ex}"); } // Build the application UI with widgets var top = Application.Top; // Main color schema var mainColorScheme = new ColorScheme(); mainColorScheme.SetColorsForAllStates(settings.MainForegroundColor, settings.MainBackgroundColor); // Creates the top-level window to show var win = new WttopWindow(settings.MainAppTitle) { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill() }; win.ColorScheme = mainColorScheme; top.Add(win); var osInfoWidget = new OSInfoWidget(serviceProvider) { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Sized(3), CanFocus = false }; win.Add(osInfoWidget); var upTimeWidget = new UptimeWidget(serviceProvider) { X = 0, Y = 1, Width = Dim.Fill(), Height = Dim.Sized(3), CanFocus = false }; win.Add(upTimeWidget); var systemTimeWidget = new SystemTimeWidget(serviceProvider) { X = 0, Y = 2, Width = Dim.Fill(), Height = Dim.Sized(3), CanFocus = false }; win.Add(systemTimeWidget); var cpuRamWidget = new CpuRamWidget(serviceProvider) { X = 0, Y = Pos.Bottom(systemTimeWidget), Width = Dim.Percent(50), Height = Dim.Sized(18), CanFocus = false }; win.Add(cpuRamWidget); var viewTopRight = new View() { X = Pos.Right(cpuRamWidget), Y = Pos.Bottom(systemTimeWidget), Width = Dim.Fill(), Height = Dim.Sized(18), CanFocus = false }; win.Add(viewTopRight); var networkWidget = new NetworkWidget(serviceProvider) { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Sized(6), CanFocus = false }; var diskWidget = new DiskWidget(serviceProvider) { X = 0, Y = Pos.Bottom(networkWidget), Width = Dim.Fill(), Height = Dim.Fill(), CanFocus = false }; viewTopRight.Add(networkWidget); viewTopRight.Add(diskWidget); var processListWidget = new ProcessListWidget(serviceProvider) { X = 0, Y = Pos.Bottom(cpuRamWidget), Width = Dim.Fill(), Height = Dim.Fill() - 1, CanFocus = false }; win.Add(processListWidget); var toolbarView = new View() { X = 0, Y = Pos.Bottom(processListWidget), CanFocus = true }; win.Add(toolbarView); toolbarView.Add( new Button("Cpu") { X = 2, Y = 0, Clicked = () => { processListWidget.Order = ProcessListOrder.Cpu; } }, new Button("Memory") { X = 9, Y = 0, Clicked = () => { processListWidget.Order = ProcessListOrder.Memory; } }, new Button("Quit") { X = 24, Y = 0, Clicked = () => { top.Running = false; } }, new Button("About") { X = 33, Y = 0, Clicked = () => { Application.Run(AboutDialog()); } } ); // Refresh section. Every second, update on all listed widget will be called // Each seconds the UI refreshs, but a frequency can be set by overridind the property RefreshTimeSeconds for each widdget int tick = 0; var token = Application.MainLoop.AddTimeout(TimeSpan.FromSeconds(1), (MainLoop) => { // List all component to refresh Task.Run(async() => { await osInfoWidget.RefreshIfNeeded(MainLoop, tick); await upTimeWidget.RefreshIfNeeded(MainLoop, tick); await systemTimeWidget.RefreshIfNeeded(MainLoop, tick); await cpuRamWidget.RefreshIfNeeded(MainLoop, tick); await networkWidget.RefreshIfNeeded(MainLoop, tick); await diskWidget.RefreshIfNeeded(MainLoop, tick); await processListWidget.RefreshIfNeeded(MainLoop, tick); }); tick++; // Every hour put it back to 0 if (tick > 360) { tick = 1; } return(true); }); try { Application.Run(); } catch (Exception ex) { Console.WriteLine($"Error - could not launch the application. The inner exception is {ex}"); } }
public void Only_DimAbsolute_And_DimFactor_As_A_Different_Procedure_For_Assigning_Value_To_Width_Or_Height() { // Testing with the Button because it properly handles the Dim class. Application.Init(new FakeDriver(), new FakeMainLoop(() => FakeConsole.ReadKey(true))); var t = Application.Top; var w = new Window("w") { Width = 100, Height = 100 }; var f1 = new FrameView("f1") { X = 0, Y = 0, Width = Dim.Percent(50), Height = 5 }; var f2 = new FrameView("f2") { X = Pos.Right(f1), Y = 0, Width = Dim.Fill(), Height = 5 }; var v1 = new Button("v1") { X = Pos.X(f1) + 2, Y = Pos.Bottom(f1) + 2, Width = Dim.Width(f1) - 2, Height = Dim.Fill() - 2 }; var v2 = new Button("v2") { X = Pos.X(f2) + 2, Y = Pos.Bottom(f2) + 2, Width = Dim.Width(f2) - 2, Height = Dim.Fill() - 2 }; var v3 = new Button("v3") { Width = Dim.Percent(10), Height = Dim.Percent(10) }; var v4 = new Button("v4") { Width = Dim.Sized(50), Height = Dim.Sized(50) }; var v5 = new Button("v5") { Width = Dim.Width(v1) - Dim.Width(v3), Height = Dim.Height(v1) - Dim.Height(v3) }; var v6 = new Button("v6") { X = Pos.X(f2), Y = Pos.Bottom(f2) + 2, Width = Dim.Percent(20, true), Height = Dim.Percent(20, true) }; w.Add(f1, f2, v1, v2, v3, v4, v5, v6); t.Add(w); t.Ready += () => { Assert.Equal("Dim.Absolute(100)", w.Width.ToString()); Assert.Equal("Dim.Absolute(100)", w.Height.ToString()); Assert.Equal(100, w.Frame.Width); Assert.Equal(100, w.Frame.Height); Assert.Equal("Dim.Factor(factor=0.5, remaining=False)", f1.Width.ToString()); Assert.Equal("Dim.Absolute(5)", f1.Height.ToString()); Assert.Equal(49, f1.Frame.Width); // 50-1=49 Assert.Equal(5, f1.Frame.Height); Assert.Equal("Dim.Fill(margin=0)", f2.Width.ToString()); Assert.Equal("Dim.Absolute(5)", f2.Height.ToString()); Assert.Equal(49, f2.Frame.Width); // 50-1=49 Assert.Equal(5, f2.Frame.Height); Assert.Equal("Dim.Combine(DimView(side=Width, target=FrameView()({X=0,Y=0,Width=49,Height=5}))-Dim.Absolute(2))", v1.Width.ToString()); Assert.Equal("Dim.Combine(Dim.Fill(margin=0)-Dim.Absolute(2))", v1.Height.ToString()); Assert.Equal(47, v1.Frame.Width); // 49-2=47 Assert.Equal(89, v1.Frame.Height); // 98-5-2-2=89 Assert.Equal("Dim.Combine(DimView(side=Width, target=FrameView()({X=49,Y=0,Width=49,Height=5}))-Dim.Absolute(2))", v2.Width.ToString()); Assert.Equal("Dim.Combine(Dim.Fill(margin=0)-Dim.Absolute(2))", v2.Height.ToString()); Assert.Equal(47, v2.Frame.Width); // 49-2=47 Assert.Equal(89, v2.Frame.Height); // 98-5-2-2=89 Assert.Equal("Dim.Factor(factor=0.1, remaining=False)", v3.Width.ToString()); Assert.Equal("Dim.Factor(factor=0.1, remaining=False)", v3.Height.ToString()); Assert.Equal(9, v3.Frame.Width); // 98*10%=9 Assert.Equal(9, v3.Frame.Height); // 98*10%=9 Assert.Equal("Dim.Absolute(50)", v4.Width.ToString()); Assert.Equal("Dim.Absolute(50)", v4.Height.ToString()); Assert.Equal(50, v4.Frame.Width); Assert.Equal(50, v4.Frame.Height); Assert.Equal("Dim.Combine(DimView(side=Width, target=Button()({X=2,Y=7,Width=47,Height=89}))-DimView(side=Width, target=Button()({X=0,Y=0,Width=9,Height=9})))", v5.Width.ToString()); Assert.Equal("Dim.Combine(DimView(side=Height, target=Button()({X=2,Y=7,Width=47,Height=89}))-DimView(side=Height, target=Button()({X=0,Y=0,Width=9,Height=9})))", v5.Height.ToString()); Assert.Equal(38, v5.Frame.Width); // 47-9=38 Assert.Equal(80, v5.Frame.Height); // 89-9=80 Assert.Equal("Dim.Factor(factor=0.2, remaining=True)", v6.Width.ToString()); Assert.Equal("Dim.Factor(factor=0.2, remaining=True)", v6.Height.ToString()); Assert.Equal(9, v6.Frame.Width); // 47*20%=9 Assert.Equal(18, v6.Frame.Height); // 89*20%=18 w.Width = 200; w.Height = 200; t.LayoutSubviews(); Assert.Equal("Dim.Absolute(200)", w.Width.ToString()); Assert.Equal("Dim.Absolute(200)", w.Height.ToString()); Assert.Equal(200, w.Frame.Width); Assert.Equal(200, w.Frame.Height); f1.Text = "Frame1"; Assert.Equal("Dim.Factor(factor=0.5, remaining=False)", f1.Width.ToString()); Assert.Equal("Dim.Absolute(5)", f1.Height.ToString()); Assert.Equal(99, f1.Frame.Width); // 100-1=99 Assert.Equal(5, f1.Frame.Height); f2.Text = "Frame2"; Assert.Equal("Dim.Fill(margin=0)", f2.Width.ToString()); Assert.Equal("Dim.Absolute(5)", f2.Height.ToString()); Assert.Equal(99, f2.Frame.Width); // 100-1=99 Assert.Equal(5, f2.Frame.Height); v1.Text = "Button1"; Assert.Equal("Dim.Combine(DimView(side=Width, target=FrameView()({X=0,Y=0,Width=99,Height=5}))-Dim.Absolute(2))", v1.Width.ToString()); Assert.Equal("Dim.Absolute(1)", v1.Height.ToString()); Assert.Equal(97, v1.Frame.Width); // 99-2=97 Assert.Equal(1, v1.Frame.Height); // 1 because is Dim.DimAbsolute v2.Text = "Button2"; Assert.Equal("Dim.Combine(DimView(side=Width, target=FrameView()({X=99,Y=0,Width=99,Height=5}))-Dim.Absolute(2))", v2.Width.ToString()); Assert.Equal("Dim.Absolute(1)", v2.Height.ToString()); Assert.Equal(97, v2.Frame.Width); // 99-2=97 Assert.Equal(1, v2.Frame.Height); // 1 because is Dim.DimAbsolute v3.Text = "Button3"; Assert.Equal("Dim.Factor(factor=0.1, remaining=False)", v3.Width.ToString()); Assert.Equal("Dim.Absolute(1)", v3.Height.ToString()); Assert.Equal(19, v3.Frame.Width); // 198*10%=19 * Percent is related to the super-view if it isn't null otherwise the view width Assert.Equal(1, v3.Frame.Height); // 1 because is Dim.DimAbsolute v4.Text = "Button4"; v4.AutoSize = false; Assert.Equal("Dim.Absolute(50)", v4.Width.ToString()); Assert.Equal("Dim.Absolute(1)", v4.Height.ToString()); v4.AutoSize = true; Assert.Equal("Dim.Absolute(11)", v4.Width.ToString()); Assert.Equal("Dim.Absolute(1)", v4.Height.ToString()); Assert.Equal(11, v4.Frame.Width); // 11 is the text length and because is Dim.DimAbsolute Assert.Equal(1, v4.Frame.Height); // 1 because is Dim.DimAbsolute v5.Text = "Button5"; Assert.Equal("Dim.Combine(DimView(side=Width, target=Button()({X=2,Y=7,Width=97,Height=1}))-DimView(side=Width, target=Button()({X=0,Y=0,Width=19,Height=1})))", v5.Width.ToString()); Assert.Equal("Dim.Absolute(1)", v5.Height.ToString()); Assert.Equal(78, v5.Frame.Width); // 97-19=78 Assert.Equal(1, v5.Frame.Height); // 1 because is Dim.DimAbsolute v6.Text = "Button6"; Assert.Equal("Dim.Factor(factor=0.2, remaining=True)", v6.Width.ToString()); Assert.Equal("Dim.Absolute(1)", v6.Height.ToString()); Assert.Equal(19, v6.Frame.Width); // 99*20%=19 Assert.Equal(1, v6.Frame.Height); // 1 because is Dim.DimAbsolute }; Application.Iteration += () => Application.RequestStop(); Application.Run(); Application.Shutdown(); }
void DimPosChanged(View view) { if (view == null) { return; } try { switch (_xRadioGroup.Selected) { case 0: view.X = Pos.Percent(_xVal); break; case 1: view.X = Pos.AnchorEnd(_xVal); break; case 2: view.X = Pos.Center(); break; case 3: view.X = Pos.At(_xVal); break; } switch (_yRadioGroup.Selected) { case 0: view.Y = Pos.Percent(_yVal); break; case 1: view.Y = Pos.AnchorEnd(_yVal); break; case 2: view.Y = Pos.Center(); break; case 3: view.Y = Pos.At(_yVal); break; } switch (_wRadioGroup.Selected) { case 0: view.Width = Dim.Percent(_wVal); break; case 1: view.Width = Dim.Fill(_wVal); break; case 2: view.Width = Dim.Sized(_wVal); break; } switch (_hRadioGroup.Selected) { case 0: view.Height = Dim.Percent(_hVal); break; case 1: view.Height = Dim.Fill(_hVal); break; case 2: view.Height = Dim.Sized(_hVal); break; } } catch (Exception e) { MessageBox.ErrorQuery("Exception", e.Message, "Ok"); } UpdateTitle(view); }
static void Main(string[] args) { LoadSettings(); Application.Init(); Colors.Base.Normal = Application.Driver.MakeAttribute(Color.Green, Color.Black); Colors.ColorSchemes.Add("Highlight", new ColorScheme() { Normal = Application.Driver.MakeAttribute(Color.BrightGreen, Color.Black) }); var win = new Window() { X = 0, Y = 1, Width = Dim.Fill(), Height = Dim.Fill(), }; Application.Top.Add(win); //var win = Application.Top; var searchLabel = new Label() { X = 0, Y = 0, Text = "Search:", }; win.Add(searchLabel); var searchField = new TextField() { X = Pos.Right(searchLabel) + 1, Y = 0, Width = Dim.Sized(20), Height = 1, }; win.Add(searchField); var searchCount = new Label() { X = Pos.Right(searchField) + 1, Y = 0, }; win.Add(searchCount); var alwaysLabel = new Label() { X = Pos.Right(searchCount) + 3, Y = 0, Text = "Always Show:", }; win.Add(alwaysLabel); var alwaysField = new TextField() { X = Pos.Right(alwaysLabel) + 1, Y = 0, Width = Dim.Sized(20), Height = 1, TabStop = false, }; win.Add(alwaysField); var modeLabel = new Label() { X = Pos.Right(alwaysField) + 3, Y = 0, Text = "Mode:", }; win.Add(modeLabel); var modeRadio = new RadioGroup() { X = Pos.Right(modeLabel) + 1, Y = 0, Width = Dim.Sized(20), RadioLabels = new NStack.ustring[] { "Total ", "DPS ", "%Total " }, HorizontalSpace = 2, DisplayMode = DisplayModeLayout.Horizontal, TabStop = false, // annoying when tabbing between search and fights SelectedItem = settings.Mode, }; win.Add(modeRadio); //var fightSource = new FightDataSource(fightList); //var fightView = new ListView(fightSource) var fightView = new ListView(fightList) { X = 0, Y = 2, Width = Dim.Fill(), Height = Dim.Percent(50), //Height = 18, }; win.Add(fightView); // the bottom portion of the screen will contain "slots" for individual player information var slots = new List <View>(); for (var i = 0; i < 6; i++) { var slotView = new FrameView() { X = 0 + (i * 25), Y = Pos.Bottom(fightView) + 1, Width = 25, Height = Dim.Fill(), }; var slotText = new Label() { X = 0, Y = 0, Height = 10, Width = Dim.Fill(), Text = "..." }; slotView.Add(slotText); win.Add(slotView); slots.Add(slotText); } var status = new StatusBar() { Visible = true, Items = new StatusItem[] { new StatusItem(Key.Null, "...", () => { }), new StatusItem(Key.Null, "...", () => { }), new StatusItem(Key.Null, "Alt+Enter to toggle full screen", () => { }) }, Text = "Ready..." }; Application.Top.Add(status); searchField.KeyDown += (key) => { if (key.KeyEvent.Key == Key.Esc) { searchField.Text = ""; } }; searchField.TextChanged += (_) => { var s = searchField.Text.ToString(); if (String.IsNullOrEmpty(s)) { fightListSource = null; fightView.SetSource(fightList); searchCount.Text = ""; } else { fightListSource = fightList.Where(x => x.IsMatch(s)).ToList(); fightView.SetSource(fightListSource); fightView.OnSelectedChanged(); searchCount.Text = $"{fightListSource.Count} matches"; } }; alwaysField.TextChanged += (_) => { fightView.OnSelectedChanged(); }; modeRadio.SelectedItemChanged += (args) => { fightView.OnSelectedChanged(); }; fightView.SelectedItemChanged += (args) => { var list = fightListSource ?? fightList; if (args.Item >= list.Count) { return; } var f = list[args.Item].Info; //status.Items[2].Title = DateTime.Now.ToString() + " " + f.Name + " " + f.Participants[0].OutboundHitSum; var mode = modeRadio.SelectedItem; var players = f.Participants.Take(slots.Count).ToList(); var always = alwaysField.Text.ToString().Split(',', StringSplitOptions.RemoveEmptyEntries); if (always.Length > 0) { players = f.Participants .Select((x, i) => new { Always = always.Contains(x.Name, StringComparer.InvariantCultureIgnoreCase) && x.OutboundHitSum > 0, Index = i, Player = x }) .OrderBy(x => !x.Always).ThenBy(x => x.Index) .Take(slots.Count) .OrderBy(x => x.Index) // restore order after take() keeps the "always" entries .Select(x => x.Player) .ToList(); } for (var i = 0; i < slots.Count; i++) { slots[i].Text = ""; if (i >= players.Count) { continue; } var p = players[i]; if (p.OutboundHitSum == 0) { continue; } var text = new StringBuilder(); text.AppendLine($"{p.Name} - {p.Class}"); if (mode == 0) { text.AppendLine($"{FightUtils.FormatNum(p.OutboundHitSum)}"); } else if (mode == 1) { text.AppendLine($"{FightUtils.FormatNum(p.OutboundHitSum / f.Duration)} DPS"); } else if (mode == 2) { text.AppendLine($"{((double)p.OutboundHitSum / f.HP).ToString("P1")} of Total"); text.AppendLine($"{((double)p.OutboundHitSum / f.TopHitSum).ToString("P1")} vs Top Player"); } text.AppendLine("---"); foreach (var dmg in p.AttackTypes) { if (mode == 0) { text.AppendLine($"{Clip(dmg.Type, 15),-15} {FightUtils.FormatNum(dmg.HitSum),6}"); } else if (mode == 1) { text.AppendLine($"{Clip(dmg.Type, 15),-15} {FightUtils.FormatNum(dmg.HitSum / f.Duration),6}"); } else if (mode == 2) { text.AppendLine($"{Clip(dmg.Type, 15),-15} {((double)dmg.HitSum / p.OutboundHitSum).ToString("P0"),6}"); } } text.AppendLine("---"); foreach (var spell in p.Spells.Where(x => x.HitSum > 0 && x.Type == "hit")) { if (mode == 0) { text.AppendLine($"{Clip(spell.Name, 15),-15} {FightUtils.FormatNum(spell.HitSum),6}"); } else if (mode == 1) { text.AppendLine($"{Clip(spell.Name, 15),-15} {FightUtils.FormatNum(spell.HitSum / f.Duration),6}"); } else if (mode == 2) { text.AppendLine($"{Clip(spell.Name, 15),-15} {((double)spell.HitSum / p.OutboundHitSum).ToString("P0"),6}"); } } slots[i].Text = text.ToString(); slots[i].SuperView.ColorScheme = always.Contains(p.Name, StringComparer.InvariantCultureIgnoreCase) ? Colors.ColorSchemes["Highlight"] : Colors.Base; } }; var path = settings.Path; if (args.Length > 1 && File.Exists(args[1])) { path = args[1]; } if (File.Exists(path)) { alwaysField.Text = LogOpenEvent.FromFileName(path)?.Player ?? ""; status.Items[2].Title = path; _ = OpenLog(path); //status.Items[2].Title = ""; } Func <Exception, bool> errorHandler = (Exception e) => { MessageBox.ErrorQuery("Error", e.Message + "\n", "OK"); return(true); }; var menu = new MenuBar(new MenuBarItem[] { new MenuBarItem("_File", new MenuItem [] { new MenuItem("_Open", "", () => { var open = new OpenDialog(); open.AllowedFileTypes = new[] { ".txt" }; open.Message = "Select a file starting with: eqlog_"; open.LayoutStyle = LayoutStyle.Computed; open.AllowsMultipleSelection = false; if (File.Exists(settings.Path)) { open.DirectoryPath = Path.GetDirectoryName(settings.Path); } Application.Run(open); if (!open.Canceled) { fightView.SelectedItem = 0; path = open.FilePath.ToString(); alwaysField.Text = LogOpenEvent.FromFileName(path)?.Player ?? ""; status.Items[2].Title = path; _ = OpenLog(path); } }), new MenuItem("_Quit", "", () => { Application.RequestStop(); }) }), }); Application.Top.Add(menu); Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(100), (_) => { var count = 0; while (fightQueue.TryDequeue(out FightInfo f) && count++ < 50) { //fightList.Add(f); // oldest to newest fightList.Insert(0, new FightInfoRow(f)); // newest to oldest } if (count > 0) { status.Items[0].Title = $"{fightList.Count} fights"; fightView.OnSelectedChanged(); //status.SetNeedsDisplay(); //fightView.SetNeedsDisplay(); if (logReader != null) { status.Items[1].Title = $"{logReader.Percent:P0} in {logReader.Elapsed:F1}s"; } } return(true); });
public static void RunUiLoop(Config config, IPullRequestSource source) { if (config == null) { throw new ArgumentNullException(nameof(config)); } Application.Init(); Application.Current.ColorScheme = CustomColorSchemes.Main; Toplevel top = Application.Top; top.X = Pos.Center(); top.Y = Pos.Center(); top.Height = Dim.Fill(); top.Width = Dim.Fill(); Dim computedHeight = Dim.Sized(0); // We intentionally initialize the status bar first, as the status // bar hooks events on the source, and the pull request view, will // drive API calls on the source which will trigger those events. // To avoid races here, make sure to hook first, run later. // StatusBar?statusBar = null; if (config.StatusBarEnabled) { computedHeight += StatusBarHeight; statusBar = new StatusBar(source); } TextView?descriptionView = null; if (config.DescriptionEnabled) { computedHeight += DescriptionHeight; descriptionView = new TextView() { Height = Dim.Fill(), Width = Dim.Fill(), ReadOnly = true, }; } using PullRequestView requestView = new PullRequestView(source, descriptionView); using Window contentWindow = new Window(ActionableTitle) { Width = Dim.Fill(), Height = Dim.Fill() - computedHeight, ColorScheme = WindowTheme, }; contentWindow.Add(requestView); top.Add(contentWindow); if (config.DescriptionEnabled) { Window descriptionWindow = new Window("Description:") { Width = Dim.Fill(), Height = DescriptionHeight, Y = Pos.Bottom(contentWindow), ColorScheme = WindowTheme, }; descriptionWindow.Add(descriptionView); top.Add(descriptionWindow); } if (config.StatusBarEnabled) { Window statusWindow = new Window("Status:") { Width = Dim.Fill(), Height = StatusBarHeight, Y = Pos.Bottom(top.Subviews.Last()), ColorScheme = WindowTheme, }; statusWindow.Add(statusBar); top.Add(statusWindow); } // Start processing data within the view now that everything is constructed. // requestView.Start(); Application.Run(); }
private static View CreaFindView() { var FindViewFrame = new FrameView("Ricerca") { X = 0, Y = 1, Width = Dim.Fill(), Height = Dim.Sized(3), }; var LblFindCategoria = new Label("Categoria:") { X = 0, Y = 0, Width = Dim.Sized(11), Height = Dim.Fill() }; var CmbFindCategoria = new ComboBox() { X = Pos.Right(LblFindCategoria), Y = 0, Width = Dim.Sized(40), Height = Dim.Fill() }; //sorgente di esempio altrimenti esplode quando in run se vuoto CmbFindCategoria.SetSource(CaricaCategoria()); // CmbFindCategoria.OpenSelectedItem += (ListViewItemEventArgs text) => { Application.RequestStop(); }; var LblFindCodice = new Label(" Codice Articolo:") { X = Pos.Right(CmbFindCategoria), Y = 0, //17 e il numero di caratteri per scrivere 'Codice articolo' Width = Dim.Sized(17), Height = Dim.Fill() }; var FindCodiceArticolo = new TextField("") { X = Pos.Right(LblFindCodice), Y = 0, Width = Dim.Sized(40), Height = Dim.Fill() }; var LblFindDescrizione = new Label(" Descrizione:") { X = Pos.Right(FindCodiceArticolo), Y = 0, //17 e il numero di caratteri per scrivere 'Codice articolo' Width = Dim.Sized(13), Height = Dim.Fill() }; var FindDescrizione = new TextField("") { X = Pos.Right(LblFindDescrizione), Y = 0, Width = Dim.Sized(50), Height = Dim.Fill() }; FindViewFrame.Add(LblFindCategoria); FindViewFrame.Add(CmbFindCategoria); FindViewFrame.Add(LblFindCodice); FindViewFrame.Add(FindCodiceArticolo); FindViewFrame.Add(LblFindDescrizione); FindViewFrame.Add(FindDescrizione); return(FindViewFrame); }