コード例 #1
0
            // assume image's format is fixed
            private static Widget ProcessImage(Token token, BuilderContext ctx)
            {
                var imageName = token.attrs.Single(attr => attr[0] == "src")[1];
                var version   = DocApp.of(ctx.Context).version;
                var url       =
                    $"{Configuration.Instance.cdnPrefix}/{version.unity_version}/{version.parse_version}/manual/static/{imageName.Replace('-', '_')}";

                var widgets = new List <Widget>
                {
                    new ImageWithPlaceholder(
                        ctx.ImageMetas[imageName].width,
                        ctx.ImageMetas[imageName].height,
                        new NetworkImage(url)
                        ),
                };

                if (token.children != null &&
                    token.children.Count == 1 &&
                    token.children[0].type == "text")
                {
                    widgets.Add(
                        new Container(
                            margin: EdgeInsets.only(top: 8.0f),
                            child: new SelectableText(
                                token.children[0].content,
                                style: new TextStyle(
                                    color: new Color(0xff9b9b9b),
                                    fontFamily: "PingFang"
                                    )
                                )
                            )
                        );
                }

                ctx.ImageNode = new Container(
                    margin: EdgeInsets.only(top: 16.0f),
                    child: new Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: widgets
                        )
                    );

                return(null);
            }
コード例 #2
0
            private void Load()
            {
                _loading = true;
                var version = DocApp.of(context).version;
                var url     =
                    $"{Configuration.Instance.cdnPrefix}/{version.unity_version}/{version.parse_version}/manual/json/{widget._title.Replace('-', '_')}.json";
                var request        = UnityWebRequest.Get(url);
                var asyncOperation = request.SendWebRequest();

                asyncOperation.completed += operation =>
                {
                    if (!mounted)
                    {
                        return;
                    }

                    using (WindowProvider.of(context).getScope())
                    {
                        if (request.responseCode == 404)
                        {
                            DocApp.of(context).ForceUnknown();
                        }
                        else
                        {
                            var content = DownloadHandlerBuffer.GetContent(request);
                            var model   = ManualModel.FromJson(JsonValue.Parse(content));
                            setState(() =>
                            {
                                _tokens      = model.tokens;
                                _prevLink    = model.prev;
                                _nextLink    = model.next;
                                _breadcrumbs = model.bread_crumb;
                                _imageMetas  = model.image_meta;
                                _loading     = false;
                            });
                        }
                    }
                };
            }
コード例 #3
0
            public override void initState()
            {
                base.initState();

                _currentLastSegment = LastSegment(ObservableUtil.currentPath.value);
                ObservableUtil.currentPath.OnChanged += OnPathChanged;

                var version        = DocApp.of(context).version;
                var request        = UnityWebRequest.Get($"{Configuration.Instance.cdnPrefix}/{version.unity_version}/{version.parse_version}/{widget._type.TocFileName()}");
                var asyncOperation = request.SendWebRequest();

                asyncOperation.completed += operation =>
                {
                    if (!mounted)
                    {
                        return;
                    }
                    var content = DownloadHandlerBuffer.GetContent(request);
                    using (WindowProvider.of(context).getScope())
                    {
                        setState(() => _menu = Models.Json.Menu.FromJson(JsonValue.Parse(content)));
                    }
                };
            }
コード例 #4
0
            private Widget BuildTextUsingMixedContent(
                BuildContext context,
                IEnumerable <MixedContent> summary)
            {
                if (summary is null)
                {
                    return(new Container());
                }

                var version = DocApp.of(context).version;

                return(new SelectableWealthyText(
                           textSpanList: summary.Select(item =>
                {
                    switch (item)
                    {
                    case DocumentCharData charData:
                        return new TextSpan(charData.content);

                    case DocumentTagLink link:
                        return new TextSpan(
                            link.content,
                            style: HyperLinkStyle,
                            recognizer: new TapGestureRecognizer
                        {
                            onTap = () => LocationUtil.Go(link.@ref),
                        }
                            );

                    case DocumentTagBreak br:
                        return new TextSpan("\n");

                    case DocumentTagBold bold:
                        return new TextSpan(
                            bold.content,
                            style: new TextStyle(
                                fontWeight: FontWeight.w500
                                )
                            );

                    case DocumentTagImage image:
                        var networkImage =
                            new NetworkImage(
                                $"{Configuration.Instance.cdnPrefix}/{version.unity_version}/{version.parse_version}/scripting/static/{image.name.Replace('-', '_')}");
                        networkImage.resolve(new ImageConfiguration());
                        return new ImageSpan(
                            networkImage,
                            margin: EdgeInsets.symmetric(vertical: 16f),
                            imageWidth: _imageMetas[image.name].width,
                            imageHeight: _imageMetas[image.name].height
                            );

                    case DocumentTagItalic italic:
                        return new TextSpan(
                            italic.content,
                            style: new TextStyle(
                                fontStyle: FontStyle.italic
                                )
                            );
                    }

                    return null;
                }).Where(span => span != null).ToList(),
                           style: NormalTextStyle
                           ));
            }
