AparokshaUI/adwaita-swift

Description of the feature request

iDevPro opened this issue · 3 comments

Is your feature request related to a problem? Please describe.

Picture resize

Describe the solution you'd like

Sometimes, to display images, it is necessary to redraw the image for Picture, for example, we upload an image of a rectangular type, but we want to display it as a square.
The solution:

  • Create Image type with some mechanics to draw like SwiftUI Image type :)

Describe alternatives you've considered

The alternatives:

  • Provide ability widget masking or clipping (not found yet how to mask View in GTK/Adwaita)
  • Provide image size and style for redraw image into Picture itself (ex: fit, fill, center, crop)

Additional context

Don't know yet...

I added one modifier and a new widget which should hopefully help accomplishing your goal:

  • Use the contentFit(_:) modifier for pictures which defines how the content should be resized to fit inside the picture's frame. If you want to display a rectangular image as a square, ContentFit.cover is the right choice.
  • To make the picture's frame a square, use the AspectFrame widget. In some situations, creating it via the aspectRatio(_:) modifier might be more convenient than using the widget's initializer.

The code for fitting a rectangular image into a square could look similar to this:

Picture()
    .contentFit(.cover)
    .data(data)
    .aspectRatio(1)