From 3ec35929ae9a2e1a808d02135331ff7638840807 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 23 Jul 2024 14:57:16 +0800 Subject: [PATCH] Add font-weight methods to styled: `font_light`, `font_semibold`, `font_bold` ... (#58) https://tailwindcss.com/docs/font-weight --- crates/ui/src/styled_ext.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/ui/src/styled_ext.rs b/crates/ui/src/styled_ext.rs index c83f8a21..015fc3a2 100644 --- a/crates/ui/src/styled_ext.rs +++ b/crates/ui/src/styled_ext.rs @@ -46,6 +46,15 @@ fn elevated(this: E, cx: &WindowContext, index: ElevationIndex) -> E .shadow(index.shadow()) } +macro_rules! font_weight { + ($fn:ident, $const:ident) => { + /// [docs](https://tailwindcss.com/docs/font-weight) + fn $fn(self) -> Self { + self.font_weight(gpui::FontWeight::$const) + } + }; +} + /// Extends [`gpui::Styled`] with specific styling methods. pub trait StyledExt: Styled + Sized { /// Horizontally stacks elements. @@ -139,6 +148,16 @@ pub trait StyledExt: Styled + Sized { fn outline(self, cx: &WindowContext) -> Self { self.border_color(cx.theme().ring) } + + font_weight!(font_thin, THIN); + font_weight!(font_extralight, EXTRA_LIGHT); + font_weight!(font_light, LIGHT); + font_weight!(font_normal, NORMAL); + font_weight!(font_medium, MEDIUM); + font_weight!(font_semibold, SEMIBOLD); + font_weight!(font_bold, BOLD); + font_weight!(font_extrabold, EXTRA_BOLD); + font_weight!(font_black, BLACK); } impl StyledExt for E {}