コード例 #5
0
            public override Widget build(BuildContext buildContext)
            {
                if (_loading)
                {
                    return(new Container(
                               child: new Center(
                                   child: new Loading(
                                       size: 48f
                                       )
                                   )
                               ));
                }

                var markdownBuildCtx = new BuilderContext(_imageMetas, buildContext);

                _spanRecognizers?.ForEach(recognizer => recognizer.dispose());

                var widgets = new List <Widget>();

                widgets.AddRange(_tokens
                                 .Where(token => Mappings.ContainsKey(token.type))
                                 .Select(token => Mappings[token.type].Invoke(token, markdownBuildCtx))
                                 .Where(w => !(w is null))
                                 .Select(w => new RepaintBoundary(child: w)));
                _spanRecognizers = markdownBuildCtx.SpanRecognizers;

                widgets.Insert(0,
                               new Container(
                                   height: 64f,
                                   padding: EdgeInsets.only(bottom: 8f),
                                   decoration: new BoxDecoration(
                                       border: new Border(
                                           bottom: new BorderSide(
                                               color: new Color(0xffd8d8d8),
                                               width: 1f
                                               )
                                           )
                                       ),
                                   child: new Align(
                                       alignment: Alignment.bottomLeft,
                                       child: new Breadcrumbs(
                                           _breadcrumbs,
                                           normalBreadcrumbStyle: new TextStyle(
                                               fontSize: 16f,
                                               color: new Color(0xff979797)
                                               ),
                                           hoverBreadCrumbStyle: new TextStyle(
                                               fontSize: 16f,
                                               color: new Color(0xff979797),
                                               decoration: TextDecoration.underline
                                               ),
                                           splitterStyle: new TextStyle(
                                               fontSize: 16f,
                                               color: new Color(0xff979797)
                                               )
                                           )
                                       )
                                   )
                               );

                var linkButtons = new List <Widget>();

                if (_prevLink != null)
                {
                    linkButtons.Add(
                        new Expanded(
                            child: new Container(
                                margin: EdgeInsets.only(right: 20),
                                child: new Button(
                                    text: _prevLink.content ?? "",
                                    onTap: () =>
                    {
                        if (!string.IsNullOrEmpty(_prevLink?.link))
                        {
                            LocationUtil.Go(
                                $"/Manual/{_prevLink?.link}");
                        }
                    },
                                    prefix: Icons.MaterialArrowBack
                                    )
                                )
                            )
                        );
                }
                else
                {
                    linkButtons.Add(
                        new Expanded(
                            flex: 1,
                            child: new Container()
                            )
                        ); // placeholder to use spaceBetween
                }

                if (_nextLink != null)
                {
                    linkButtons.Add(
                        new Expanded(
                            child: new Container(
                                margin: EdgeInsets.only(left: 20),
                                child: new Button(
                                    text: _nextLink.content ?? "",
                                    onTap: () =>
                    {
                        if (!string.IsNullOrEmpty(_nextLink.link))
                        {
                            LocationUtil.Go(
                                $"/Manual/{_nextLink.link}");
                        }
                    },
                                    suffix: Icons.MaterialArrowForward
                                    )
                                )
                            )
                        );
                }
                else
                {
                    linkButtons.Add(
                        new Expanded(
                            flex: 1,
                            child: new Container()
                            )
                        ); // placeholder to use spaceBetween
                }


                widgets.Add(
                    new Container(
                        margin: EdgeInsets.only(top: 32, bottom: 64),
                        child: new Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: linkButtons
                            )
                        )
                    );

                var version = DocApp.of(buildContext).version;

                return(new Row(
                           crossAxisAlignment: CrossAxisAlignment.start,
                           children: new List <Widget>
                {
                    new Expanded(
                        child: new Stack(
                            children: new List <Widget>
                    {
                        new Scroller(
                            child: new SingleChildScrollView(
                                controller: _scrollController,
                                child: new ScrollableOverlay(
                                    child: new Column(
                                        children: new List <Widget>
                        {
                            new Container(
                                constraints: new BoxConstraints(
                                    minHeight: MediaQuery.of(buildContext).size.height -
                                    Header.Height -
                                    SearchBar.Height -
                                    Footer.Height
                                    ),
                                child: new Column(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: widgets)
                                ),
                            new Footer(style: Footer.Light, showSocials: false)
                        }
                                        )
                                    )
                                )
                            ),
                        new ToTop(_scrollController, displayThreshold: 128f)
                    }
                            )
                        ),

                    new MetaFields(
                        markdownBuildCtx.PositionRecords,
                        _scrollController
                        )
                }
                           ));
            }