Shoes: Element.width return 0

馋奶兔 提交于 2019-12-11 06:36:39

问题


I don't understand why the width function is implemented on all elements if it returns 0 for non-zero width elements. The following returns 0 for me.

Shoes.app do
  p = para "My width is: "
  para p.width
end

Why is that? (app.width does not return 0)


回答1:


The problem is that the size of the para object is determined dynamically when it is drawn. At the time you create the second para, nothing has actually been laid out yet, so a width hasn't been set. You can see that accessing the width after drawing works as expected:

Shoes.app do
  p = para "My width is: "
  @para = para p.width
  button 'Get Width' do
    @para.text = p.width
  end
end

The way to get around this is to use the start method, which is called when the containing slot is drawn for the first time:

Shoes.app do
  p = para "My width is: "
  width = para p.width
  start do
    width.text = p.width
  end
end


来源:https://stackoverflow.com/questions/1293318/shoes-element-width-return-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!