exyte / Macaw

Powerful and easy-to-use vector graphics Swift library with SVG support
MIT License
6.01k stars 554 forks source link

Am I missing something with Coordinate scaling? #665

Closed PunkStarStudios closed 4 years ago

PunkStarStudios commented 4 years ago

I think I am missing a big piece here.

I subclass MacawView (class MacawSalesChartView: MacawView).

The chart I draw end up being different depending on what device I run it on. I can lock down height so it's the same across any device, but the width will change depending on the device. So if I am drawing out a bar graph for example, I assume I need to know the width of the chart (frame/rect/whatever) so I can calculate spacing and bar width and all that.

So my question is 2 fold :

1) Is there some kind of automatic scaling system (I seem to recall someone saying there was in a youtube video) where I simply set a "virtual size" and do all the work and it redraws it correctly on the various devices

or

2) Do I need to modify the drawing code based on the width of the frame running on that particular device. And if so, where can I get the frame width/height from?

Thanks in advance.

ystrot commented 4 years ago

Hi David,

  1. There is content layout you can use: https://github.com/exyte/Macaw/wiki/Understanding-MacawView-content-layout

  2. You don't need to modify your drawing code if you're using content layout. However you can always access node width/height using node.bounds.