다음은 비율에 따라보기의 크기를 조정하는 방법을 보여주는 예제 코드입니다. 비율은 unscaledwidth 및 unscaledheight 속성에 의해 정의됩니다. 최소 너비 또는 최소 높이에 대한 구현은 없지만 필요한 경우 추가 할 수 있습니다.
이 방법의 단점은 모든 리소스가 확장된다는 것입니다. SWF 런타임에서 기본 구성 요소의 리소스는 벡터 기반이며, DHTML 런타임에서는 PNG 파일로 변환되며 크기가 조정되면 매우 선명하지 않습니다. 나는 일반적으로 기존의 오픈 라즐로 구성 요소를 확장하지 않는 게 좋을,하지만 그건 당신의 결정입니다 :
<canvas width="100%" height="100%">
<!-- OpenLaszlo scaled view example by Raju Bitter -->
<class name="scaledview">
<attribute name="unscaledwidth" type="number" value="400"/>
<attribute name="unscaledheight" type="number" value="300"/>
<attribute name="wratio" type="number" value="${this.unscaledwidth/this.unscaledheight}"/>
<handler name="oninit">
this.setAttribute("width", this.unscaledwidth)
this.setAttribute("height", this.unscaledheight)
this._setSize();
</handler>
<handler name="onwidth" reference="canvas">
this._setSize();
</handler>
<handler name="onheight" reference="canvas">
this._setSize();
</handler>
<method name="_setSize">
var scale = 1.0;
if (canvas.width/canvas.height > this.wratio) {
scale = canvas.height/this.unscaledheight;
this.setAttribute("x", Math.round((canvas.width-this.width*scale)/2));
this.setAttribute("y", 0);
} else {
scale = canvas.width/this.unscaledwidth;
this.setAttribute("x", 0);
this.setAttribute("y", Math.round((canvas.height-this.height*scale)/2));
}
this.setAttribute("xscale", scale);
this.setAttribute("yscale", scale);
</method>
</class>
<scaledview id="sv" bgcolor="red">
<window width="200" height="100" title="Just a window!" align="center" valign="middle"/>
</scaledview>
<view>
<simplelayout axis="y" />
<text fontsize="12"
text="${'canvas: ' + canvas.width + ' * ' + canvas.height + ' ratio=' + (canvas.width/canvas.height)}"/>
<text fontsize="12"
text="${'scaledview: ' + sv.width + ' * ' + sv.height + ' ratio=' + sv.wratio}" />
<text fontsize="12"
text="${'scaledview: xscale=' + sv.xscale + '/yscale=' + sv.yscale}" />
</view>
</canvas>
확인 당신이 빨간색 <scaledview>이 정의 된 비율에 따라 스케일링 볼 수있는 응용 프로그램의 스크린 샷. 창 구성 요소는 캔버스 해상도가 증가하거나 감소함에 따라 크기가 커지고 축소됩니다. 캔버스 해상도의 화면 비율에 따라 폭과 높이, 그리고에 canvas.width 또는 하나 canvas.height을 min으로 상자를 확장 할 뜻
![enter image description here](https://i.stack.imgur.com/dFAWc.png)
합니까? 왜 화면에 표시되는 항목의 크기가 커지기 때문에 규모를 조정합니까? –
예 상자 크기를 다른 화면 크기에 따라 조정하는 방식으로 상자의 최소 너비와 높이를 조정하려고합니다. 이전에 나는 stretches = true를주고 width.write ("width", canvas.width/canvas.height)와 같은 수식을 사용했습니다. < 1.33 ? this.width * this.unstretchedheight/this.unstretchedwidth : canvas .신장);. 이것은 가로 세로 비율 – karthick
을 기반으로 적절한 너비를 할당합니다. @ RajuBitter : 그러나 신축성 속성이 서브 뷰에 적용되지 않기 때문에 최신 5.0 또는 4.9에서는 작동하지 않습니다. 그래서 xscale 또는 yscale을 사용해야합니다. – karthick