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

refactor: const-ify the core primitives #5032

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
689e99b
refactor(math): use `Option::zip` for cleaner code
BastiDood Aug 29, 2024
e13d754
feat(math): add `const` where stable
BastiDood Aug 29, 2024
2fbf71d
feat(math): introduce `const` alternatives for `Vec2b::and` and `Vec2…
BastiDood Aug 29, 2024
d1c37ed
feat(color): use `const` where stable
BastiDood Aug 29, 2024
fdfe280
refactor(paint): use `default` attribute when deriving `Default`
BastiDood Aug 29, 2024
278c5fb
feat(paint): add `const` where stable
BastiDood Aug 29, 2024
9139060
feat(paint): add `Self::DEFAULT` constants
BastiDood Aug 29, 2024
1586664
feat(paint): add `const` alternatives to constructors
BastiDood Aug 29, 2024
789bcf5
refactor(paint): prefer `f32::INFINITY` constant
BastiDood Aug 29, 2024
f59abbc
refactor(gui): use `const` functions where stable
BastiDood Aug 29, 2024
fe73fa2
refactor(gui): implement `const` alternatives for various constructors
BastiDood Aug 29, 2024
a56382b
refactor(gui): prefer destructuring width and height
BastiDood Aug 29, 2024
ffc0dd3
refactor(gui): prefer using the `f32::recip` helper
BastiDood Aug 29, 2024
c105ef0
fix(gui): remove `const` for runtime-only functions
BastiDood Aug 29, 2024
860aab0
refactor(frame): add `const` where stable
BastiDood Aug 29, 2024
f05de6f
fix(gui): add `inline` to builder methods
BastiDood Aug 30, 2024
4f34491
chore: update branch from `main`
BastiDood Aug 30, 2024
b3c847f
fix(gui): add missing `const` in builders
BastiDood Aug 30, 2024
fa1f6ac
chore(paint): fix typo on `Shadow`
BastiDood Sep 1, 2024
fae5fdd
fix(gui): revert `const` for `UiBuilder::style`
BastiDood Sep 1, 2024
ec12532
chore: update branch from `master`
BastiDood Sep 2, 2024
f17659b
chore(clippy): remove needless borrow
BastiDood Sep 2, 2024
7028897
fix(paint): use correct default value for `PathShape::fill`
BastiDood Sep 2, 2024
59a351e
chore: update branch from `main`
BastiDood Sep 2, 2024
c93ea59
feat(gui): add `const` to `Sides`
BastiDood Sep 2, 2024
6cc2eee
chore: merge updates from `master`
BastiDood Sep 5, 2024
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
2 changes: 1 addition & 1 deletion crates/ecolor/src/hex_color_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Display for HexColor {
impl HexColor {
/// Retrieves the inner [`Color32`]
#[inline]
pub fn color(&self) -> Color32 {
pub const fn color(&self) -> Color32 {
match self {
Self::Hex3(color) | Self::Hex4(color) | Self::Hex6(color) | Self::Hex8(color) => *color,
}
Expand Down
4 changes: 2 additions & 2 deletions crates/ecolor/src/hsva.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct Hsva {

impl Hsva {
#[inline]
pub fn new(h: f32, s: f32, v: f32, a: f32) -> Self {
pub const fn new(h: f32, s: f32, v: f32, a: f32) -> Self {
Self { h, s, v, a }
}

Expand Down Expand Up @@ -110,7 +110,7 @@ impl Hsva {
// ------------------------------------------------------------------------

#[inline]
pub fn to_opaque(self) -> Self {
pub const fn to_opaque(self) -> Self {
Self { a: 1.0, ..self }
}

Expand Down
2 changes: 1 addition & 1 deletion crates/ecolor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub fn gamma_from_linear(linear: f32) -> f32 {

/// Cheap and ugly.
/// Made for graying out disabled `Ui`s.
pub fn tint_color_towards(color: Color32, target: Color32) -> Color32 {
pub const fn tint_color_towards(color: Color32, target: Color32) -> Color32 {
let [mut r, mut g, mut b, mut a] = color.to_array();

if a == 0 {
Expand Down
14 changes: 7 additions & 7 deletions crates/ecolor/src/rgba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl Rgba {

/// Return an additive version of this color (alpha = 0)
#[inline]
pub fn additive(self) -> Self {
pub const fn additive(self) -> Self {
let [r, g, b, _] = self.0;
Self([r, g, b, 0.0])
}
Expand All @@ -142,22 +142,22 @@ impl Rgba {
}

#[inline]
pub fn r(&self) -> f32 {
pub const fn r(&self) -> f32 {
self.0[0]
}

#[inline]
pub fn g(&self) -> f32 {
pub const fn g(&self) -> f32 {
self.0[1]
}

#[inline]
pub fn b(&self) -> f32 {
pub const fn b(&self) -> f32 {
self.0[2]
}

#[inline]
pub fn a(&self) -> f32 {
pub const fn a(&self) -> f32 {
self.0[3]
}

Expand Down Expand Up @@ -185,13 +185,13 @@ impl Rgba {

/// Premultiplied RGBA
#[inline]
pub fn to_array(&self) -> [f32; 4] {
pub const fn to_array(&self) -> [f32; 4] {
[self.r(), self.g(), self.b(), self.a()]
}

/// Premultiplied RGBA
#[inline]
pub fn to_tuple(&self) -> (f32, f32, f32, f32) {
pub const fn to_tuple(&self) -> (f32, f32, f32, f32) {
(self.r(), self.g(), self.b(), self.a())
}

Expand Down
8 changes: 4 additions & 4 deletions crates/eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,12 +628,12 @@ impl Frame {
///
/// Equivalent to `cfg!(target_arch = "wasm32")`
#[allow(clippy::unused_self)]
pub fn is_web(&self) -> bool {
pub const fn is_web(&self) -> bool {
cfg!(target_arch = "wasm32")
}

/// Information about the integration.
pub fn info(&self) -> &IntegrationInfo {
pub const fn info(&self) -> &IntegrationInfo {
&self.info
}

Expand All @@ -660,7 +660,7 @@ impl Frame {
/// To get a [`glow`] context you need to compile with the `glow` feature flag,
/// and run eframe using [`Renderer::Glow`].
#[cfg(feature = "glow")]
pub fn gl(&self) -> Option<&std::sync::Arc<glow::Context>> {
pub const fn gl(&self) -> Option<&std::sync::Arc<glow::Context>> {
self.gl.as_ref()
}

Expand All @@ -679,7 +679,7 @@ impl Frame {
///
/// Can be used to manage GPU resources for custom rendering with WGPU using [`egui::PaintCallback`]s.
#[cfg(feature = "wgpu")]
pub fn wgpu_render_state(&self) -> Option<&egui_wgpu::RenderState> {
pub const fn wgpu_render_state(&self) -> Option<&egui_wgpu::RenderState> {
self.wgpu_render_state.as_ref()
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl EpiIntegration {
}

/// If `true`, it is time to close the native window.
pub fn should_close(&self) -> bool {
pub const fn should_close(&self) -> bool {
self.close
}

Expand Down
2 changes: 1 addition & 1 deletion crates/eframe/src/stopwatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Stopwatch {
}

impl Stopwatch {
pub fn new() -> Self {
pub const fn new() -> Self {
Self {
total_time_ns: 0,
start: None,
Expand Down
4 changes: 2 additions & 2 deletions crates/eframe/src/web/app_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl AppRunner {
Ok(runner)
}

pub fn egui_ctx(&self) -> &egui::Context {
pub const fn egui_ctx(&self) -> &egui::Context {
&self.egui_ctx
}

Expand Down Expand Up @@ -168,7 +168,7 @@ impl AppRunner {
self.painter.destroy();
}

pub fn has_outstanding_paint_data(&self) -> bool {
pub const fn has_outstanding_paint_data(&self) -> bool {
self.clipped_primitives.is_some()
}

Expand Down
2 changes: 1 addition & 1 deletion crates/eframe/src/web/web_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl WebLogger {

/// Create a new [`WebLogger`] with the given filter,
/// but don't install it.
pub fn new(filter: log::LevelFilter) -> Self {
pub const fn new(filter: log::LevelFilter) -> Self {
Self { filter }
}
}
Expand Down
Loading
Loading