GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — NowUI/Assets/NowUI/Example/NowDocsExample.cs at main · AboutUnity/NowUI Expand file tree/ Copy pathNowDocsExample.csMore file actions 4163 lines (3516 loc) · 160 KB / Copy pathNowDocsExample.csFile metadata and controls4163 lines (3516 loc) · 160 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 #if NOWUI_UGUI using System.Collections.Generic; using System.IO; using System.Runtime.CompilerServices; using JetBrains.Annotations; using UnityEngine; using NowUI; using NowUI.CodeEditor; using NowUI.Docking; using NowUI.Markup; using NowUI.Markdown; using NowUI.Sdf; /// <summary> /// Browses the package's Documentation~/ folder: a tree menu of pages, the selected /// page rendered through the markdown extension, and live demo pages for /// extension/runtime examples. Relative .md links navigate between /// pages; external links open in the browser. /// </summary> [AddComponentMenu("NowUI/Examples/Now Docs Browser")] public class NowDocsExample : NowLayoutGraphic { enum PageId { Overview, Features, Api, Performance, Layout, Controls, ControlsGallery, FilePickerDemo, ViewStackDemo, CustomControls, CustomControlsDemo, StylesThemes, Mobile, EditorGui, RichText, RichTextDemo, Markdown, Markup, MarkupDemo, CodeEditor, CodeEditorDemo, Lottie, LottieDemo, Lines, LinesDemo, Shapes, ShapesDemo, Glass, GlassDemo, CustomMaterials, CustomMaterialsDemo, Effects, EffectsDemo, ModelPreviews, ModelPreviewsDemo, WorldSpace, RenderPipelines, Docking, DockingDemo, NodeGraph, Sdf, SdfDemo, TextStyling, TextStylingDemo, } enum PageKind { [UsedImplicitly] Markdown, ControlsDemo, ControlsGalleryDemo, LottieDemo, CodeEditorDemo, MarkupDemo, RichTextDemo, SdfDemo, DockingDemo, LinesDemo, ShapesDemo, CustomMaterialsDemo, GlassDemo, EffectsDemo, ModelPreviewsDemo, ViewStackDemo, FilePickerDemo, TextStylingDemo, } struct Page { public string title; public string file; public string icon; public PageKind kind; } struct NavEntry { public string title; public string icon; public int pageIndex; public int depth; public bool section; } static readonly Page[] Pages = { new Page { title = "Overview", file = "README.md", icon = "🏠" }, new Page { title = "Features", file = "Features.md", icon = "✨" }, new Page { title = "Public API", file = "API.md", icon = "🧩" }, new Page { title = "Performance", file = "Performance.md", icon = "🚢" }, new Page { title = "Layout", file = "Layout.md", icon = "📐" }, new Page { title = "Controls", file = "Controls.md", icon = "🎛️" }, new Page { title = "Controls gallery", icon = "🧪", kind = PageKind.ControlsGalleryDemo }, new Page { title = "File picker demo", icon = "📁", kind = PageKind.FilePickerDemo }, new Page { title = "View stack demo", icon = "🧭", kind = PageKind.ViewStackDemo }, new Page { title = "Custom controls", file = "CustomControls.md", icon = "🧰" }, new Page { title = "Custom controls demo", icon = "🧪", kind = PageKind.ControlsDemo }, new Page { title = "Styles & themes", file = "StylesAndThemes.md", icon = "🎨" }, new Page { title = "Mobile", file = "Mobile.md", icon = "📱" }, new Page { title = "IMGUI", file = "EditorGUI.md", icon = "🖥️" }, new Page { title = "Rich text", file = "RichText.md", icon = "🔤" }, new Page { title = "Rich text demo", icon = "🧪", kind = PageKind.RichTextDemo }, new Page { title = "Markdown", file = "Markdown.md", icon = "📝" }, new Page { title = "Markup", file = "Markup.md", icon = "🧱" }, new Page { title = "Markup demo", icon = "🧪", kind = PageKind.MarkupDemo }, new Page { title = "Code editor", file = "CodeEditor.md", icon = "👩💻" }, new Page { title = "Editor demo", icon = "🧪", kind = PageKind.CodeEditorDemo }, new Page { title = "Lottie", file = "Lottie.md", icon = "🎞️" }, new Page { title = "Lottie demo", icon = "🧪", kind = PageKind.LottieDemo }, new Page { title = "Lines", file = "Lines.md", icon = "➖" }, new Page { title = "Lines demo", icon = "🧪", kind = PageKind.LinesDemo }, new Page { title = "Shapes", file = "Shapes.md", icon = "🔺" }, new Page { title = "Shapes demo", icon = "🧪", kind = PageKind.ShapesDemo }, new Page { title = "Glass", file = "Glass.md", icon = "🧊" }, new Page { title = "Glass demo", icon = "🧪", kind = PageKind.GlassDemo }, new Page { title = "Custom materials", file = "CustomMaterials.md", icon = "🖼️" }, new Page { title = "Custom material demo", icon = "🧪", kind = PageKind.CustomMaterialsDemo }, new Page { title = "Effects", file = "Effects.md", icon = "🌊" }, new Page { title = "Effects demo", icon = "🧪", kind = PageKind.EffectsDemo }, new Page { title = "Model previews", file = "ModelPreviews.md", icon = "🧍" }, new Page { title = "Model previews demo", icon = "🧪", kind = PageKind.ModelPreviewsDemo }, new Page { title = "World space", file = "WorldSpace.md", icon = "🌍" }, new Page { title = "Render pipelines", file = "RenderPipelines.md", icon = "🎛️" }, new Page { title = "Docking", file = "Docking.md", icon = "🧲" }, new Page { title = "Docking demo", icon = "🧪", kind = PageKind.DockingDemo }, new Page { title = "Node graph", file = "NodeGraph.md", icon = "🕸️" }, new Page { title = "SDF shapes", file = "SDF.md", icon = "⚫" }, new Page { title = "SDF demo", icon = "🧪", kind = PageKind.SdfDemo }, new Page { title = "Text styling", file = "TextStyling.md", icon = "🔠" }, new Page { title = "Text styling demo", icon = "🧪", kind = PageKind.TextStylingDemo }, }; static readonly NavEntry[] Navigation = { Section("Start", "🚀"), Link(PageId.Overview), Link(PageId.Features), Link(PageId.Api), Link(PageId.Performance), Section("Core UI", "🧱"), Link(PageId.Layout), Link(PageId.Controls), Link(PageId.ControlsGallery, 1), Link(PageId.FilePickerDemo, 1), Link(PageId.ViewStackDemo, 1), Link(PageId.CustomControls), Link(PageId.CustomControlsDemo, 1), Link(PageId.StylesThemes), Link(PageId.Mobile), Link(PageId.EditorGui), Section("Text & Content", "✏️"), Link(PageId.TextStyling), Link(PageId.TextStylingDemo, 1), Link(PageId.RichText), Link(PageId.RichTextDemo, 1), Link(PageId.Markdown), Link(PageId.Markup), Link(PageId.MarkupDemo, 1), Link(PageId.CodeEditor), Link(PageId.CodeEditorDemo, 1), Link(PageId.Lottie), Link(PageId.LottieDemo, 1), Section("Rendering", "🎬"), Link(PageId.Lines), Link(PageId.LinesDemo, 1), Link(PageId.Shapes), Link(PageId.ShapesDemo, 1), Link(PageId.Glass), Link(PageId.GlassDemo, 1), Link(PageId.CustomMaterials), Link(PageId.CustomMaterialsDemo, 1), Link(PageId.Effects), Link(PageId.EffectsDemo, 1), Link(PageId.ModelPreviews), Link(PageId.ModelPreviewsDemo, 1), Link(PageId.WorldSpace), Link(PageId.RenderPipelines), Section("Extensions", "🧩"), Link(PageId.Docking), Link(PageId.DockingDemo, 1), Link(PageId.NodeGraph), Link(PageId.Sdf), Link(PageId.SdfDemo, 1), }; static NavEntry Section(string title, string icon) { return new NavEntry { title = title, icon = icon, pageIndex = -1, section = true }; } static NavEntry Link(PageId page, int depth = 0) { return new NavEntry { pageIndex = (int)page, depth = depth }; } static readonly int FrostTintId = Shader.PropertyToID("_FrostTint"); static readonly int FrostEdgeId = Shader.PropertyToID("_FrostEdge"); static readonly int FrostAmountId = Shader.PropertyToID("_FrostAmount"); static readonly int FrostNoiseScaleId = Shader.PropertyToID("_NoiseScale"); static readonly int FrostTimeScaleId = Shader.PropertyToID("_TimeScale"); [SerializeField] NowThemeAsset _themeAsset; [SerializeField] NowFontAsset _font; [SerializeField] NowLottieAsset[] _lotties; int _selected; string _docsSearch = ""; bool _forceHarnessScrollTop; int _rating = 3; int _builderRating = 2; int _clicks; int _gallerySaves; bool _galleryShadows = true; bool _galleryNotifications = true; bool _galleryChipSelected = true; bool _galleryAdvanced; int _galleryQuality = 1; float _galleryVolume = 0.72f; float _gallerySpeed = 24f; int _galleryLives = 3; Vector3 _gallerySpawn = new Vector3(0f, 1.5f, 4f); Color _galleryTint = new Color(0.36f, 0.62f, 1f, 1f); Gradient _galleryRamp; AnimationCurve _galleryFalloff; string _galleryName = ""; string _galleryNotes = ""; int _galleryResolution = 1; int _galleryTab; int _galleryCountry; int _galleryChannels = 3; LayerMask _galleryLayers = 1; GalleryQuality _galleryQualityLevel = GalleryQuality.High; GalleryChannels _galleryChannelFlags = GalleryChannels.Music | GalleryChannels.Effects; System.DateTime _galleryDate; System.TimeSpan _galleryAlarm = new System.TimeSpan(7, 30, 0); #if NOWUI_INPUT_SYSTEM UnityEngine.InputSystem.Key _galleryJumpKey = UnityEngine.InputSystem.Key.Space; #endif bool _lottieScrub; float _lottieProgress = 0.35f; bool _sdfDemoLocked; readonly NowDockSpace _dockDemo = new NowDockSpace(); bool _dockDemoLayoutApplied; bool _dockDemoGrid = true; float _dockDemoExposure = 0.62f; int _dockDemoSelection = 1; int _dockDemoMessages; bool _effectsDemoTexture; bool _effectsDemoAuto = true; bool _effectsDemoWave = true; float _effectsDemoProgress = 0.55f; float _effectsDemoSubdivision = 4f; bool _modelPreviewDemoAutoRotate = true; bool _modelPreviewDemoPaused; bool _modelPreviewDemoSceneLighting; bool _modelPreviewDemoPostProcessing; int _modelPreviewDemoUpdateMode; float _modelPreviewDemoAngle = 18f; float _modelPreviewDemoResolutionScale = 0.8f; float _modelPreviewDemoWaveAmplitude = 6f; bool _customMaterialAnimate = true; float _customMaterialFrost = 0.72f; float _customMaterialRadius = 28f; bool _glassDemoAnimate = true; float _glassDemoBlur = 8f; float _glassDemoTint = 0.06f; float _glassDemoRadius = 28f; float _glassDemoOutline = 1.5f; float _glassDemoSaturation = 1.15f; bool _glassDemoDebug = true; int _glassDemoQuality = 0; int _richTextLinkClicks; string _richTextLastLink = "none"; float _textOutlineDemoPixels = 32f; bool _textOutlineDemoUseSdf; NowRichTextParser _richTextDemoParser; readonly NowRichTextSpan[] _richTextDemoSpans = new NowRichTextSpan[3]; readonly NowViewStack _viewStackDemo = new NowViewStack(); DocsViewStackHomeView _viewStackHomeView; DocsViewStackDetailsView _viewStackDetailsView; DocsViewStackPopupView _viewStackPopupView; int _viewStackDemoOpens; int _viewStackDemoConfirms; float _viewStackDemoProgress = 0.64f; bool _viewStackDemoSync = true; string _filePickerOpenPath = ""; string _filePickerSavePath = ""; string _filePickerDirectoryPath = ""; bool _filePickerShowHidden; int _filePickerChanges; readonly NowMarkupState _markupDemoState = new NowMarkupState(); int _markupDemoClicks; string _markupDemoLastEvent = "none"; Texture2D _sdfDemoTexture; Texture2D _customMaterialTexture; Material _customMaterialCanvas; NowModelPreviewDemoRig _modelPreviewDemoRig; string _modelPreviewDemoError; readonly NowSdfGraph _sdfDemoIdle = NowSdf.Graph(); readonly NowSdfGraph _sdfDemoActive = NowSdf.Graph(); static readonly string[] GlassQualityLabels = { "Auto", "Fast", "Balanced", "High", "Ultra" }; static readonly string[] ModelPreviewUpdateLabels = { "When dirty", "Every frame", "Manual" }; readonly NowSdfGraph _sdfDemoGlow = NowSdf.Graph(); readonly NowSdfGraph _sdfDemoStreaks = NowSdf.Graph(); readonly NowSdfGraph _sdfDemoOrbit = NowSdf.Graph(); readonly NowSdfGraph _sdfDemoTextIdle = NowSdf.Graph(); readonly NowSdfGraph _sdfDemoTextActive = NowSdf.Graph(); readonly Vector2[] _shapeDemoPolygon = new Vector2[6]; readonly Dictionary<string, string> _docs = new Dictionary<string, string>(); static bool _documentationRootResolved; static string _documentationRoot; protected override void OnEnable() { base.OnEnable(); EnsureModelPreviewDemo(); } protected override void OnDisable() { ReleaseModelPreviewDemo(); base.OnDisable(); } void EnsureModelPreviewDemo() { if (_modelPreviewDemoRig != null || !string.IsNullOrEmpty(_modelPreviewDemoError)) return; try { _modelPreviewDemoRig = new NowModelPreviewDemoRig(); _modelPreviewDemoRig.preview .SetMaxResolution(512) .SetBackground(new Color(0.012f, 0.028f, 0.052f, 1f)); } catch (System.Exception exception) { _modelPreviewDemoError = exception.Message; Debug.LogException(exception, this); } } void ReleaseModelPreviewDemo() { _modelPreviewDemoRig?.Dispose(); _modelPreviewDemoRig = null; } internal void ConfigureModelPreviewsDemoHarness(NowThemeAsset theme, NowFontAsset font) { _themeAsset = theme; _font = font; _selected = (int)PageId.ModelPreviewsDemo; _modelPreviewDemoAutoRotate = false; _modelPreviewDemoPaused = false; _modelPreviewDemoSceneLighting = false; _modelPreviewDemoPostProcessing = false; _modelPreviewDemoUpdateMode = (int)NowModelPreviewUpdateMode.WhenDirty; _modelPreviewDemoAngle = 18f; _modelPreviewDemoResolutionScale = 0.8f; _modelPreviewDemoWaveAmplitude = 6f; EnsureModelPreviewDemo(); } internal void ConfigureOverviewHarness(NowThemeAsset theme, NowFontAsset font) { ConfigurePageHarness(theme, font, "Overview"); } internal void ConfigureTextStylingDemoHarness( NowThemeAsset theme, NowFontAsset font, float outlinePixels = 100f, bool useSdf = true) { ConfigurePageHarness(theme, font, "Text styling demo"); _textOutlineDemoPixels = Mathf.Clamp(outlinePixels, 0f, 100f); _textOutlineDemoUseSdf = useSdf; } internal void ConfigurePageHarness(NowThemeAsset theme, NowFontAsset font, string pageTitle) { _themeAsset = theme; _font = font; _docsSearch = ""; for (int i = 0; i < Pages.Length; ++i) { if (!string.Equals(Pages[i].title, pageTitle, System.StringComparison.Ordinal)) continue; _selected = i; return; } throw new System.ArgumentException($"Unknown docs page '{pageTitle}'.", nameof(pageTitle)); } internal void PinHarnessScrollTop() { _forceHarnessScrollTop = true; } internal bool RenderModelPreviewsDemoNowForHarness() { return _modelPreviewDemoRig?.preview.RenderNow() ?? false; } string LoadDoc(string file) { if (_docs.TryGetValue(file, out string text)) return text; try { string root = ResolveDocumentationRoot(); if (string.IsNullOrEmpty(root)) throw new DirectoryNotFoundException("Could not locate the installed NowUI Documentation~ directory."); text = File.ReadAllText(Path.Combine(root, file)); } catch (System.Exception exception) { text = $"# {file}\n\nCould not read the installed package's" + $" `Documentation~/{file}` file:\n\n```\n{exception.Message}\n```"; } _docs[file] = text; return text; } static string ResolveDocumentationRoot() { if (_documentationRootResolved) return _documentationRoot; _documentationRootResolved = true; #if UNITY_EDITOR var package = UnityEditor.PackageManager.PackageInfo.FindForAssembly(typeof(Now).Assembly); if (package != null) { string resolved = Path.Combine(package.resolvedPath, "Documentation~"); if (Directory.Exists(resolved)) return _documentationRoot = resolved; } #endif try { string projectRoot = Path.GetFullPath(Path.Combine(Application.dataPath, "..")); string[] directCandidates = { Path.Combine(projectRoot, "Assets", "NowUI", "Documentation~"), Path.Combine(projectRoot, "Packages", "com.blenminer.nowui", "Documentation~"), }; for (int i = 0; i < directCandidates.Length; ++i) { if (Directory.Exists(directCandidates[i])) return _documentationRoot = directCandidates[i]; } string cacheRoot = Path.Combine(projectRoot, "Library", "PackageCache"); if (Directory.Exists(cacheRoot)) { string[] packageRoots = Directory.GetDirectories(cacheRoot, "com.blenminer.nowui@*"); for (int i = 0; i < packageRoots.Length; ++i) { string candidate = Path.Combine(packageRoots[i], "Documentation~"); if (Directory.Exists(candidate)) return _documentationRoot = candidate; } } } catch (System.Exception exception) when ( exception is IOException || exception is System.UnauthorizedAccessException || exception is System.ArgumentException || exception is System.NotSupportedException) { } return null; } void NavigateLink(string link) { string target = Path.GetFileName(link.Split('#')[0]); for (int i = 0; i < Pages.Length; ++i) { if (Pages[i].file == target) { _selected = i; return; } } Application.OpenURL(link); } void DrawDocsSidebarHeader(NowThemeAsset theme, NowRect rect) { bool editorChrome = UsesUnityEditorChrome(theme); Color text = theme.GetColor(NowColorToken.Text, Color.white); Color muted = theme.GetColor(NowColorToken.TextMuted, Color.gray); Color accent = theme.GetColor(NowColorToken.Accent, new Color(0.10f, 0.45f, 0.95f, 1f)); Color accentText = theme.GetColor(NowColorToken.AccentText, Color.white); float badgeSize = editorChrome ? 24f : 30f; using (NowLayout.Area(610001, rect, spacing: editorChrome ? 5f : 9f, padding: 0f, alignItems: NowLayoutAlign.Start)) { using (NowLayout.HorizontalScope(height: badgeSize, stretchWidth: true, alignItems: NowLayoutAlign.Center, spacing: editorChrome ? 7f : 9f)) { NowRect badge = NowLayout.ReserveRect(badgeSize, badgeSize); Now.Rectangle(badge) .SetColor(accent) .SetRadius(editorChrome ? 2f : 9f) .Draw(); DrawCenteredText(theme, badge, "N", editorChrome ? 12f : 16f, accentText, bold: true); using (NowLayout.VerticalScope(spacing: 0f, stretchWidth: true)) { NowLayout.Label("NowUI") .SetFontSize(editorChrome ? 13f : 15f) .SetHeight(editorChrome ? 14f : 17f) .SetBold() .SetColor(text) .Draw(); NowLayout.Label("Immediate-mode UI docs") .SetFontSize(editorChrome ? 9f : 10f) .SetHeight(editorChrome ? 10f : 13f) .SetColor(muted) .Draw(); } } NowLayout.TextField("docs-search") .SetPlaceholder("Search docs...") .SetHeight(editorChrome ? 18f : 20f) .SetStretchWidth() .Draw(ref _docsSearch); } } /// <summary>Draws a single string centered inside a rect, outside any layout group.</summary> static void DrawCenteredText(NowThemeAsset theme, NowRect rect, string value, float fontSize, Color color, bool bold = false) { theme.Text(rect, NowTextStyle.Body) .SetFontSize(fontSize) .SetColor(color) .SetBold(bold) .SetAlign(NowTextAlign.Center, NowTextVerticalAlign.Middle) .Draw(value); } void DrawDocsNavigation(NowThemeAsset theme, NowRect rect) { bool editorChrome = UsesUnityEditorChrome(theme); Vector4 contentPadding = editorChrome ? new Vector4(0f, 0f, 4f, 0f) : new Vector4(2f, 2f, 2f, 2f); using (NowLayout.Area(rect)) using (BeginDocsScroll("docs-menu")) using (NowLayout.VerticalScope(contentPadding, spacing: editorChrome ? 0f : 3f)) { bool drewAny = false; for (int i = 0; i < Navigation.Length; ++i) { var entry = Navigation[i]; if (entry.section) { if (!SectionHasVisiblePage(i)) continue; if (drewAny) NowLayout.Space(editorChrome ? 5f : 8f); DrawDocsNavSection(theme, entry); drewAny = true; continue; } if (!PageMatchesSearch(entry.pageIndex)) continue; DrawDocsNavPage(entry); drewAny = true; } if (!drewAny) { NowLayout.Space(8f); NowLayout.Label("No matching pages") .SetFontSize(12f) .SetBold() .SetColor(theme.GetColor(NowColorToken.Text, Color.white)) .Draw(); NowLayout.Label($"Nothing matches \"{_docsSearch.Trim()}\".") .SetFontSize(11f) .SetColor(theme.GetColor(NowColorToken.TextMuted, Color.gray)) .SetStretchWidth() .Draw(); } } } void DrawDocsNavSection(NowThemeAsset theme, NavEntry entry) { bool editorChrome = UsesUnityEditorChrome(theme); Color muted = theme.GetColor(NowColorToken.TextMuted, Color.gray); using (NowLayout.HorizontalScope(height: editorChrome ? 18f : 20f, stretchWidth: true, alignItems: NowLayoutAlign.Center, spacing: editorChrome ? 5f : 7f)) { if (!editorChrome) { NowLayout.Label(entry.icon) .SetFontSize(9f) .SetColor(Color.white) .Draw(); } NowLayout.Label(entry.title.ToUpperInvariant()) .SetFontSize(editorChrome ? 9f : 10f) .SetBold() .SetColor(muted) .Draw(); NowRect rule = NowLayout.ReserveRect(height: 1f, stretchWidth: true); Now.Rectangle(rule) .SetColor(muted.WithAlpha(0.16f)) .Draw(); } } void DrawDocsNavPage(NavEntry entry) { int pageIndex = Mathf.Clamp(entry.pageIndex, 0, Pages.Length - 1); var page = Pages[pageIndex]; bool selected = pageIndex == _selected; var theme = NowTheme.themeAsset; Color text = theme.GetColor(NowColorToken.Text, Color.white); Color muted = theme.GetColor(NowColorToken.TextMuted, Color.gray); Color accent = theme.GetColor(NowColorToken.Accent, new Color(0.10f, 0.45f, 0.95f, 1f)); Color accentText = theme.GetColor(NowColorToken.AccentText, Color.white); bool editorChrome = UsesUnityEditorChrome(theme); float rowHeight = editorChrome ? Mathf.Max(18f, theme.controlStyles.treeRowHeight) : 28f; NowRect rect = NowLayout.ReserveRect(height: rowHeight, stretchWidth: true); NowRect row = editorChrome ? rect : rect.Inset(1f, 0f); NowResolvedId id = NowControls.GetControlId($"doc-{pageIndex}"); var interaction = NowControls.Interact(id, row, out bool focused, out bool submitted); if (interaction.clicked || submitted) _selected = pageIndex; float hoverT = NowControlState.Transition(interaction, "hover", interaction.hovered || focused, 14f); Color editorHover = theme.GetColor(NowColorToken.SurfaceHover, new Color(0.32f, 0.32f, 0.32f, 1f)); editorHover.a *= hoverT; if (selected) { Now.Rectangle(row) .SetColor(editorChrome ? accent : theme.GetColor(NowColorToken.AccentMuted, accent.WithAlpha(0.18f))) .SetRadius(editorChrome ? 1f : 7f) .Draw(); if (!editorChrome) { Now.Rectangle(new NowRect(row.x + 3f, row.y + 7f, 3f, row.height - 14f)) .SetColor(accent) .SetRadius(1.5f) .Draw(); } } else if (hoverT > 0.004f) { Now.Rectangle(row) .SetColor(editorChrome ? editorHover : accent.WithAlpha(0.09f * hoverT)) .SetRadius(editorChrome ? 1f : 7f) .Draw(); } float indent = editorChrome ? 6f + entry.depth * 14f : 8f + entry.depth * 18f; float badgeX = row.x + indent; float centerY = row.y + row.height * 0.5f; if (!editorChrome && entry.depth > 0) { Color branch = muted.WithAlpha(selected ? 0.38f : 0.26f); float lineX = row.x + indent - 11f; Now.Line(new Vector2(lineX, row.y + 4f), new Vector2(lineX, row.yMax - 4f)) .SetColor(branch) .SetWidth(1f) .Draw(); Now.Line(new Vector2(lineX, centerY), new Vector2(badgeX - 4f, centerY)) .SetColor(branch) .SetWidth(1f) .Draw(); } NowRect titleRect; if (editorChrome) { titleRect = new NowRect(badgeX, row.y + 2f, row.xMax - badgeX - 5f, row.height - 3f); } else { var badgeRect = new NowRect(badgeX, row.y + 3f, 24f, 22f); Now.Text(badgeRect) .SetFontSize(14f) .SetColor(Color.white) .Draw(page.icon); titleRect = new NowRect(badgeRect.xMax + 8f, row.y + 5f, row.xMax - badgeRect.xMax - 14f, row.height - 8f); } var title = Now.Text(titleRect) .SetFontSize(editorChrome ? 11f : 12f) .SetColor(selected && editorChrome ? accentText : selected ? text : Color.Lerp(text, accentText, hoverT * 0.2f)); if (selected && !editorChrome) title = title.SetBold(); title.Draw(page.title); } bool SectionHasVisiblePage(int sectionIndex) { if (string.IsNullOrWhiteSpace(_docsSearch)) return true; for (int i = sectionIndex + 1; i < Navigation.Length; ++i) { var entry = Navigation[i]; if (entry.section) return false; if (PageMatchesSearch(entry.pageIndex)) return true; } return false; } bool PageMatchesSearch(int pageIndex) { if (string.IsNullOrWhiteSpace(_docsSearch)) return true; if (pageIndex < 0 || pageIndex >= Pages.Length) return false; string query = _docsSearch.Trim(); var page = Pages[pageIndex]; return ContainsSearch(page.title, query) || ContainsSearch(page.file, query); } static bool ContainsSearch(string value, string query) { return !string.IsNullOrEmpty(value) && value.IndexOf(query, System.StringComparison.OrdinalIgnoreCase) >= 0; } protected override void DrawNowUI(NowRect rect) { if (!_font) return; using var _ = NowTheme.Scope(_themeAsset); Now.defaultFont = _font; var theme = NowTheme.themeAsset; var bounds = new NowRect(0, 0, rect.width, rect.height); bool editorChrome = UsesUnityEditorChrome(theme); // Surface is the fill used by controls. A document canvas is a true // background; using Surface here turns Unity's native control gray into // a washed-out page-sized slab. Now.Rectangle(bounds) .SetColor(theme.GetColor(NowColorToken.Background, Color.black)) .Draw(); NowRect menuRect; NowRect menuInner; NowRect menuTitleRect; NowRect menuListRect; if (editorChrome) { float menuWidth = Mathf.Min(256f, Mathf.Max(196f, bounds.width * 0.34f)); menuRect = new NowRect(bounds.x, bounds.y, menuWidth, bounds.height); Now.Rectangle(menuRect) .SetColor(theme.GetColor(NowColorToken.SurfaceMuted, new Color(0.165f, 0.165f, 0.165f, 1f))) .Draw(); Now.Rectangle(new NowRect(menuRect.xMax - 1f, menuRect.y, 1f, menuRect.height)) .SetColor(theme.GetColor(NowColorToken.BorderStrong, Color.black)) .Draw(); menuInner = menuRect.Inset(8f); menuTitleRect = new NowRect(menuInner.x, menuInner.y, menuInner.width, 50f); menuListRect = new NowRect(menuInner.x, menuTitleRect.yMax + 8f, menuInner.width, menuInner.yMax - menuTitleRect.yMax - 8f); } else { menuRect = new NowRect(bounds.x + 12, bounds.y + 12, 292, bounds.height - 24); theme.Rectangle(menuRect, NowRectangleStyle.Elevated).Draw(); menuInner = menuRect.Inset(12f); menuTitleRect = new NowRect(menuInner.x, menuInner.y, menuInner.width, 76f); menuListRect = new NowRect(menuInner.x, menuTitleRect.yMax + 10f, menuInner.width, menuInner.yMax - menuTitleRect.yMax - 10f); } Color separator = theme.GetColor(NowColorToken.Border, Color.gray); Now.Rectangle(new NowRect(menuInner.x, menuTitleRect.yMax + (editorChrome ? 3f : 4f), menuInner.width, 1f)) .SetColor(editorChrome ? theme.GetColor(NowColorToken.BorderStrong, separator) : separator.WithAlpha(0.45f)) .Draw(); DrawDocsSidebarHeader(theme, menuTitleRect); DrawDocsNavigation(theme, menuListRect); float contentLeft = menuRect.xMax + (editorChrome ? 20f : 12f); float contentRight = 12f; float contentAvailable = bounds.xMax - contentLeft - contentRight; float scrollGutter = theme.controlStyles.scrollbarWidth + theme.controlStyles.scrollbarPadding; float scrollbarBreathing = editorChrome ? 4f : 0f; float contentWidth = Mathf.Max(1f, Mathf.Min( contentAvailable - scrollGutter - scrollbarBreathing, editorChrome ? 800f : 940f)); var contentRect = new NowRect( contentLeft, bounds.y + (editorChrome ? 14f : 12f), contentAvailable, bounds.height - (editorChrome ? 26f : 24f)); using (NowLayout.Area(contentRect)) using (BeginDocsScroll($"docs-scroll-{_selected}")) using (NowLayout.HorizontalScope( new Vector4(0f, 0f, scrollbarBreathing, 0f), stretchWidth: true)) { NowLayout.FlexibleSpace(); using (NowLayout.VerticalScope(width: contentWidth, spacing: 0f)) { DrawDocsBreadcrumb(theme); DrawDocsPageContent(theme); DrawDocsPager(theme); } NowLayout.FlexibleSpace(); } } NowScrollScope BeginDocsScroll(string id) { NowResolvedId resolved = NowControls.GetControlId(id); if (_forceHarnessScrollTop) { // Retained focus restoration can legitimately reveal a deep control // while the harness warms up. Captures need an explicit idle/top // invariant instead of inheriting that navigation behavior. NowFocus.Clear(); NowControlState.Get<Vector2>(resolved) = Vector2.zero; } NowScrollScope scroll = NowLayout.ScrollView(resolved).Begin(); if (_forceHarnessScrollTop) scroll.scrollOffset = Vector2.zero; return scroll; } void DrawDocsPageContent(NowThemeAsset theme) { switch (Pages[_selected].kind) { case PageKind.ControlsDemo: DrawLiveDemo(theme); break; case PageKind.ControlsGalleryDemo: DrawControlsGalleryDemo(theme); break; case PageKind.LottieDemo: DrawLottieDemo(theme); break; case PageKind.CodeEditorDemo: DrawCodeEditorDemo(); break; case PageKind.RichTextDemo: DrawRichTextDemo(theme); break; case PageKind.TextStylingDemo: DrawTextStylingDemo(theme); break; case PageKind.MarkupDemo: DrawMarkupDemo(theme); break; case PageKind.SdfDemo: DrawSdfDemo(theme); break; case PageKind.DockingDemo: DrawDockingDemo(theme); break; case PageKind.LinesDemo: DrawLinesDemo(theme); break; case PageKind.ShapesDemo: DrawShapesDemo(theme); break; case PageKind.CustomMaterialsDemo: DrawCustomMaterialsDemo(theme); break; case PageKind.GlassDemo: DrawGlassDemo(theme); break; case PageKind.EffectsDemo: DrawEffectsDemo(theme); break; case PageKind.ModelPreviewsDemo: DrawModelPreviewsDemo(theme); break; case PageKind.ViewStackDemo: DrawViewStackDemo(theme); break; case PageKind.FilePickerDemo: DrawFilePickerDemo(theme); break; default: var result = DocsMarkdown(LoadDoc(Pages[_selected].file)).Draw(); if (result.clickedLink != null) NavigateLink(result.clickedLink); |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |