Merge branch 'master' into feature/test-recorder

This commit is contained in:
Héctor Ramón Jiménez 2025-09-11 04:57:17 +02:00
commit a052ce58b0
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
69 changed files with 1555 additions and 833 deletions

View file

@ -78,14 +78,19 @@ where
let total_spacing = spacing * items.len().saturating_sub(1) as f32;
let max_cross = axis.cross(limits.max());
let compression = limits.compression();
let (main_compress, cross_compress) =
axis.pack(compression.width, compression.height);
let (main_compress, cross_compress) = {
let compression = limits.compression();
axis.pack(compression.width, compression.height)
};
let compression = {
let (compress_x, compress_y) = axis.pack(main_compress, false);
Size::new(compress_x, compress_y)
};
let mut fill_main_sum = 0;
let mut some_fill_cross = false;
let mut cross = if cross_compress { 0.0 } else { max_cross };
let mut available = axis.main(limits.max()) - total_spacing;
let mut nodes: Vec<Node> = Vec::with_capacity(items.len());

View file

@ -130,8 +130,17 @@ impl From<Alignment> for alignment::Horizontal {
}
/// The shaping strategy of some text.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Shaping {
/// Auto-detect the best shaping strategy from the text.
///
/// This strategy will use [`Basic`](Self::Basic) shaping if the
/// text consists of only ASCII characters; otherwise, it will
/// use [`Advanced`](Self::Advanced) shaping.
///
/// This is the default, if neither the `basic-shaping` nor `advanced-shaping`
/// features are enabled.
Auto,
/// No shaping and no font fallback.
///
/// This shaping strategy is very cheap, but it will not display complex
@ -140,8 +149,8 @@ pub enum Shaping {
/// You should use this strategy when you have complete control of the text
/// and the font you are displaying in your application.
///
/// This is the default.
#[default]
/// This will be the default if the `basic-shaping` feature is enabled and
/// the `advanced-shaping` feature is disabled.
Basic,
/// Advanced text shaping and font fallback.
///
@ -150,9 +159,23 @@ pub enum Shaping {
/// may be needed to display all of the glyphs.
///
/// Advanced shaping is expensive! You should only enable it when necessary.
///
/// This will be the default if the `advanced-shaping` feature is enabled.
Advanced,
}
impl Default for Shaping {
fn default() -> Self {
if cfg!(feature = "advanced-shaping") {
Self::Advanced
} else if cfg!(feature = "basic-shaping") {
Self::Basic
} else {
Self::Auto
}
}
}
/// The wrapping strategy of some text.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum Wrapping {

View file

@ -166,31 +166,6 @@ impl Theme {
}
}
impl Default for Theme {
fn default() -> Self {
#[cfg(feature = "auto-detect-theme")]
{
use std::sync::LazyLock;
static DEFAULT: LazyLock<Theme> = LazyLock::new(|| {
match dark_light::detect()
.unwrap_or(dark_light::Mode::Unspecified)
{
dark_light::Mode::Dark => Theme::Dark,
dark_light::Mode::Light | dark_light::Mode::Unspecified => {
Theme::Light
}
}
});
DEFAULT.clone()
}
#[cfg(not(feature = "auto-detect-theme"))]
Theme::Light
}
}
impl fmt::Display for Theme {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
@ -256,6 +231,18 @@ impl fmt::Display for Custom {
}
}
/// A theme mode, denoting the tone or brightness of a theme.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Mode {
/// No specific tone.
#[default]
None,
/// A mode referring to themes with light tones.
Light,
/// A mode referring to themes with dark tones.
Dark,
}
/// The base style of a theme.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Style {
@ -268,7 +255,13 @@ pub struct Style {
/// The default blank style of a theme.
pub trait Base {
/// Returns the default base [`Style`] of a theme.
/// Returns the default theme for the preferred [`Mode`].
fn default(preference: Mode) -> Self;
/// Returns the [`Mode`] of the theme.
fn mode(&self) -> Mode;
/// Returns the default base [`Style`] of the theme.
fn base(&self) -> Style;
/// Returns the color [`Palette`] of the theme.
@ -280,6 +273,39 @@ pub trait Base {
}
impl Base for Theme {
fn default(preference: Mode) -> Self {
use std::env;
use std::sync::OnceLock;
static SYSTEM: OnceLock<Option<Theme>> = OnceLock::new();
let system = SYSTEM.get_or_init(|| {
let name = env::var("ICED_THEME").ok()?;
Theme::ALL
.iter()
.find(|theme| theme.to_string() == name)
.cloned()
});
if let Some(system) = system {
return system.clone();
}
match preference {
Mode::None | Mode::Light => Self::Light,
Mode::Dark => Self::Dark,
}
}
fn mode(&self) -> Mode {
if self.extended_palette().is_dark {
Mode::Dark
} else {
Mode::Light
}
}
fn base(&self) -> Style {
default(self)
}

View file

@ -15,7 +15,7 @@ pub struct Screenshot {
pub size: Size<u32>,
/// The scale factor of the [`Screenshot`]. This can be useful when converting between widget
/// bounds (which are in logical pixels) to crop screenshots.
pub scale_factor: f64,
pub scale_factor: f32,
}
impl Debug for Screenshot {
@ -35,7 +35,7 @@ impl Screenshot {
pub fn new(
bytes: impl Into<Bytes>,
size: Size<u32>,
scale_factor: f64,
scale_factor: f32,
) -> Self {
Self {
bytes: bytes.into(),