首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gojs PanelExpanderButton自定义图标

Gojs PanelExpanderButton自定义图标
EN

Stack Overflow用户
提问于 2018-08-31 06:33:57
回答 1查看 741关注 0票数 0

在Gojs中,可以提供自定义图标吗?在我的例子中,我想使用SVG/PNG图像作为PanelExpanderButton图标。

代码语言:javascript
复制
go.GraphObject.defineBuilder("PanelExpanderButton", function(args) {
      var eltname = /** @type {string} */ (go.GraphObject.takeBuilderArgument(args, "COLLAPSIBLE"));

      var button = /** @type {Panel} */ (
        $("Button",
          { // set these values for the visible binding conversion
            "_buttonExpandedFigure": $(go.Picture, {
                // desiredSize: new go.Size(10, 10),
                source: "assets/images/expand.png"
              },
            ),
            "_buttonCollapsedFigure": $(go.Picture, {
                // desiredSize: new go.Size(10, 10),
                source: "assets/images/collapse.png"
              },
            )
          },
          $(go.Picture, { source: "assets/images/expand.png", desiredSize: new go.Size(10, 10) },
            new go.Binding("figure", "visible", function(vis) { return vis ? button["_buttonExpandedFigure"] : button["_buttonCollapsedFigure"]; })
            .ofObject(eltname)
          )
        )
      );

      var border = button.findObject("ButtonBorder");
      if (border instanceof go.Shape) {
        border.stroke = null;
        border.fill = "transparent";
      }

      button.click = function(e, button) {
        var diagram = button.diagram;
        if (diagram === null) return;
        if (diagram.isReadOnly) return;
        var elt = button.findTemplateBinder();
        if (elt === null) elt = button.part;
        if (elt !== null) {
          var pan = elt.findObject(eltname);
          if (pan !== null) {
            diagram.startTransaction('Collapse/Expand Panel');
            pan.visible = !pan.visible;
            diagram.commitTransaction('Collapse/Expand Panel');
          }
        }
      }

      return button;
    });

当面板展开/折叠时,我无法更改图标

在这里,我试着用这张照片,但没有成功

编码愉快!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-31 15:00:45

“图形”必须是Shape.defineFigureGenerator定义的名称之一,包括库中预定义的所有图形名称。因此,不能以这种方式使用Picture

但是您可以复制和修改"PanelExpanderButton“的定义,这是在https://gojs.net/latest/extensions/Buttons.js中提供的。通过这种方式,您可以对其进行大小调整,并为其状态提供任意形状。如果您想使用SVG,请注意特定于平台的限制:https://gojs.net/latest/intro/pictures.html#UsingSVGAsPictureSource

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52109740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档