如何让一个元素占据所有剩余宽度?

发布于 2024-08-01 17:50:28 字数 327 浏览 4 评论 0原文

Shoes.app do
  flow do
    file = "something with variable length"
    para "Loading #{file}: "
    progress :width => -300
  end
end

正如您从代码中看到的,我试图显示一个从文本末尾一直到应用程序窗口右边缘的进度条。 当文本具有固定长度时,此解决方案有效,但一旦文本在上面的片段中改变长度,它就不起作用:进度条的空间太小或太多。

这个问题有解决办法吗?

我尝试询问 para 元素的宽度,但它是 0???

Shoes.app do
  flow do
    file = "something with variable length"
    para "Loading #{file}: "
    progress :width => -300
  end
end

As you can see from the code I am trying to display a progress bar that goes from the end of the text until the right edge of the application window.
When the text has a fixed length this solution works but it doesn't once the text changes length in the above fragment: there will be either too little or too much space for the progress bar.

Is there a solution to this problem?

I tried asking the para element it's width but it is 0???

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

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

发布评论

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

评论(1

世俗缘 2024-08-08 17:50:28

正如我之前提到的,您必须获取文本块的宽度计算出来之后。 尝试这个:

Shoes.app do
  flow do
    file = "something with variable length"
    @p = para "Loading #{file}: "
    @prog = progress
    start do
      @prog.width = @prog.parent.width - @p.width
    end
  end
  button 'Change text!' do
    text = @p.text
    @p.text = text + '1'
    @prog.width = @prog.parent.width - @p.width    
  end
end

As I mentioned before, you have to get the width of the textblock after it is calculated. Try this:

Shoes.app do
  flow do
    file = "something with variable length"
    @p = para "Loading #{file}: "
    @prog = progress
    start do
      @prog.width = @prog.parent.width - @p.width
    end
  end
  button 'Change text!' do
    text = @p.text
    @p.text = text + '1'
    @prog.width = @prog.parent.width - @p.width    
  end
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文