NetworkConfiguratorDeviceList.xaml.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.Numerics;
  2. using Robust.Client.AutoGenerated;
  3. using Robust.Client.UserInterface.Controls;
  4. namespace Content.Client.NetworkConfigurator;
  5. [GenerateTypedNameReferences]
  6. public sealed partial class NetworkConfiguratorDeviceList : ScrollContainer
  7. {
  8. public event Action<string>? OnRemoveAddress;
  9. public void UpdateState(HashSet<(string address, string name)> devices, bool ui)
  10. {
  11. DeviceList.RemoveAllChildren();
  12. foreach (var device in devices)
  13. {
  14. DeviceList.AddChild(BuildDeviceListRow(device, ui));
  15. }
  16. }
  17. private BoxContainer BuildDeviceListRow((string address, string name) savedDevice, bool ui)
  18. {
  19. var row = new BoxContainer()
  20. {
  21. Orientation = BoxContainer.LayoutOrientation.Horizontal,
  22. Margin = new Thickness(8)
  23. };
  24. var name = new Label()
  25. {
  26. Text = savedDevice.name[..Math.Min(11, savedDevice.name.Length)],
  27. SetWidth = 84
  28. };
  29. var address = new Label()
  30. {
  31. Text = savedDevice.address,
  32. HorizontalExpand = true,
  33. Align = Label.AlignMode.Center
  34. };
  35. var removeButton = new TextureButton()
  36. {
  37. StyleClasses = { "CrossButtonRed" },
  38. VerticalAlignment = VAlignment.Center,
  39. Scale = new Vector2(0.5f, 0.5f)
  40. };
  41. row.AddChild(name);
  42. row.AddChild(address);
  43. if (ui)
  44. {
  45. row.AddChild(removeButton);
  46. removeButton.OnPressed += _ => OnRemoveAddress?.Invoke(savedDevice.address);
  47. }
  48. return row;
  49. }
  50. }