MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / ShowSourceCodeWindow

Method ShowSourceCodeWindow

Source/Editor/Utilities/Utils.cs:676–725  ·  view source on GitHub ↗

Shows the source code window. The source code. The window title. The optional parent window.

(string source, string title, Window parentWindow = null)

Source from the content-addressed store, hash-verified

674 /// <param name="title">The window title.</param>
675 /// <param name="parentWindow">The optional parent window.</param>
676 public static void ShowSourceCodeWindow(string source, string title, Window parentWindow = null)
677 {
678 if (string.IsNullOrEmpty(source))
679 {
680 MessageBox.Show("No generated shader source code.", "No source.");
681 return;
682 }
683
684 var settings = CreateWindowSettings.Default;
685 settings.ActivateWhenFirstShown = true;
686 settings.AllowMaximize = true;
687 settings.AllowMinimize = false;
688 settings.HasSizingFrame = true;
689 settings.HasBorder = true;
690 settings.StartPosition = WindowStartPosition.CenterParent;
691 settings.Size = new Float2(500, 600) * (parentWindow?.DpiScale ?? Platform.DpiScale);
692 settings.Parent = parentWindow;
693 settings.Title = title;
694 var dialog = Platform.CreateWindow(ref settings);
695
696 var copyButton = new Button(4, 4, 100)
697 {
698 Text = "Copy",
699 Parent = dialog.GUI,
700 };
701 copyButton.Clicked += () => Clipboard.Text = source;
702
703 var backPanel = new Panel
704 {
705 AnchorPreset = AnchorPresets.StretchAll,
706 Offsets = new Margin(0, 0, copyButton.Bottom + 4, 0),
707 ScrollBars = ScrollBars.Both,
708 IsScrollable = true,
709 Parent = dialog.GUI,
710 };
711
712 var sourceTextBox = new TextBox(true, 0, 0, 0);
713 sourceTextBox.Parent = backPanel;
714 sourceTextBox.AnchorPreset = AnchorPresets.HorizontalStretchTop;
715 sourceTextBox.Text = source;
716 sourceTextBox.Height = sourceTextBox.TextSize.Y;
717 sourceTextBox.IsReadOnly = true;
718 sourceTextBox.IsMultilineScrollable = false;
719 sourceTextBox.IsScrollable = true;
720
721 backPanel.SizeChanged += control => { sourceTextBox.Width = (control.Size.X >= sourceTextBox.TextSize.X) ? control.Width : sourceTextBox.TextSize.X + 30; };
722
723 dialog.Show();
724 dialog.Focus();
725 }
726
727 private static OrientedBoundingBox GetWriteBox(ref Vector3 min, ref Vector3 max, Real margin)
728 {

Callers 3

OpenMethod · 0.80
ShowSourceCodeMethod · 0.80
ShowSourceCodeMethod · 0.80

Calls 3

ShowMethod · 0.45
CreateWindowMethod · 0.45
FocusMethod · 0.45

Tested by

no test coverage detected