【问题标题】:Modify GridLayout in famo.us在 famo.us 中修改 GridLayout
【发布时间】:2014-04-27 09:47:37
【问题描述】:

我想将每个网格修改为我自己的内容。我的问题是如何修改网格以显示单个表面?例如,而不是数组项只有surface1、surface2、surface3 等。

var Engine = require('famous/core/Engine');
var Surface = require('famous/core/Surface');
var HeaderFooterLayout = require("famous/views/HeaderFooterLayout");
var GridLayout = require("famous/views/GridLayout");

var mainContext = Engine.createContext();

var layout;

createLayout();
addHeader();
addContent();
addFooter();

    function createLayout() {
      layout = new HeaderFooterLayout({
        headerSize: 100,
        footerSize: 50
      });

      mainContext.add(layout);
    }

    function addHeader() {
      layout.header.add(new Surface({
        content: "Header",
        classes: ["grey-bg"],
        properties: {
          lineHeight: "100px",
          textAlign: "center"
        }
      }));
    }

    function addContent() {
      layout.content.add(createGrid( 'content', [2, 1] ));
    }

    function addFooter() {
      layout.footer.add(createGrid( 'footer', [3, 1] ));
    }

    function createGrid( section, dimensions ) {
      var grid = new GridLayout({
        dimensions: dimensions
      });

      var surfaces = [];
      grid.sequenceFrom(surfaces);

      for(var i = 0; i < dimensions[0]; i++) {
        surfaces.push(new Surface({
          content: section + ' ' + (i + 1),
          size: [undefined, undefined],
          properties: {
            backgroundColor: "hsl(" + (i * 360 / 8) + ", 100%, 50%)",
            color: "#404040",
            textAlign: 'center'
          }
        }));
      }

      return grid;
    }

【问题讨论】:

    标签: famo.us


    【解决方案1】:

    您将始终需要表面数组才能使用通用 GridLayout 类。我可能遗漏了一些东西,但您似乎只是不想使用循环并单独定义表面。

    var Engine = require('famous/core/Engine');
    var Surface = require('famous/core/Surface');
    var HeaderFooterLayout = require("famous/views/HeaderFooterLayout");
    var GridLayout = require("famous/views/GridLayout");
    
    var mainContext = Engine.createContext();
    
    var layout;
    var surface1;
    var surface2;
    
    createLayout();
    addHeader();
    addContent();
    addFooter();
    
    function createLayout() {
      layout = new HeaderFooterLayout({
        headerSize: 100,
        footerSize: 50
      });
    
      mainContext.add(layout);
    }
    
    function addHeader() {
      layout.header.add(new Surface({
        content: "Header",
        classes: ["grey-bg"],
        properties: {
          lineHeight: "100px",
          textAlign: "center"
        }
      }));
    }
    
    function addContent() {
      layout.content.add(createGrid( 'content', [2, 1] ));
    }
    
    function addFooter() {
      layout.footer.add(createGrid( 'footer', [3, 1] ));
    }
    
    function createGrid( section, dimensions ) {
      var grid = new GridLayout({
        dimensions: dimensions
      });
    
      var surfaces = [];
      grid.sequenceFrom(surfaces);
    
    
      surface1 = new Surface({
          content: "surface 1 content",
          size: [undefined, undefined],
          properties: {
            backgroundColor: "hsl(" + (i * 360 / 8) + ", 100%, 50%)",
            color: "#404040",
            textAlign: 'center'
          }
       });
    
      surfaces.push(surface1);
    
      surface2 = new Surface({
          content: "surface 2 content",
          size: [undefined, undefined],
          properties: {
            backgroundColor: "hsl(" + (i * 360 / 8) + ", 100%, 50%)",
            color: "#404040",
            textAlign: 'center'
          }
       });
    
      surfaces.push(surface2);
    
      // etc
    
      return grid;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多