Fix compilation of `egui_extras` without `serde` feature (#5014)
* Closes https://github.com/emilk/egui/issues/4771
This commit is contained in:
parent
bd7d71e7fd
commit
58bc67e02f
|
|
@ -57,6 +57,10 @@ jobs:
|
||||||
- name: check epaint --no-default-features
|
- name: check epaint --no-default-features
|
||||||
run: cargo check --locked --no-default-features --lib -p epaint
|
run: cargo check --locked --no-default-features --lib -p epaint
|
||||||
|
|
||||||
|
# Regression test for https://github.com/emilk/egui/issues/4771
|
||||||
|
- name: cargo check -p test_egui_extras_compilation
|
||||||
|
run: cargo check -p test_egui_extras_compilation
|
||||||
|
|
||||||
- name: Test doc-tests
|
- name: Test doc-tests
|
||||||
run: cargo test --doc --all-features
|
run: cargo test --doc --all-features
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3804,6 +3804,14 @@ dependencies = [
|
||||||
"winapi-util",
|
"winapi-util",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "test_egui_extras_compilation"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"eframe",
|
||||||
|
"egui_extras",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "test_inline_glow_paint"
|
name = "test_inline_glow_paint"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ all-features = true
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["dep:mime_guess2", "serde"]
|
default = ["dep:mime_guess2"]
|
||||||
|
|
||||||
## Shorthand for enabling the different types of image loaders (`file`, `http`, `image`, `svg`).
|
## Shorthand for enabling the different types of image loaders (`file`, `http`, `image`, `svg`).
|
||||||
all_loaders = ["file", "http", "image", "svg", "gif"]
|
all_loaders = ["file", "http", "image", "svg", "gif"]
|
||||||
|
|
|
||||||
|
|
@ -153,16 +153,22 @@ impl CodeTheme {
|
||||||
///
|
///
|
||||||
/// There is one dark and one light theme stored at any one time.
|
/// There is one dark and one light theme stored at any one time.
|
||||||
pub fn from_memory(ctx: &egui::Context) -> Self {
|
pub fn from_memory(ctx: &egui::Context) -> Self {
|
||||||
if ctx.style().visuals.dark_mode {
|
#![allow(clippy::needless_return)]
|
||||||
ctx.data_mut(|d| {
|
|
||||||
d.get_persisted(egui::Id::new("dark"))
|
let (id, default) = if ctx.style().visuals.dark_mode {
|
||||||
.unwrap_or_else(Self::dark)
|
(egui::Id::new("dark"), Self::dark as fn() -> Self)
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
ctx.data_mut(|d| {
|
(egui::Id::new("light"), Self::light as fn() -> Self)
|
||||||
d.get_persisted(egui::Id::new("light"))
|
};
|
||||||
.unwrap_or_else(Self::light)
|
|
||||||
})
|
#[cfg(feature = "serde")]
|
||||||
|
{
|
||||||
|
return ctx.data_mut(|d| d.get_persisted(id).unwrap_or_else(default));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "serde"))]
|
||||||
|
{
|
||||||
|
return ctx.data_mut(|d| d.get_temp(id).unwrap_or_else(default));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -170,11 +176,17 @@ impl CodeTheme {
|
||||||
///
|
///
|
||||||
/// There is one dark and one light theme stored at any one time.
|
/// There is one dark and one light theme stored at any one time.
|
||||||
pub fn store_in_memory(self, ctx: &egui::Context) {
|
pub fn store_in_memory(self, ctx: &egui::Context) {
|
||||||
if self.dark_mode {
|
let id = if ctx.style().visuals.dark_mode {
|
||||||
ctx.data_mut(|d| d.insert_persisted(egui::Id::new("dark"), self));
|
egui::Id::new("dark")
|
||||||
} else {
|
} else {
|
||||||
ctx.data_mut(|d| d.insert_persisted(egui::Id::new("light"), self));
|
egui::Id::new("light")
|
||||||
}
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
ctx.data_mut(|d| d.insert_persisted(id, self));
|
||||||
|
|
||||||
|
#[cfg(not(feature = "serde"))]
|
||||||
|
ctx.data_mut(|d| d.insert_temp(id, self));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -245,9 +257,15 @@ impl CodeTheme {
|
||||||
pub fn ui(&mut self, ui: &mut egui::Ui) {
|
pub fn ui(&mut self, ui: &mut egui::Ui) {
|
||||||
ui.horizontal_top(|ui| {
|
ui.horizontal_top(|ui| {
|
||||||
let selected_id = egui::Id::NULL;
|
let selected_id = egui::Id::NULL;
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
let mut selected_tt: TokenType =
|
let mut selected_tt: TokenType =
|
||||||
ui.data_mut(|d| *d.get_persisted_mut_or(selected_id, TokenType::Comment));
|
ui.data_mut(|d| *d.get_persisted_mut_or(selected_id, TokenType::Comment));
|
||||||
|
|
||||||
|
#[cfg(not(feature = "serde"))]
|
||||||
|
let mut selected_tt: TokenType =
|
||||||
|
ui.data_mut(|d| *d.get_temp_mut_or(selected_id, TokenType::Comment));
|
||||||
|
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
ui.set_width(150.0);
|
ui.set_width(150.0);
|
||||||
egui::widgets::global_dark_light_mode_buttons(ui);
|
egui::widgets::global_dark_light_mode_buttons(ui);
|
||||||
|
|
@ -288,7 +306,10 @@ impl CodeTheme {
|
||||||
|
|
||||||
ui.add_space(16.0);
|
ui.add_space(16.0);
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
ui.data_mut(|d| d.insert_persisted(selected_id, selected_tt));
|
ui.data_mut(|d| d.insert_persisted(selected_id, selected_tt));
|
||||||
|
#[cfg(not(feature = "serde"))]
|
||||||
|
ui.data_mut(|d| d.insert_temp(selected_id, selected_tt));
|
||||||
|
|
||||||
egui::Frame::group(ui.style())
|
egui::Frame::group(ui.style())
|
||||||
.inner_margin(egui::Vec2::splat(2.0))
|
.inner_margin(egui::Vec2::splat(2.0))
|
||||||
|
|
|
||||||
|
|
@ -543,12 +543,13 @@ impl TableState {
|
||||||
let rect = Rect::from_min_size(ui.available_rect_before_wrap().min, Vec2::ZERO);
|
let rect = Rect::from_min_size(ui.available_rect_before_wrap().min, Vec2::ZERO);
|
||||||
ui.ctx().check_for_id_clash(state_id, rect, "Table");
|
ui.ctx().check_for_id_clash(state_id, rect, "Table");
|
||||||
|
|
||||||
let state = ui
|
#[cfg(feature = "serde")]
|
||||||
.data_mut(|d| d.get_persisted::<Self>(state_id))
|
let state = ui.data_mut(|d| d.get_persisted::<Self>(state_id));
|
||||||
.filter(|state| {
|
#[cfg(not(feature = "serde"))]
|
||||||
// make sure that the stored widths aren't out-dated
|
let state = ui.data_mut(|d| d.get_temp::<Self>(state_id));
|
||||||
state.column_widths.len() == columns.len()
|
|
||||||
});
|
// Make sure that the stored widths aren't out-dated:
|
||||||
|
let state = state.filter(|state| state.column_widths.len() == columns.len());
|
||||||
|
|
||||||
let is_sizing_pass =
|
let is_sizing_pass =
|
||||||
ui.is_sizing_pass() || state.is_none() && columns.iter().any(|c| c.is_auto());
|
ui.is_sizing_pass() || state.is_none() && columns.iter().any(|c| c.is_auto());
|
||||||
|
|
@ -597,7 +598,15 @@ impl TableState {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn store(self, ui: &egui::Ui, state_id: egui::Id) {
|
fn store(self, ui: &egui::Ui, state_id: egui::Id) {
|
||||||
ui.data_mut(|d| d.insert_persisted(state_id, self));
|
#![allow(clippy::needless_return)]
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
{
|
||||||
|
return ui.data_mut(|d| d.insert_persisted(state_id, self));
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "serde"))]
|
||||||
|
{
|
||||||
|
return ui.data_mut(|d| d.insert_temp(state_id, self));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reset(ui: &egui::Ui, state_id: egui::Id) {
|
fn reset(ui: &egui::Ui, state_id: egui::Id) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
[package]
|
||||||
|
name = "test_egui_extras_compilation"
|
||||||
|
version = "0.1.0"
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
|
edition = "2021"
|
||||||
|
rust-version = "1.76"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
eframe = { workspace = true, features = ["default", "persistence"] }
|
||||||
|
egui_extras = { workspace = true }
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Regression test for <https://github.com/emilk/egui/issues/4771>
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
//! Regression test for <https://github.com/emilk/egui/issues/4771>
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
Loading…
Reference in New Issue