diff --git a/Cargo.toml b/Cargo.toml index 0702c45..b3f6714 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,11 @@ categories = ["gui"] exclude = ["assets/"] [dependencies] -egui = "0.26" +egui26 = { version = "0.26", package = "egui", default-features = false, optional = true } +egui27 = { version = "0.27", package = "egui", default-features = false, optional = true } [dev-dependencies] eframe = "0.26" + +[features] +default = [ "egui26" ] diff --git a/README.md b/README.md index 588f462..7a16cf5 100644 --- a/README.md +++ b/README.md @@ -42,11 +42,13 @@ ## Usage +catppuccin-egui uses Cargo features to add support for new egui versions without breaking backwards compatibility. + Add the crate to your `Cargo.toml`: ```toml [dependencies] -catppuccin-egui = "4.0" +catppuccin-egui = { version = "5.0", features = ["egui27"] } ``` To use a theme, call the `set_theme` function with a theme and the egui context: diff --git a/src/lib.rs b/src/lib.rs index 1a12201..ad17542 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,7 @@ //! # Example //! //! ```rust +//! # use eframe::egui; //! struct App; //! impl eframe::App for App { //! fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { @@ -20,6 +21,7 @@ //! You can also customize your own theme: //! //! ```rust +//! # use eframe::egui; //! use catppuccin_egui::{Theme, MOCHA}; //! const MY_MOCHA: Theme = Theme { //! red: egui::Color32::from_rgb(255, 0, 0), @@ -28,6 +30,14 @@ //! ``` //! +#[cfg(not(any(feature = "egui26", feature = "egui27")))] +compile_error!("at least one egui version must be enabled"); + +#[cfg(feature = "egui26")] +use egui26 as egui; +#[cfg(feature = "egui27")] +use egui27 as egui; + use egui::{epaint, style, Color32}; /// Apply the given theme to a [`Context`](egui::Context). @@ -41,6 +51,7 @@ pub fn set_theme(ctx: &egui::Context, theme: Theme) { /// # Example /// /// ```rust +/// # use eframe::egui; /// # use egui::__run_test_ctx; /// # __run_test_ctx(|ctx| { /// let mut style = (*ctx.style()).clone();