Responsive Design with Konva? - scale

is it possible that with Konva drawed figures, dynamically scale depending of the device/resolution the user use?
So, like a responsive design?
Thanks

Take a look at this example made with KineticJS and try to adapt it according to your needs. The trick is in setting a fixed size for the stage at the begining and then adapt it's size and scale accordingly to the width/height of the stage's container.
You will also have to update some naming conventions that might have changed in the transition between KineticJS and Konva.js.

Related

CSS Scaling based on base-width

I know there are several approaches to scale my website. But I couldn't even find a smart way to scale my page based on a base-width.
Say, I have optimised my mobile-site for a specific width and for all other widths the page is scaled. I may set my basic-width to 640px - if the visitors viewport is 640px, the elements are not scaled. If the visitors viewport is 1000ox, the element should be scaled by factor 1.5625 (1000px/640px). What is a smart way to achieve this. Yes, I could run JS to get the viewport and calculate the width, but I would prefer a CSS solution - like setting a parameter and multiply width within the classes.
Thanks and regards :)
Here's a wee list of what you should consider using in css.
Media Queries : These can help you to adjust fixed a width to whichever size is required for the user.
https://www.w3schools.com/css/css_rwd_mediaqueries.asp
Use percentages : By using percentages instead of a fixed width the object you apply it on adjusts to the screen of the user.
https://www.w3schools.com/cssref/pr_dim_width.asp
Use min-width & max-width : This allows you to set a minimum or maximum width it can help making it easier to adjust the website to the used screen size.
https://www.w3schools.com/cssref/pr_dim_min-width.asp
https://www.w3schools.com/cssref/pr_dim_max-width.asp
I hope that helps you out a little bit :)
this is a good one to play around with: https://www.w3schools.com/cssref/playit.asp?filename=playcss_width&preval=50%25

Can i define generic size that fits to any device? bootstrap

I started to work with bottstrap. And the amazing thing about that thing - its giving the ability to control the width of blocks on the screen - to fit to any size of device as comfortable as can.
The code that alowed to help me with the width is:
class = 'col-md-2'
My question is -
There is any way to do that exactly thing just with height of blocks? because when i make a site - the widht is suitable in any device (again,, because col-md...)
but the height is different. and i dont want that.
you can use row-eq-height and you can check the documentation here http://getbootstrap.com.vn/examples/equal-height-columns/

How to properly size Qt widgets?

Main Question
What is the "right" way to give your widgets default sizes and make sure they contract, expand, or remain fixed if there is additional or not enough space to accommodate them?
How I Think Qt Works
After reading the Qt documentation it seems like the sizing algorithm goes something like this...the layout begins by asking its children for their ideal size via the QWidget::sizeHint method. If the layout has additional space or not enough space then it'll determine which widgets to resize based on each widget's sizing policy (QWidget::sizePolicy), minimum size (QWidget::minimumSize), and maximum size (QWidget::maximumSize).
Why isn't there a QWidget::setSizeHint method?
If my understanding is close to being accurate then it would seem all you'd have to do is set the sizeHint, sizePolicy, maximumSize, and minimumSize on each widget and everything would just work. So why isn't there a setSizeHint method?!?!??!! Sure, every time you use a widget that provides all of the functionality you need (QTableView, QComboBox, etc) you could extend it and override a single method but that sounds absolutely ridiculous.
One of the sizing issues I'm fighting with.
I've got a QMainWindow with a QDockWidget on the left hand side. The QDockWidget has a QTableView. I'd like to have the QDockWidget/QTableView take up a "reasonable" amount of space on start up and then the user can resize it however small or large they'd like.
Unfortunately, when the application starts up it gives the QDockWidget/QTableView so little space that it requires a horizontal scroll bar. The only way I've found to force it to give it a reasonable amount of width is to set the QDockWidget's minimum width but then it prevents the user from resizing it as small as they might like to.
Why isn't there a QWidget::setSizeHint method?
In my opinion it is much better for a widget to compute its preferred size based on its content (or rules) instead of allowing the coder to set a sizeHint probably hardcoded or at least prone to errors.
I almost never had to set a size on a widget, playing with the QSizePolicy was enough. And when I needed some specific constraints, playing with minimum/maximum sizes was enough. So that Qt layouts were always able to adapt the widget.
If you want to set up yourself some percentages on the sizes etc, you can play with the stretch parameter. You can also add spacers when you need empty spaces.
Extending a QWidget to override the QWidget::sizeHint method does not sound ridiculous to me, as you change the widget behaviour by changing its preferred size and that fits the polymorphism spirit of OOD.
How to properly size Qt widgets? is a vague question and depends on the use cases. Most of the time choosing the good layouts and size-policy lets you achieve very adaptative GUI. Qt Designer can help to do this right, even if the layout management is not always intuitive (you need to place your widgets first and then set them in layouts from the inner to the outer layout).
About your specific issue, it's hard to tell why your QDockWidget gets too small without knowing the details of the layout(s) you have around your two widgets in the window. Maybe it is a specific issue with QDockWidget : see related questions :
QDockWidget starting size
Qt 5.7 QDockWidget default size
Prevent QDockWidget autosizing behaviour

JavaFx text resizing

What is the best way (in terms of performance) to resize a text proportionally to the size of its parent ? I want to make a undecorated window in which the text (which can span several lines) always use all the available size.
Well, I don't know if it is the best way but using scale is working fine.
You just have to listen changes to the heightProperty and widthProperty of the parents in order to compute a scale factor and apply it to the component (Here a Text or a Label). This can be done with JavaFx magic binding too :)
So, there is no need to dynamically change the Font or something like that (and I think this would be a lot more slow than scale computation).

How to make images resizable in flexible layout?

If we make fluid layout we can use em or % for font and div width and height to make fluid but how to make images resizable?
I want to make one layout for all sizes and devices
Joel Spolsky managed to find a very easy solution (a small proprietary CSS definition for IE). He found the solution here.
There's no simple solution for this. You can use flexible units for the images just like you can your other page elements. But this will result in inefficiencies and aesthetic issues including excess file size for a tiny image (if you're sizing it down), pixellation of sized-up images, etc. So what you likely want is to start with a large image and scale down to the appropriate size versions, and use Javascript to write out a tag referring to the correct size image depending on context.
Well you can size images relative to the viewport width (eg. img.thing { width: 50%; }, but you don't generally want to. Scaled images will at best (when the browser does bicubic resizing) look a bit blurry, and at worst totally blocky/jaggy (nearest neighbour resizing). You can include some CSS (SVG's image-rendering will be supported for HTML in Firefox 3.6; -ms-interpolation-mode in IE) to try to coax the browsers to use the better scaling mode, but it's far from reliable and still the best rendering isn't that great.
In addition, CSS background-image​s cannot be resized at all (yet; it is proposed for CSS3 but you'll have a long wait).
Liquid layout generally aims to adjust the distances between fixed-size images to respond to changes in viewport width, rather than scale the whole page including images. The user can, at least in modern browsers, zoom the whole page including images themselves, taking the image quality hit if they need to.
I reckon you will have to make use of the canvas element from HTML5. Or you could have some JavaScript that sets the size of the image tag but you would have to do some math to figure out the correct proportions.

Resources