Flex 第一个窗口宽度/边界被忽略

发布于 2024-10-28 22:56:20 字数 2029 浏览 2 评论 0原文

我有一个窗口,我想在其中添加/删除组件并根据状态相应地调整窗口大小。但由于某种原因它忽略了第一次调整大小。 这是一个示例代码

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       minWidth="450"
                       minHeight="355"
                       currentState="{stateBox.selected ? 'one' : 'two'}"
                       currentStateChange="handleStateChange(event.oldState, event.newState)">

    <fx:Script>
        <![CDATA[
            private function handleStateChange(oldState:String, newState:String):void 
            {
                if (oldState == "two") {
                    width   -= 341;
                    minWidth    = 450;
                } else {
                    width   += 341;
                    minWidth    = 791;
                }
            }
        ]]>
    </fx:Script>

    <s:states>
        <s:State name="one" />
        <s:State name="two" />
    </s:states>
    <s:Rect id="rect1" top="0" left="0" right="0" right.two="341"  bottom="0" >
        <s:fill>
            <s:SolidColor color="0xDDDDDD" />
        </s:fill>
    </s:Rect>

    <s:Rect id="rect2" top="0" bottom="0" width="341" right="0" includeIn="two" >
        <s:fill>
            <s:SolidColor color="0x000000" />
        </s:fill>
    </s:Rect>

    <s:CheckBox id="stateBox" label="change state" />
</s:WindowedApplication>

想法是当状态更改为“two”时,我想添加 rect2 来显示并增加窗口的 minWidth 和大小。当状态更改为“一”时,我想从显示中删除 rect2 并调整窗口大小。这似乎有效,除了窗口在第一次状态从“二”变为“一”时不会缩小,但之后按预期工作。我不知道为什么它会忽略我第一次减小宽度。我还尝试直接更改nativeWindow.bounds,但这也不起作用。

