damascene-core 0.6.0

Damascene — backend-agnostic UI library core
Documentation
//! Text constructors.
//!
//! [`text`] is default body text. [`h1`] / [`h2`] / [`h3`] are heading
//! constructors used directly.
//!
//! Modifiers (`.muted`, `.bold`, `.semibold`, `.small`, `.color`, etc.)
//! are inherent methods on [`El`]; see [`crate::style`].

// Lock in full per-item documentation for this module (issue #73).
#![warn(missing_docs)]

use std::panic::Location;

use crate::style::StyleProfile;
use crate::tree::*;

/// Default body text leaf — single-line, hug-sized, [`TextRole::Body`].
#[track_caller]
pub fn text(s: impl Into<String>) -> El {
    El::new(Kind::Text)
        .at_loc(Location::caller())
        .style_profile(StyleProfile::TextOnly)
        .text(s)
        .text_role(TextRole::Body)
        .hug()
}

/// Body text that wraps — full-width with wrapping enabled, like an HTML `<p>`.
#[track_caller]
pub fn paragraph(s: impl Into<String>) -> El {
    text(s)
        .at_loc(Location::caller())
        .wrap_text()
        .fill_width()
        .height(Size::Hug)
}

/// Top-level heading ([`TextRole::Display`]) — like an HTML `<h1>`.
#[track_caller]
pub fn h1(s: impl Into<String>) -> El {
    El::new(Kind::Heading)
        .at_loc(Location::caller())
        .style_profile(StyleProfile::TextOnly)
        .text(s)
        .text_role(TextRole::Display)
        .hug()
}

/// Section heading ([`TextRole::Heading`]) — like an HTML `<h2>`.
#[track_caller]
pub fn h2(s: impl Into<String>) -> El {
    El::new(Kind::Heading)
        .at_loc(Location::caller())
        .style_profile(StyleProfile::TextOnly)
        .text(s)
        .text_role(TextRole::Heading)
        .hug()
}

/// Subsection heading ([`TextRole::Title`]) — like an HTML `<h3>`.
#[track_caller]
pub fn h3(s: impl Into<String>) -> El {
    El::new(Kind::Heading)
        .at_loc(Location::caller())
        .style_profile(StyleProfile::TextOnly)
        .text(s)
        .text_role(TextRole::Title)
        .hug()
}

/// Inline monospace text — body text with the `.code()` modifier applied, like an HTML `<code>`.
#[track_caller]
pub fn mono(s: impl Into<String>) -> El {
    text(s).code()
}