Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convenience const fn for Margin, Rounding and Shadow #4080

Merged
merged 5 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)
}

Expand Down
12 changes: 8 additions & 4 deletions crates/epaint/src/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,36 @@ 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),
}
}

/// 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),
}
}

/// 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),
}
}

/// 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),
Expand Down
2 changes: 1 addition & 1 deletion crates/epaint/src/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading