mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 05:10: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:
@@ -19,8 +19,12 @@ impl Shadow {
|
||||
color: Color32::TRANSPARENT,
|
||||
};
|
||||
|
||||
pub const fn new(extrusion: f32, color: Color32) -> Self {
|
||||
Self { extrusion, color }
|
||||
}
|
||||
|
||||
/// Tooltips, menus, …, for dark mode.
|
||||
pub fn small_dark() -> Self {
|
||||
pub const fn small_dark() -> Self {
|
||||
Self {
|
||||
extrusion: 16.0,
|
||||
color: Color32::from_black_alpha(96),
|
||||
@@ -28,7 +32,7 @@ impl Shadow {
|
||||
}
|
||||
|
||||
/// Tooltips, menus, …, for light mode.
|
||||
pub fn small_light() -> Self {
|
||||
pub const fn small_light() -> Self {
|
||||
Self {
|
||||
extrusion: 16.0,
|
||||
color: Color32::from_black_alpha(20),
|
||||
@@ -36,7 +40,7 @@ impl Shadow {
|
||||
}
|
||||
|
||||
/// Used for egui windows in dark mode.
|
||||
pub fn big_dark() -> Self {
|
||||
pub const fn big_dark() -> Self {
|
||||
Self {
|
||||
extrusion: 32.0,
|
||||
color: Color32::from_black_alpha(96),
|
||||
@@ -44,7 +48,7 @@ impl Shadow {
|
||||
}
|
||||
|
||||
/// Used for egui windows in light mode.
|
||||
pub fn big_light() -> Self {
|
||||
pub const fn big_light() -> Self {
|
||||
Self {
|
||||
extrusion: 32.0,
|
||||
color: Color32::from_black_alpha(16),
|
||||
|
||||
@@ -701,7 +701,7 @@ impl Rounding {
|
||||
};
|
||||
|
||||
#[inline]
|
||||
pub fn same(radius: f32) -> Self {
|
||||
pub const fn same(radius: f32) -> Self {
|
||||
Self {
|
||||
nw: radius,
|
||||
ne: radius,
|
||||
|
||||
Reference in New Issue
Block a user