最初我只是尝试根据状态设置 minWidth (minWidth.one="450 minWidth.two="791") 但这导致窗口在左侧增大并在右侧缩小,这导致每当状态发生变化时窗口都会向左移动。所以然后每当状态发生变化时,我都会将窗口移至右侧,但这会导致一些我不想要的闪烁,

有人知道为什么会发生这种情况吗?或者有什么好的解决方案可以解决我的问题吗?

I have a window in which I want to add/remove component and resize the window accordingly based on states. but for some reason it's ignoring the first resize.
here's a sample code

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       minWidth="450"
                       minHeight="355"
                       currentState="{stateBox.selected ? 'one' : 'two'}"
                       currentStateChange="handleStateChange(event.oldState, event.newState)">

    <fx:Script>
        <![CDATA[
            private function handleStateChange(oldState:String, newState:String):void 
            {
                if (oldState == "two") {
                    width   -= 341;
                    minWidth    = 450;
                } else {
                    width   += 341;
                    minWidth    = 791;
                }
            }
        ]]>
    </fx:Script>

    <s:states>
        <s:State name="one" />
        <s:State name="two" />
    </s:states>
    <s:Rect id="rect1" top="0" left="0" right="0" right.two="341"  bottom="0" >
        <s:fill>
            <s:SolidColor color="0xDDDDDD" />
        </s:fill>
    </s:Rect>

    <s:Rect id="rect2" top="0" bottom="0" width="341" right="0" includeIn="two" >
        <s:fill>
            <s:SolidColor color="0x000000" />
        </s:fill>
    </s:Rect>

    <s:CheckBox id="stateBox" label="change state" />
</s:WindowedApplication>

Idea is that when the state change to 'two', I want to add rect2 to display and increase the minWidth and size of the window. And when the state change to 'one', i want to remove rect2 from display and resize the window. This seems to work except the window doesn't shrink on the very first time the state change from "two" to "one" but works as expected afterwards. I'm not sure why it's ignoring first time I reduce the width. I also tried changing nativeWindow.bounds directly but that didn't work either.

Originally I just tried setting minWidth based on state (minWidth.one="450 minWidth.two="791") but that caused window to grow on left and shrink on right which caused the window to move left whenever the state changed. so then I just moved the window to right whenever state changed but that caused some flicker that I didn't want.

does anyone have any idea why this might be happening? or a good solution for my problem?

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

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

发布评论

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

评论(1

故事与诗 2024-11-04 22:56:20

尝试将这些行从:

                width   -= 341;
                minWidth    = 450;

翻转到:

                minWidth    = 450;
                width   -= 341;

我认为问题在于一般情况下设置条件的方式......我将复制您的代码并修改它我将如何执行此操作并重新发布为编辑,但您可以尝试上述建议(我相信您可能将宽度设置为低于最小宽度,然后减小 minWidth,因此首先设置的宽度将被设置为无效的宽度当前的 minWidth,认为您可能只在第一次看到这个,因为编辑时间

(编辑两次,通过将最小和最大高度设置为等于设置高度来添加锁定窗口大小):

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                       xmlns:s="library://ns.adobe.com/flex/spark"
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       minHeight="355"
                       maxHeight="355"
                       minWidth="450"
                       width.two="791"
                       width.one="450"
                       minWidth.one="450"
                       minWidth.two="791"
                       maxWidth.one="450"
                       maxWidth.two="791">

    <fx:Script>
        <![CDATA[
            protected function stateBox_changeHandler(event:Event):void
            {
                // TODO Auto-generated method stub
                currentState=stateBox.selected ? 'two' : 'one';
            }
        ]]>
    </fx:Script>

    <s:states>
        <s:State name="one"/>
        <s:State name="two"/>
    </s:states>

    <s:HGroup width="100%"
              height="100%"
              gap="0">
        <s:Rect width="450"
                height="100%">
            <s:fill>
                <s:SolidColor color="0xff0000"/>
            </s:fill>
        </s:Rect>

        <s:Rect width="341"
                height="100%"
                includeIn="two">
            <s:fill>
                <s:SolidColor color="0x000000"/>
            </s:fill>
        </s:Rect>
    </s:HGroup>

    <s:CheckBox id="stateBox"
                label="change state"
                change="stateBox_changeHandler(event)"/>
</s:WindowedApplication>

这是否实现了所需的行为 ^ (抱歉,我知道我更改了很多代码,但这就是我的处理方法,也许这不起作用,因为您需要设置其他显式大小,但似乎实现了我的目标)

Try flipping these lines around from:

                width   -= 341;
                minWidth    = 450;

to:

                minWidth    = 450;
                width   -= 341;

I think the problem is with the way that condition is setup in general.... I'm going to copy your code and modify it how I would go about doing this and repost as an edit, but you could try the above suggestion (I believe you may be setting the width lower than the minimum width then reducing the minWidth so the setting of the width in the first place would have been set to a width that isn't valid according to the current minWidth, think you may only see this the first time around due to timing with validation.

EDIT(ed twice, add locking the window size by setting min and max heights equal to the set height):

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                       xmlns:s="library://ns.adobe.com/flex/spark"
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       minHeight="355"
                       maxHeight="355"
                       minWidth="450"
                       width.two="791"
                       width.one="450"
                       minWidth.one="450"
                       minWidth.two="791"
                       maxWidth.one="450"
                       maxWidth.two="791">

    <fx:Script>
        <![CDATA[
            protected function stateBox_changeHandler(event:Event):void
            {
                // TODO Auto-generated method stub
                currentState=stateBox.selected ? 'two' : 'one';
            }
        ]]>
    </fx:Script>

    <s:states>
        <s:State name="one"/>
        <s:State name="two"/>
    </s:states>

    <s:HGroup width="100%"
              height="100%"
              gap="0">
        <s:Rect width="450"
                height="100%">
            <s:fill>
                <s:SolidColor color="0xff0000"/>
            </s:fill>
        </s:Rect>

        <s:Rect width="341"
                height="100%"
                includeIn="two">
            <s:fill>
                <s:SolidColor color="0x000000"/>
            </s:fill>
        </s:Rect>
    </s:HGroup>

    <s:CheckBox id="stateBox"
                label="change state"
                change="stateBox_changeHandler(event)"/>
</s:WindowedApplication>

Does this achieve the desired behavior ^ (sorry I know I changed a lot of code but this is just how I would approach it, maybe this won't work because of other explicit sizing you need to set but seems to achieve the goal to me)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文