【问题标题】:Setting default font for Shoes elements?为鞋子元素设置默认字体?
【发布时间】:2014-02-25 19:10:54
【问题描述】:

我有以下代码:

Shoes.app title: "Add a person to database" do  
  stack do

    title "Create a new person" 
    para "Enter their name:", :font => "MS UI Gothic"
        @name = edit_line
    para "Enter their age:", :font => "MS UI Gothic"
        @age = edit_line
    para "Enter their address:",:font => "MS UI Gothic"
        @address = edit_line
    para "Enter their mobile number:", :font => "MS UI Gothic"
        @mob_number = edit_line
    para "Enter their home number:", :font => "MS UI Gothic"
        @home_number = edit_line

    button "Add person to database" do
        Person.new(@name, @age, @address, @mob_number, @home_number)
        para newperson.details
    end
  end
end

我不想将每个元素的字体样式设置为“MS UI Gothic”,而是希望将应用程序中出现的所有文本的默认字体设置为 MS UI Gothic。我无法从我找到的任何教程中弄清楚如何做到这一点。有什么建议吗?

【问题讨论】:

  • 我在他们的文档中也找不到关于全局样式的任何内容。奇怪,我希望会有这样的东西出现。至少您可以使用变量para_style = { font: "MS UI Gothic" } 并将其传递给每个段落。至少这使您可以集中样式定义,并仅在 1 个位置进行更改。不过,仍然是穷人的“解决方案”。

标签: ruby fonts styles shoes


【解决方案1】:

这取决于您使用的是 Shoes3 还是 Shoes4。

在 Shoes3 中,您可以将 style Para, font: "MS UI Gothic" 放在 Shoes.app 块中的任何位置。它会为应用程序中的所有段落设置该样式。

Shoes.app title: "Add a person to database" do  
  style Para, font: "MS UI Gothic"
  stack do

    title "Create a new person" 
    para "Enter their name:"
    @name = edit_line
    para "Enter their age:"
    @age = edit_line
    para "Enter their address:"
    @address = edit_line
    para "Enter their mobile number:"
    @mob_number = edit_line
    para "Enter their home number:"
    @home_number = edit_line

    button "Add person to database" do
      Person.new(@name, @age, @address, @mob_number, @home_number)
      para newperson.details
    end
  end
end

由于 Shoes4 位于新的 Ruby (1.9+) 中,因此您需要编写 style Shoes::Para, font: "MS UI Gothic" 代替。

有关 Shoes3 和 4 在此主题上的差异的更多信息,请查看 github 上的对话:https://github.com/shoes/shoes4/pull/460。

【讨论】:

  • 仅供参考,Shoes 4 中的字体支持还没有完全到位。
  • 我使用的是 Shoes 3.2,但我必须通过 style Shoes::Para, font: "MS UI Gothic" 设置字体。我在 Arch Linux x86_64 上。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多