0

谁能解释一下视口在 JUCE 框架中是如何工作的。我在论坛上找到了一个讨论,但我无法理解分层组件。我很困惑,请用一个简单的例子来解释我。

4

1 回答 1

2

JUCE 中的视口与游戏中的任何其他视口一样。API中的细节很清楚

这个怎么运作:

您必须为其添加一个组件,该组件将充当其包含其他组件的内容组件。它必须大于视口,否则会破坏视口的用途。之后,您将能够滚动内容组件。

例子:

Component contentComponentOfViewport = new Component();
contentComponentOfViewport.addAndMakeVisible(registerButton);
contentComponentOfViewport.addAndMakeVisible(loginButton);
contentComponentOfViewport.addAndMakeVisible(usernameTextfield);
contentComponentOfViewport.addAndMakeVisible(passwordTextfield);

contentComponent.setSize(viewportObject.getWidth() + 1, viewportObject.getHeight() + 1); // with this size you will be able to scroll around with 1x1 pixel offset

viewportObject.setViewedComponent(contentComponentOfViewport); // set it to the viewportObject so it will become scrollable now which is the role of the viewport.

视口只是一个带有滚动条的组件。如果内容组件的大小 <= 到视口的大小,则滚动条不会显示(无论如何显示滚动条都没有意义)

注意:视口只能有 1 个组件(contentComponentViewport在示例中),它将包含其他组件。它就像一个图片(内容组件)和图片框架(视口)一样的类比

另请阅读: https ://www.juce.com/doc/classViewport

于 2017-08-08T07:31:16.517 回答