Allows anchoring background images via `background.position`: `center` (default), `top_left`, `top_right`, `bottom_left`, `bottom_right`, matching CSS `background-position` semantics. Also adds `none` to `background.fit` to keep the original image size, making watermark-style bottom-right or corner positioning possible without stretching or cover cropping.
91 lines
3.2 KiB
Rust
91 lines
3.2 KiB
Rust
use schemars::JsonSchema;
|
|
use serde::{Deserialize, Serialize};
|
|
use settings_macros::MergeFrom;
|
|
|
|
/// Determines how the workspace background image is fitted into the window bounds.
|
|
///
|
|
#[derive(
|
|
Copy, Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema, MergeFrom,
|
|
strum::VariantArray, strum::VariantNames,
|
|
)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum BackgroundImageFit {
|
|
/// The image is scaled to cover the entire workspace bounds.
|
|
#[default]
|
|
Cover,
|
|
/// The image is stretched to fill the workspace bounds.
|
|
Fill,
|
|
/// The image is scaled to fit entirely within the workspace bounds.
|
|
Contain,
|
|
/// The image keeps its original size; `position` decides which part is
|
|
/// visible.
|
|
None,
|
|
}
|
|
|
|
/// Determines where the workspace background image is anchored.
|
|
///
|
|
/// Default: center
|
|
#[derive(
|
|
Copy, Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema, MergeFrom,
|
|
strum::VariantArray, strum::VariantNames,
|
|
)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum BackgroundImagePosition {
|
|
/// The image is centered within the workspace bounds.
|
|
#[default]
|
|
Center,
|
|
/// The image is anchored to the top-left corner.
|
|
TopLeft,
|
|
/// The image is anchored to the top-right corner.
|
|
TopRight,
|
|
/// The image is anchored to the bottom-left corner.
|
|
BottomLeft,
|
|
/// The image is anchored to the bottom-right corner.
|
|
BottomRight,
|
|
}
|
|
|
|
impl BackgroundImagePosition {
|
|
/// Returns the anchor point as (x, y) ratios of the overflow area,
|
|
/// matching CSS `background-position` semantics.
|
|
pub fn ratio(self) -> (f32, f32) {
|
|
match self {
|
|
BackgroundImagePosition::Center => (0.5, 0.5),
|
|
BackgroundImagePosition::TopLeft => (0.0, 0.0),
|
|
BackgroundImagePosition::TopRight => (1.0, 0.0),
|
|
BackgroundImagePosition::BottomLeft => (0.0, 1.0),
|
|
BackgroundImagePosition::BottomRight => (1.0, 1.0),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Settings for the image displayed behind the workspace UI.
|
|
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
|
|
pub struct BackgroundImageSettingsContent {
|
|
/// The path to the image file to display behind the workspace UI.
|
|
///
|
|
/// `~` and environment variables are expanded. When `null`, no background
|
|
/// image is displayed.
|
|
pub path: Option<String>,
|
|
|
|
/// How the image is fitted into the workspace bounds: "cover", "fill",
|
|
/// "contain" or "none" (original size).
|
|
///
|
|
/// Default: cover
|
|
pub fit: Option<BackgroundImageFit>,
|
|
|
|
/// Where the image is anchored within the workspace bounds: "center",
|
|
/// "top_left", "top_right", "bottom_left" or "bottom_right". Controls
|
|
/// which part of the image is visible when it overflows the bounds.
|
|
///
|
|
/// Default: center
|
|
pub position: Option<BackgroundImagePosition>,
|
|
|
|
/// The opacity of the editor and terminal surfaces drawn on top of the
|
|
/// image, between 0.0 (surfaces fully transparent, image fully visible)
|
|
/// and 1.0 (surfaces fully opaque, image hidden). Lower values let the
|
|
/// image show through the code area; text and chrome stay unaffected.
|
|
///
|
|
/// Default: 0.15
|
|
pub opacity: Option<f32>,
|
|
}
|