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, }
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
///|
|
||||
test "font builders" {
|
||||
let f = @font.font("Zed Sans").bold().italic()
|
||||
assert_eq(f.family, "Zed Sans")
|
||||
assert_eq(f.weight, @font.font_weight_bold)
|
||||
assert_eq(f.style, Italic)
|
||||
let d : @font.Font = Default::default()
|
||||
assert_eq(d.family, ".SystemUIFont")
|
||||
assert_eq(d.weight, @font.FontWeight(400.0))
|
||||
assert_true(@font.font_weight_light < @font.font_weight_semibold)
|
||||
}
|
||||
|
||||
///|
|
||||
test "font features" {
|
||||
assert_eq(
|
||||
@font.FontFeatures::disable_ligatures().is_calt_enabled(),
|
||||
Some(false),
|
||||
)
|
||||
assert_eq(@font.FontFeatures([("calt", 1)]).is_calt_enabled(), Some(true))
|
||||
assert_eq((Default::default() : @font.FontFeatures).is_calt_enabled(), None)
|
||||
assert_eq(@font.FontFallbacks::from_fonts(["A", "B"]).fallback_list(), [
|
||||
"A", "B",
|
||||
])
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
// Generated using `moon info`, DON'T EDIT IT
|
||||
package "experiments/gpui/font"
|
||||
|
||||
import {
|
||||
"moonbitlang/core/debug",
|
||||
}
|
||||
|
||||
// Values
|
||||
pub fn font(String) -> Font
|
||||
|
||||
pub let font_weight_black : FontWeight
|
||||
|
||||
pub let font_weight_bold : FontWeight
|
||||
|
||||
pub let font_weight_extra_bold : FontWeight
|
||||
|
||||
pub let font_weight_extra_light : FontWeight
|
||||
|
||||
pub let font_weight_light : FontWeight
|
||||
|
||||
pub let font_weight_medium : FontWeight
|
||||
|
||||
pub let font_weight_normal : FontWeight
|
||||
|
||||
pub let font_weight_semibold : FontWeight
|
||||
|
||||
pub let font_weight_thin : FontWeight
|
||||
|
||||
pub let system_ui_font : String
|
||||
|
||||
// Errors
|
||||
|
||||
// Types and methods
|
||||
#derive(Eq, Hash, @debug.Debug)
|
||||
pub(all) struct Font {
|
||||
family : String
|
||||
features : FontFeatures
|
||||
fallbacks : FontFallbacks?
|
||||
weight : FontWeight
|
||||
style : FontStyle
|
||||
}
|
||||
pub fn Font::bold(Self) -> Self
|
||||
pub fn Font::italic(Self) -> Self
|
||||
pub impl Default for Font
|
||||
|
||||
#derive(Default, Eq, Hash, @debug.Debug)
|
||||
pub(all) struct FontFallbacks(Array[String])
|
||||
pub fn FontFallbacks::fallback_list(Self) -> Array[String]
|
||||
pub fn FontFallbacks::from_fonts(Array[String]) -> Self
|
||||
|
||||
#derive(Default, Eq, Hash, @debug.Debug)
|
||||
pub(all) struct FontFeatures(Array[(String, Int32)])
|
||||
pub fn FontFeatures::disable_ligatures() -> Self
|
||||
pub fn FontFeatures::is_calt_enabled(Self) -> Bool?
|
||||
pub fn FontFeatures::tag_value_list(Self) -> Array[(String, Int32)]
|
||||
|
||||
#derive(Eq, Hash, @debug.Debug)
|
||||
pub(all) enum FontStyle {
|
||||
Normal
|
||||
Italic
|
||||
Oblique
|
||||
}
|
||||
pub impl Default for FontStyle
|
||||
|
||||
#derive(Compare, Eq, Hash, @debug.Debug)
|
||||
pub(all) struct FontWeight(Double)
|
||||
pub impl Default for FontWeight
|
||||
pub impl Show for FontWeight
|
||||
|
||||
// Type aliases
|
||||
|
||||
// Traits
|
||||
Reference in new issue
Block a user