视口如何在 Juce 中工作?
How viewport Works In Juce?
谁能解释一下视口在 JUCE 框架中的工作原理。我在论坛上找到了一个讨论,但我无法理解分层组件。我很困惑,请用一个简单的例子来解释我。
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
),其中将包含其他组件。就拿图片(content component)和Picture frame(Viewport)来类比
谁能解释一下视口在 JUCE 框架中的工作原理。我在论坛上找到了一个讨论,但我无法理解分层组件。我很困惑,请用一个简单的例子来解释我。
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
),其中将包含其他组件。就拿图片(content component)和Picture frame(Viewport)来类比