Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViewSequence 核心說明 #8

Open
hinablue opened this issue May 8, 2014 · 0 comments
Open

ViewSequence 核心說明 #8

hinablue opened this issue May 8, 2014 · 0 comments

Comments

@hinablue
Copy link
Owner

hinablue commented May 8, 2014

#2 有提到了 View 核心,延伸的核心模組還有 ViewSequence 這個部分,不過目的不同。

ViewSequence 核心

他是用來儲存一個序列化資料的模組,所以雖然字面上是 ViewSequence,但是骨子裡跟 View 沒有關係。

初始化方法

這個模組初始化可以傳入這幾個數值(使用 Object 的方式傳入,

  • array 傳入一個陣列,這個陣列用來儲存你的物件。
  • index 定義第一個元素,這個模組用這個元素來當作第一個被 render 的物件
  • loop 當巡迴過整個陣列之後,決定是否要返回第一個(或最後一個)元素
  • firstNode 第一個元素
  • lastNode 最後一個元素

這個模組建立後,裡面會再建立一個結構函示,名稱雖為 Backing,不過外部使用時,是用 _ 來取得。

模組方法

  • getValue(n) 取得第 n 個物件
  • setValue(n, value) 將第 n 個物件設定為 value
  • reindex(start, removeCount, insertCount) 重新定義索引值
  • getPrevious 取得目前索引值的上一個物件
  • getNext 取得目前索引值的下一個物件
  • getIndex 取得當前的索引值
  • toString 將目前索引值輸出為字串
  • unshift(value) 從開頭新增一個物件
  • push(value) 從尾端新增一個物件
  • splice(index, howMany) 從第 index 物件開始切割,然後移除掉 howMany 個物件
  • swap(other) 交換物件位置,與模組設定中的 .index 物件交換位置
  • getSize 取得該 .index 物件的尺寸

簡易操作

  var surf1 = new Surface({
    size: [120, 100],
    properties: {
      backgroundColor: 'black'
    }
  });
  var surf2 = new Surface({
    size: [130, 100],
    properties: {
      backgroundColor: 'black'
    }
  });
  var surf3 = new Surface({
    size: [140, 100],
    properties: {
      backgroundColor: 'red'
    }
  });
  var surf4 = new Surface({
    size: [150, 100],
    properties: {
      backgroundColor: 'black'
    }
  });

  var views = new ViewSequence({
    array: [surf1, surf2, surf3, surf4],
    index: 2
  });

  var mainCtx = Engine.createContext();

  mainCtx.add(views.getNext());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant