1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 05:40:03 -04:00

Convenience const fn for Margin, Rounding and Shadow (#4080)

I often write constants at the top of my widget files, as a "config". I
kept writing stuff like that :
```rust
const DEFAULT_INNER_MARGIN: Margin = Margin { left: 17., right: 17., top: 7., bottom: 7. };
```
So I prefixed constructors for `Margin`, `Rounding` and `Shadow` const.
No code was changed.

I also added a `Shadow::new()` for similar reasons.
This commit is contained in:
0Qwel
2024-02-21 16:20:26 +01:00
committed by GitHub
parent cdb7d153dc
commit 23e8312fc0
3 changed files with 13 additions and 9 deletions

View File

@@ -622,7 +622,7 @@ impl Margin {
};
#[inline]
pub fn same(margin: f32) -> Self {
pub const fn same(margin: f32) -> Self {
Self {
left: margin,
right: margin,
@@ -633,7 +633,7 @@ impl Margin {
/// Margins with the same size on opposing sides
#[inline]
pub fn symmetric(x: f32, y: f32) -> Self {
pub const fn symmetric(x: f32, y: f32) -> Self {
Self {
left: x,
right: x,
@@ -649,12 +649,12 @@ impl Margin {
}
#[inline]
pub fn left_top(&self) -> Vec2 {
pub const fn left_top(&self) -> Vec2 {
vec2(self.left, self.top)
}
#[inline]
pub fn right_bottom(&self) -> Vec2 {
pub const fn right_bottom(&self) -> Vec2 {
vec2(self.right, self.bottom)
}