Skip to content

Add ratio method to Size#2861

Merged
hecrj merged 2 commits intoiced-rs:masterfrom
tigerros:master
Nov 24, 2025
Merged

Add ratio method to Size#2861
hecrj merged 2 commits intoiced-rs:masterfrom
tigerros:master

Conversation

@tigerros
Copy link
Contributor

@tigerros tigerros commented Mar 26, 2025

A new aspect_ratio function to create a Responsive with a given ratio. More info in the doc and examples.

A simple aspect_ratio function for Size<f32> which returns a new Size that satisfies the given aspect ratio within the bounds of the current Size while being as large as possible.

@airstrike
Copy link
Contributor

For the record—and I understand this is subjective—I'm not a huge fan of the double closures API as it "feels out of place" (again subjective) relative to how other widgets work.

My current half-baked view is that the ideal implementation would be one that modifies Responsive to include additional fields such that it allows for configuration of its sizing strategy between:

  1. the current "Fill parent in both axes" approach
  2. Fill only the width axis
  3. Fill only the height axis
  4. fill by using an aspect ratio

I haven't explored a draft implementation yet but that's my current thinking in terms of what I've seen people need, what I'd like to have myself, and what I think would feel idiomatic for iced.

@tigerros
Copy link
Contributor Author

double closures API as it "feels out of place" (again subjective) relative to how other widgets work

Could this be because there's not a lot of helpers/widgets that work with Responsive? If you wanted to create other Responsive helpers, you might encounter this pattern again. One closure to generate the Element, then another closure to (optionally) wrap the modified Element from the first one, because wrapping the whole Responsive outside of the helper doesn't produce the same behavior.

@edwloef
Copy link
Contributor

edwloef commented Mar 28, 2025

Could this maybe also be a helper function in the layout module, similar to layout::atomic but with a fixed aspect ratio?

@tigerros tigerros marked this pull request as draft March 28, 2025 18:09
@tigerros tigerros changed the title aspect_ratio helper for Responsive aspect_ratio function for Size Mar 28, 2025
@tigerros
Copy link
Contributor Author

tigerros commented Mar 28, 2025

Changed it to just a simple Size function because forcing it to be a Responsive had issues. Now it's simpler, easier to use and more flexible.

@tigerros tigerros marked this pull request as ready for review March 28, 2025 19:13
hecrj and others added 2 commits November 24, 2025 10:42
Co-authored-by: tigerros <tigerros@users.noreply.github.com>
Co-authored-by: tigerros <tigerros@users.noreply.github.com>
Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@hecrj hecrj added this to the 0.14 milestone Nov 24, 2025
@hecrj hecrj added feature New feature or request layout addition labels Nov 24, 2025
@hecrj hecrj enabled auto-merge November 24, 2025 09:45
@hecrj hecrj disabled auto-merge November 24, 2025 09:45
@hecrj hecrj changed the title aspect_ratio function for Size Add ratio method to Size Nov 24, 2025
@hecrj hecrj enabled auto-merge November 24, 2025 09:45
@hecrj hecrj merged commit 1f18774 into iced-rs:master Nov 24, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

addition feature New feature or request layout

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments