Add style, font, and card example packages; extend geometry and color
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8c0685fe01
commit
1e2bcde532
26 files changed
+45666
-30
No files matched your search
@@ -0,0 +1,146 @@
|
||||
// Font descriptors, ported from gpui/src/text_system.rs and
|
||||
// text_system/{font_features,font_fallbacks}.rs. Font loading, metrics and
|
||||
// shaping belong to the text-system milestone (M9).
|
||||
|
||||
///|
|
||||
/// The weight of a font, from 100 (thin) to 900 (black).
|
||||
#derive(Eq, Compare, Hash, Debug)
|
||||
pub(all) struct FontWeight(Double)
|
||||
|
||||
///|
|
||||
pub let font_weight_thin : FontWeight = FontWeight(100.0)
|
||||
|
||||
///|
|
||||
pub let font_weight_extra_light : FontWeight = FontWeight(200.0)
|
||||
|
||||
///|
|
||||
pub let font_weight_light : FontWeight = FontWeight(300.0)
|
||||
|
||||
///|
|
||||
pub let font_weight_normal : FontWeight = FontWeight(400.0)
|
||||
|
||||
///|
|
||||
pub let font_weight_medium : FontWeight = FontWeight(500.0)
|
||||
|
||||
///|
|
||||
pub let font_weight_semibold : FontWeight = FontWeight(600.0)
|
||||
|
||||
///|
|
||||
pub let font_weight_bold : FontWeight = FontWeight(700.0)
|
||||
|
||||
///|
|
||||
pub let font_weight_extra_bold : FontWeight = FontWeight(800.0)
|
||||
|
||||
///|
|
||||
pub let font_weight_black : FontWeight = FontWeight(900.0)
|
||||
|
||||
///|
|
||||
pub impl Default for FontWeight with fn default() {
|
||||
font_weight_normal
|
||||
}
|
||||
|
||||
///|
|
||||
pub impl Show for FontWeight with fn output(self, logger) {
|
||||
logger.write_string(self.0.to_string())
|
||||
}
|
||||
|
||||
///|
|
||||
/// The slant of a font face.
|
||||
#derive(Eq, Hash, Debug)
|
||||
pub(all) enum FontStyle {
|
||||
Normal
|
||||
Italic
|
||||
Oblique
|
||||
}
|
||||
|
||||
///|
|
||||
pub impl Default for FontStyle with fn default() {
|
||||
Normal
|
||||
}
|
||||
|
||||
///|
|
||||
/// OpenType feature settings, as `(tag, value)` pairs. Treat as immutable.
|
||||
#derive(Eq, Hash, Default, Debug)
|
||||
pub(all) struct FontFeatures(Array[(String, Int32)])
|
||||
|
||||
///|
|
||||
/// Disables contextual alternates (`calt`), which turns off ligatures.
|
||||
pub fn FontFeatures::disable_ligatures() -> FontFeatures {
|
||||
FontFeatures([("calt", 0)])
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn FontFeatures::tag_value_list(
|
||||
self : FontFeatures,
|
||||
) -> Array[(String, Int32)] {
|
||||
self.0
|
||||
}
|
||||
|
||||
///|
|
||||
/// Whether `calt` is enabled; `None` if the feature is not set.
|
||||
pub fn FontFeatures::is_calt_enabled(self : FontFeatures) -> Bool? {
|
||||
for entry in self.0 {
|
||||
let (tag, value) = entry
|
||||
if tag == "calt" {
|
||||
return Some(value == 1)
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
///|
|
||||
/// Font families to try, in order, when the primary family lacks a glyph.
|
||||
#derive(Eq, Hash, Default, Debug)
|
||||
pub(all) struct FontFallbacks(Array[String])
|
||||
|
||||
///|
|
||||
pub fn FontFallbacks::from_fonts(fonts : Array[String]) -> FontFallbacks {
|
||||
FontFallbacks(fonts)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn FontFallbacks::fallback_list(self : FontFallbacks) -> Array[String] {
|
||||
self.0
|
||||
}
|
||||
|
||||
///|
|
||||
/// The name GPUI uses for the platform's UI font.
|
||||
pub let system_ui_font : String = ".SystemUIFont"
|
||||
|
||||
///|
|
||||
/// A font: a family plus the properties used to select a face.
|
||||
#derive(Eq, Hash, Debug)
|
||||
pub(all) struct Font {
|
||||
family : String
|
||||
features : FontFeatures
|
||||
fallbacks : FontFallbacks?
|
||||
weight : FontWeight
|
||||
style : FontStyle
|
||||
}
|
||||
|
||||
///|
|
||||
/// A regular-weight, upright font of `family`.
|
||||
pub fn font(family : String) -> Font {
|
||||
{
|
||||
family,
|
||||
features: Default::default(),
|
||||
fallbacks: None,
|
||||
weight: Default::default(),
|
||||
style: Normal,
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
pub impl Default for Font with fn default() {
|
||||
font(system_ui_font)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Font::bold(self : Font) -> Font {
|
||||
{ ..self, weight: font_weight_bold, }
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Font::italic(self : Font) -> Font {
|
||||
{ ..self, style: Italic, }
|
||||
}
|
||||
Reference in new issue
Block a user