使用固定 rowCount 和 rowCount 来缩放 Spark DataGrid没有斯科勒斯

发布于 2024-12-13 07:15:42 字数 1802 浏览 3 评论 0原文

这是调整大小的缩放比例: stage.scaleMode = StageScaleMode.SHOW_ALL; // 不好,因为只是 Datagrid 需要缩放

我正在尝试找到一种方法来缩放(字体或scaleX&Y)DataGrid(使用requestedMinRowCount = requestsMaxRowCount = requestsRowCount = dataProviderLength),以便它始终显示所有内容行(所以没有滚动条)。

我提出的缩放解决方案是:

protected function thisDatagrid_resizeHandler(event:ResizeEvent):void
{
   if (event.oldWidth < this.width) {
     this.setStyle('fontSize', this.getStyle('fontSize') + 0.5);
   } else if (event.oldWidth > this.width) {
      this.setStyle('fontSize', this.getStyle('fontSize') - 0.5);
   }
   this.minWidth = this.measuredMinWidth;
}

虽然上面的代码实际上在调整大小时调整了文本(因此是单元格、列和网格)的大小,但我遇到的问题是当重新缩放垂直发生时。

为了使 requestsRowCount 正常工作,Datagrid 上不应设置固定高度。 所以我想知道有什么方法可以让网格不断显示所有的行和行?缩放时的列(即使垂直调整大小)?

另一个选项是覆盖 updateDisplayList,尽管不能直接调整大小。

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {

     //super.updateDisplayList(unscaledWidth, unscaledHeight);              
     trace('oldWidth: ' + oldWidth + '  | unscaledWidth: ' + unscaledWidth + '  | parentWidth: ' + this.parent.width);
     trace('oldHeight: ' + oldHeight + '  | unscaledHeight: ' + unscaledHeight + '  | parentHeight: ' + this.parent.height);
     trace('Potential ScaleX: ' + (unscaledWidth - oldWidth)/unscaledWidth);
     trace('Potential ScaleY: ' + (unscaledHeight - oldHeight)/unscaledHeight);
     trace('----------------------------------------------------');
     /* scaleX = (unscaledWidth - oldWidth)/unscaledWidth;
     scaleY = (unscaledHeight - oldHeight)/unscaledHeight; */

     //super.updateDisplayList(unscaledWidth, unscaledHeight);
}

如果我取消注释scaleX & 就会出现问题scaleY,它会永远循环...

This is resize is scaling by: stage.scaleMode = StageScaleMode.SHOW_ALL; // No Good cause just the Datagrids need to scale

I am trying to find a way to Scale (either font or scaleX&Y) a DataGrid (with requestedMinRowCount = requestedMaxRowCount = requestedRowCount = dataProviderLength), so that it would Always show all the Rows (so no scrollers).

A Solution I came up with for Scaling is:

protected function thisDatagrid_resizeHandler(event:ResizeEvent):void
{
   if (event.oldWidth < this.width) {
     this.setStyle('fontSize', this.getStyle('fontSize') + 0.5);
   } else if (event.oldWidth > this.width) {
      this.setStyle('fontSize', this.getStyle('fontSize') - 0.5);
   }
   this.minWidth = this.measuredMinWidth;
}

While the code above actually does resize the text (hence the cell, column and grid) on Resize, the problem I am getting is when the rescale happens vertically.

For the requestedRowCount to work, there should not be a fixed height set on the Datagrid.
So I am wondering what is the way to get the grid to constantly show all it's rows & columns as it scales (even if resized vertically)?

Another Option would be overriding updateDisplayList, though not straight forward for resizing.

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {

     //super.updateDisplayList(unscaledWidth, unscaledHeight);              
     trace('oldWidth: ' + oldWidth + '  | unscaledWidth: ' + unscaledWidth + '  | parentWidth: ' + this.parent.width);
     trace('oldHeight: ' + oldHeight + '  | unscaledHeight: ' + unscaledHeight + '  | parentHeight: ' + this.parent.height);
     trace('Potential ScaleX: ' + (unscaledWidth - oldWidth)/unscaledWidth);
     trace('Potential ScaleY: ' + (unscaledHeight - oldHeight)/unscaledHeight);
     trace('----------------------------------------------------');
     /* scaleX = (unscaledWidth - oldWidth)/unscaledWidth;
     scaleY = (unscaledHeight - oldHeight)/unscaledHeight; */

     //super.updateDisplayList(unscaledWidth, unscaledHeight);
}

The problem with this if I uncomment scaleX & scaleY, it'll loop forever...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小红帽 2024-12-20 07:15:42

我可能会误解你,但你不能使用:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <s:DataGrid
        id="grid"
        width="100%"
        requestedRowCount="{grid.dataProvider.length}"
        rowHeight="24"
        fontSize="12"
        horizontalScrollPolicy="off"
        verticalScrollPolicy="off">

        <s:dataProvider>
            <s:ArrayCollection>
                <s:source>
                    <fx:Object id="one" label="One" value="1" />
                    <fx:Object id="two" label="Two" value="2" />
                    <fx:Object id="three" label="Three" value="3" />
                </s:source>
            </s:ArrayCollection>
        </s:dataProvider>

        <s:columns>
            <s:ArrayCollection>
                <s:GridColumn dataField="label" headerText="Label" />
                <s:GridColumn dataField="value" headerText="Value" />
            </s:ArrayCollection>
        </s:columns>
    </s:DataGrid>
</s:Application>

I might be misunderstanding you but couldn't you just use:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <s:DataGrid
        id="grid"
        width="100%"
        requestedRowCount="{grid.dataProvider.length}"
        rowHeight="24"
        fontSize="12"
        horizontalScrollPolicy="off"
        verticalScrollPolicy="off">

        <s:dataProvider>
            <s:ArrayCollection>
                <s:source>
                    <fx:Object id="one" label="One" value="1" />
                    <fx:Object id="two" label="Two" value="2" />
                    <fx:Object id="three" label="Three" value="3" />
                </s:source>
            </s:ArrayCollection>
        </s:dataProvider>

        <s:columns>
            <s:ArrayCollection>
                <s:GridColumn dataField="label" headerText="Label" />
                <s:GridColumn dataField="value" headerText="Value" />
            </s:ArrayCollection>
        </s:columns>
    </s:DataGrid>
</s:Application>
流殇 2024-12-20 07:15:42

最好的(也是最高效的方法是使用数据网格所在的组的布局,并应用如下所示的布局:

例如:ScaleOneLayout.as

import mx.core.UIComponent;

import spark.layouts.BasicLayout;

public class ScaleOneLayout extends BasicLayout
{
    public function ScaleOneLayout()
    {
        super();
    }

    override public function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
   {
        var child:UIComponent;
        child = target.getElementAt(0) as UIComponent;
        child.setLayoutBoundsSize(child.getPreferredBoundsWidth(), child.getPreferredBoundsHeight());
        child.scaleX = unscaledWidth / child.width;
        child.scaleY = unscaledHeight / child.height;
    }
}

The best (and most performant way is to use the layout of a group where the Datagrids would be located, and apply a layout like the one below:

ex: ScaleOneLayout.as

import mx.core.UIComponent;

import spark.layouts.BasicLayout;

public class ScaleOneLayout extends BasicLayout
{
    public function ScaleOneLayout()
    {
        super();
    }

    override public function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
   {
        var child:UIComponent;
        child = target.getElementAt(0) as UIComponent;
        child.setLayoutBoundsSize(child.getPreferredBoundsWidth(), child.getPreferredBoundsHeight());
        child.scaleX = unscaledWidth / child.width;
        child.scaleY = unscaledHeight / child.height;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文