I have a class which extends UIComponent and draws directly onto a Sprite contained within. Currently I'm (probably incorrectly) listening to the Event.RESIZE event and drawing the contents when the width and height are non-zero. The problem is that even though I've passed percentage widths to the instance tag, it doesn't appear to be resized along with other Flex components on the page, certainly the resize event isn't being fired at all.
I've hacked it for the moment by binding the width and height to a container which does resize, but how should I really be handling this?
Update :
It turns out I was setting the width and height somewhere in the redraw method (I have no recollection of why I did this!). I shall go hang my head in shame now...
I think you need to provide more information. I'm doing exactly the same, and it works smoothly for me. Perhaps the answer lies somewhere else: e.g. exactly what type of container do you use? Isn't it possible that the space gained/lost on resizing gets allocated to some other component within the cointainer? Try substituting your own component with an mx:Box with some colored background, and see if that resizes with the container.
Related
I've got one lit-element, inner-element, slotted into another lit-element, outer-element. For flexibility, the outer-element gets to set the width and height of the inner-element using CSS. The inner-element needs to know it's width and height to determine how to draw its SVG content.
How can inner-element reliably learn its own width and height across browsers?
I've got a live example here:
https://stackblitz.com/edit/7pkfkx-j9rnx9
I'm using updated() to get the width/height based on this very helpful information:
https://github.com/Polymer/lit-element/issues/507#issuecomment-459546838
In Chrome, the example works fine - the SVG displays "width = 150 height = 100". But in Edge, I get "width = 300 height = 303.8". Note that even in Edge, the inner-element ends up having the correct width and height (150x100), it just seems to be getting there after updated() has been called.
I don't have access to Edge in order to confirm, but there are a few things you might be interested in testing here.
1) In your index.ts you have the following code:
import './inner-element.js';
import './outer-element.js';
This means that the inner element, will register and upgrade before the outer element has been registered and upgraded, which means that its size will be determined initially as if outer-element is a div, and then subsequently be granted the slotted styles inside of outer-element. Swap the imports to prevent this specific race order from occuring.
2) You are measuring in firstUpdated() which can technically happen before the element hit's the page, meaning that you are measuring an unrendered element, which is an element that has no size. Waiting until connectedCallback() can ensure that you are measuring the element "in page".
3) Measuring the element synchronously means you might be measuring before all of the parent based/classed based/etc code has been run, using requestAnimationFrame() in connectedCallback() can help ensure that you aren't measuring until you can be 100% sure that the element is ready to be measured.
Try this demo out to confirm: https://stackblitz.com/edit/measure?file=inner-element.js
I've discovered that a reliable way to get the rendered width and height of the inner-element is to access them in a window.setTimeout() callback registered in firstUpdated().
This is demonstrated here.
Whereas the LitElement doesn't always have access to its own rendered width and height when its' updated() or firstUpdated() is called, it does seem to have access to these values when the timeout callback is called.
I would feel more comfortable marking this answer as correct if I could articulate why this is the case, but empirically it is working.
I have a QScrollArea (we'll call it myContainer) that contains and scrolls a child view (we'll call it myChildWidget). All works almost fine - when I change the height of myChildWidget dynamically in response to something, if the height exceeds that of myContainer (the QScrollArea), a vertical scroll bar pops into view, effectively narrowing myChildWidget since I've set it to resize its child using:
myContainer->setWidgetResizable(true);
The problem is that myChildWidget is not actually resized until later, rather than right when I set its new height or try resizing myContainer, so I can't do certain things depending on its new width without subclassing and putting in a whole bunch of extra code. Surely there's something I can call to get the QScrollArea to auto-resize its child right away, right? I can use:
QCoreApplication::processEvents();
but the problem with that is that it causes the widgets to flash and redraw when I'm not done setting things up. I've tried update(), updateGeometry(), and adjustSize(), both on the container and its child, and none work. Anything I'm missing? Thanks for any help.
When I resize a JavaFX window, I get the red highlighted spaces
at the bottom and right. I’ve tried a lot in the SceneBuilder to auto-maximize the “Bottom Left Control” by specifying a larger height & width alongside a “Pref Height” and “Pref Width” but nothing worked.
Of course I could register a resize listener that resizes the controls at runtime imperatively but that’s not really a nice solution. Is there a declarative way where this magic is done behind the scenes and where I have to merely set some flag to accomplish this?
I can't quite figure out what the best way of displaying an image is in my particular case, so hopefully someone on here has a few tips.
I want to display an image that gets re-sized automatically to fit inside the space that is available. I currently do this by creating a class derived from QLabel that implements void resizeEvent(QResizeEvent*) where I do a QPixmap::scaled to re-size the image. The problem is that this only works when the widget is enlarged because the widget doesn't get a resizeEvent when I try to make the widget smaller. I guess that because I set the image to the same size as the widget, it isn't allowed to be sized smaller again? I guess I could try to create a smaller image therefor introducing a sort of "border" around the image which would perhaps allow re-size events to occur when making the area smaller. Any thoughts?
resizeEvent is sent whenever size is changed. It doesn't matter whether it is enlarged or not.
But you can set Policy and Max/Min size to constraint widget in shrinking/enlarging. So if you have your widget not getting resizeEvent AND it doesn't shrink either, then look at your size policy and min width/height. If it shrinks but you doesn't have resizeEvent then you have some error in you logic, I believe.
Alternatively you can use paintEvent for image painting and use QWidget::rect() for your widget width/height.
Try changing the size policy of the label to QSizePolicy::Preferred.
Have a look at size policies in general.
If I have an object in a layout in Flex what is a good way to 'break it out' of that layout to be able to animate it.
For instance I have an image and a caption arranged at an angle. I want to make the image 'zoom out' slightly when the mouse rolls over it. Since its in a layout container is active if I were to resize it then obviously it would move around everything else.
I dont think I can achieve what I want by just setting includeinlayout=false.
Any experience with best practices on this?
My best idea I'm wondering about is making the image invisible and creating another image at the same location by using the screen coordinate conversion functions. This jsut semes clumsy
Wrap your object in a fixed size Canvas so that the layout upstream will remain the same. Then position the object manually within that container and then set its includeInLayout to false. At that point, you could do whatever you wanted with the interior object. Oh, also set clipContent to false. This should work whether you want it to grow or shrink.
If this is an itemrenderer or something that you've wrapped into a class, you could handle all of this in the class definition and make it transparent to consumers of the object. You'd also be able to write a mouseOver function that did what you wanted with the interior object that should zoom.