视口如何在Juce中运行?

时间:2017-06-16 22:40:17

标签: graphics juce

任何人都可以解释一下视口在JUCE框架中的工作原理。我在论坛上发现了一个讨论,但我在分层组件中无法理解。我很困惑,请用一个简单的例子解释我。

1 个答案:

答案 0 :(得分:2)

JUCE中的视口就像游戏中的任何其他视口一样。 API中的详细信息是明确的

它如何运作:

您必须向其中放置一个组件,该组件将充当其包含其他组件的内容组件。它必须大于Viewport,否则会破坏Viewport的目的。之后,您将能够滚动内容组件。

示例:

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.

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

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

也请阅读此内容: https://www.juce.com/doc/classViewport