2017-06-16 32 views
0

任何人都可以請我解釋一下JUCE框架中的視口是如何工作的。我在論壇上發現了一個討論,但我無法理解分層組件。我很困惑,請用一個簡單的例子來解釋我。視窗如何在Juce中工作?

回答

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. 

視口僅僅是一個滾動條組件。滾動條不會顯示內容組件的大小是否爲< =與Viewport的大小(無論如何顯示滾動條無關)

注:視口只能有1個組件(示例中爲contentComponentViewport),它將包含其他組件。它像一個圖片(內容組件)和圖片幀(視口)作爲類比

閱讀此也:https://www.juce.com/doc/classViewport