使用默认实例化形状扩展 dojo.gfx.Group

发布于 2024-08-14 21:33:38 字数 1120 浏览 3 评论 0原文

我正在尝试使用 dojo.gfx 创建一些简单的 UI 组件。我已经成功地扩展了 dojo.gfx.Group,但无法将任何默认形状绘制到表面。在 Firebug 中检查渲染的 SVG,确实有一个节点,但没有矩形。

简化的类如下所示:

dojo.provide("gfxui.SimpleButton");

dojo.require("dojox.gfx.shape");//-¿ needed?
dojo.require("dojox.gfx.svg");
dojo.require("dojox.gfx._base");

dojo.declare("gfxui.SimpleButton", dojox.gfx.Group, {
    constructor: function(){
        this.draw();
    },
    draw:function(){
        var bg = this.createRect(this.rect_props);
        //var bg = this.createObject(dojox.gfx.Rect);
    }
}

gfxui.SimpleButton.nodeType = dojox.gfx.Group.nodeType;

dojo.extend(dojox.gfx.Surface, {
    createButton: function(){
        var button = this.createObject(gfxui.SimpleButton, null, true);
        this.add(button);
        return button;
    }
});

HTML 中的 javascript 如下所示:

dojo.require("dojox.gfx");
dojo.require("gfxui.SimpleButton");

function init(){
    var g = dojox.gfx;
    var surface = dojox.gfx.createSurface(dojo.byId("gfx_holder"), 800, 280, "#eee");
    var button = container.createButton();
};
dojo.addOnLoad(init);

I'm attempting to create some simple UI components with dojo.gfx. I've managed to extend dojo.gfx.Group, but am out of my depth getting any of the default shapes drawn to the surface. Inspecting the rendered SVG in Firebug, there's rightfully a node but no rect.

The simplified class looks like this:

dojo.provide("gfxui.SimpleButton");

dojo.require("dojox.gfx.shape");//-¿ needed?
dojo.require("dojox.gfx.svg");
dojo.require("dojox.gfx._base");

dojo.declare("gfxui.SimpleButton", dojox.gfx.Group, {
    constructor: function(){
        this.draw();
    },
    draw:function(){
        var bg = this.createRect(this.rect_props);
        //var bg = this.createObject(dojox.gfx.Rect);
    }
}

gfxui.SimpleButton.nodeType = dojox.gfx.Group.nodeType;

dojo.extend(dojox.gfx.Surface, {
    createButton: function(){
        var button = this.createObject(gfxui.SimpleButton, null, true);
        this.add(button);
        return button;
    }
});

And the javascript in the HTML looks like this:

dojo.require("dojox.gfx");
dojo.require("gfxui.SimpleButton");

function init(){
    var g = dojox.gfx;
    var surface = dojox.gfx.createSurface(dojo.byId("gfx_holder"), 800, 280, "#eee");
    var button = container.createButton();
};
dojo.addOnLoad(init);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

却一份温柔 2024-08-21 21:33:38

我更喜欢简单的增强技术。下面是 script 标签的内容:

// let's include gfx (renderer will be selected dynamically)
dojo.require("dojox.gfx");

// useful short names
var d = dojo, g = dojox.gfx;

// our creator function
function createButton(color){
  // let's create our main shape: group
  var group = this.createGroup();
  // add custom properties, if any
  group._rect = group.createRect().
    setShape({x: 5, y: 5, width: 100, height: 30}).
    setStroke("black").
    setFill(color);
  return group;
}

// we want it to be available on groups and surfaces
d.extend(g.Surface, {createButton: createButton});
d.extend(g.Group,   {createButton: createButton});

// let's test the result
dojo.addOnLoad(function(){
  var s = g.createSurface(dojo.byId("surface"), 500, 400),
      b = s.createButton("red");
});

上面的示例假设有一个名为“surface”的

增强技术适用于任何渲染器,无论其实现如何,并且仅使用已发布的 API。

I prefer a simple augmentation technique. Below is the content of a script tag:

// let's include gfx (renderer will be selected dynamically)
dojo.require("dojox.gfx");

// useful short names
var d = dojo, g = dojox.gfx;

// our creator function
function createButton(color){
  // let's create our main shape: group
  var group = this.createGroup();
  // add custom properties, if any
  group._rect = group.createRect().
    setShape({x: 5, y: 5, width: 100, height: 30}).
    setStroke("black").
    setFill(color);
  return group;
}

// we want it to be available on groups and surfaces
d.extend(g.Surface, {createButton: createButton});
d.extend(g.Group,   {createButton: createButton});

// let's test the result
dojo.addOnLoad(function(){
  var s = g.createSurface(dojo.byId("surface"), 500, 400),
      b = s.createButton("red");
});

The example above assumes that there is a <div> called "surface".

The augmentation technique works for any renderer regardless its implementation, and uses only published APIs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文