【问题标题】:Pharo Smalltalk customizing font sizes, styles and backgroundsPharo Smalltalk 自定义字体大小、样式和背景
【发布时间】:2015-07-24 00:43:42
【问题描述】:

基本上我有 2 个问题,我正在尝试使用 Pharo 4.0 Smalltalk 编写一个简单的 GUI。我无法为我的标签或文本区域/按钮更改 pharo 中的字体大小/样式。我也无法更改它们的背景颜色和边框宽度。我已经尝试了所有方法:

font1 := (TextFontReference toFont: 
                (StrikeFont familyName: 'Atlanta' size: 22)).
TextMorph  new contents: ('test' asText addAttribute: font1); 
color: Color blue; 
autoFit: true; 
borderColor: Color green; 
borderWidth: 2.

SimpleButtonMorph new target: self;
label: 'test1';
actionSelector: #test1click; 
basicBorderColor: Color green; 
basicBorderWidth: 2; 
highlightColor: Color green.

TextMorph  new contents: 'test2'; 
color: Color blue; 
autoFit: true; 
borderColor: Color green; 
borderWidth: 2; 
font:'Atlanta' / fontName: 'Atlanta' pointSize: 22 / fontName: 'Arial' size: 32.

以上选项均无效。基本上我需要为按钮和标签自定义字体和背景。我该怎么办?

【问题讨论】:

  • 能否请您将代码示例更明确一些?你尝试了什么,你期待什么结果却没有成功?

标签: smalltalk pharo morphic


【解决方案1】:

至于背景颜色和边框宽度,只要添加 openInWorld 就可以了。

SimpleButtonMorph new target: self;
label: 'test1';
actionSelector: #test1click; 
basicBorderColor: Color green; 
basicBorderWidth: 2; 
highlightColor: Color green;
openInWorld 

【讨论】:

    【解决方案2】:

    颜色应该是 TextMorph 中的文本属性 (TextColor),字体不是文本属性(参见 Text 的类侧)。 Atlanta 是 StrikeFont 还是 truetype? StrikeFonts 是旧的位图字体。对于一些显示自定义颜色、字体和边框的简单代码,您可能需要从配置浏览器加载 CardsMorphic

    【讨论】:

      猜你喜欢
      • 2020-02-29
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多