简体   繁体   English

如何在容器重新缩放subMorph?

[英]How to rescale subMorph when the container does?

I am exploring Squeak, release 5.2 in MacOS. 我正在探索Squeak,在MacOS上发布5.2版本。

I am drawing lines (PolygonMorph) inside a RectangleMorph 'r'. 我在RectangleMorph'r'中绘制线条(PolygonMorph)。 When I translate 'r' the lines translate but when I rescale 'r' the lines do not rescale. 当我翻译'r'时,线条会转换,但是当我重新缩放'r'时,线条不会重新缩放。

Run the snipped below. 运行下面的剪辑。 Then with the Halo translate and resize the rectangle 'r'. 然后用Halo翻译并调整矩形'r'的大小。 You will see line 'p' get translated but not rescaled. 你会看到'p'行被翻译但没有重新缩放。

r := RectangleMorph new.
"[Pharo] r:= Morph.new."
r extent: 500@500.
r openInWindow. 

p := PolygonMorph 
        vertices: {(r left)@(r top). (r right)@(r bottom)}
        color: Color white borderWidth: 2 borderColor: Color white.

r addMorph: p.

How can I get 'p' to rescale ? 如何让'p'重新缩放?

bye 再见

This may not be the complete answer you are looking for, but sharing what I did, might help you to make some progress with your interesting problem. 这可能不是您正在寻找的完整答案,但分享我所做的,可能会帮助您在您的有趣问题上取得一些进展。

  1. I'm not a Squeak (or Pharo) user, so I downloaded Squeak from the web. 我不是Squeak(或Pharo)用户,所以我从网上下载了Squeak。
  2. Pasted your code in a Workspace and executed it. 将您的代码粘贴到Workspace中并执行它。
  3. Reproduced the behavior you observed: resizing the rectangle has no effect on its polygon sub-morph. 重现您观察到的行为:调整矩形大小对其多边形子变形没有影响。
  4. Popped up the rectangle menu and saw the 'add halo' item. 弹出矩形菜单,看到“添加光环”项。
  5. Wrote 'add halo' somewhere and right-clicked to bring all methods with that literal. 'add halo'某处写了'add halo'并右键单击以使用该文字带来所有方法。
  6. Found #addHalo: as the associated message to the menu item. 找到#addHalo:作为菜单项的关联消息。
  7. Inserted a halt to debug #addHalo: . 插入一个halt调试#addHalo: .
  8. Cmd+clicked to bring the halo and debugged until I found that the resize handle would send addGrow:with: to the morph. Cmd +点击带晕并调试,直到我发现调整大小句柄会发送addGrow:with:变形。
  9. Then I saw that addGrow:with: sends setExtentFromHalo: and that this sends extent: . 然后我看到addGrow:with:发送setExtentFromHalo:并且它发送了extent: .

My conclusion is that you would need a new subclass of RectangleMorph that resizes all its sub-morphs, proportionally, when it receives setExtentFromHalo: . 我的结论是你需要一个新的RectangleMorph子类,当它收到setExtentFromHalo:时,按比例调整所有子变形的大小。 Something on the lines of 有点像的东西

ScalableRectangleMorph >> #setExtentFromHalo: aPoint
  current := self extent.
  super setExtentFromHalo: aPoint.
  scale := self extent - current / current.
  self submorphsDo: [:m | m extent: (m extent * scale) rounded]

Give this a try (I haven't), and let us know how it went. 尝试一下(我没有),让我们知道它是怎么回事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM