Bar.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Linq;
  3. namespace Terminal.Gui;
  4. public class BarItem : View {
  5. public BarItem ()
  6. {
  7. Height = 1;
  8. }
  9. public override string Text {
  10. set {
  11. base.Text = $"{KeyBindings.Bindings.FirstOrDefault (b => b.Value.Scope != KeyBindingScope.Focused).Key} `{value}`";
  12. }
  13. get {
  14. return $"{KeyBindings.Bindings.FirstOrDefault(b => b.Value.Scope != KeyBindingScope.Focused).Key} `{base.Text}`";
  15. }
  16. }
  17. }
  18. /// <summary>
  19. /// The Bar <see cref="View"/> provides a container for other views to be used as a toolbar or status bar.
  20. /// </summary>
  21. /// <remarks>
  22. /// Views added to a Bar will be positioned horizontally from left to right.
  23. /// </remarks>
  24. public class Bar : View {
  25. /// <inheritdoc/>
  26. public Bar () => SetInitialProperties ();
  27. void SetInitialProperties ()
  28. {
  29. X = 0;
  30. Y = Pos.AnchorEnd (1);
  31. Width = Dim.Fill ();
  32. Height = 1;
  33. AutoSize = false;
  34. ColorScheme = Colors.Menu;
  35. }
  36. public override void Add (View view)
  37. {
  38. // Align the views horizontally from left to right. Use Border to separate them.
  39. // until we know this view is not the rightmost, make it fill the bar
  40. //view.Width = Dim.Fill ();
  41. view.Margin.Thickness = new Thickness (1, 0, 0, 0);
  42. view.Margin.ColorScheme = Colors.Menu;
  43. // Light up right border
  44. view.BorderStyle = LineStyle.Single;
  45. view.Border.Thickness = new Thickness (0, 0, 1, 0);
  46. view.Padding.Thickness = new Thickness (0, 0, 1, 0);
  47. view.Padding.ColorScheme = Colors.Menu;
  48. // leftmost view is at X=0
  49. if (Subviews.Count == 0) {
  50. view.X = 0;
  51. } else {
  52. // Make view to right be autosize
  53. //Subviews [^1].AutoSize = true;
  54. // Align the view to the right of the previous view
  55. view.X = Pos.Right (Subviews [^1]);
  56. }
  57. base.Add (view);
  58. }
  59. }