mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-06 02:37:21 +00:00
Use the already existing styles/typography for Headline
This commit is contained in:
parent
dcb9c0b9d8
commit
d1445431f2
3 changed files with 71 additions and 74 deletions
|
@ -16,7 +16,6 @@ mod stack;
|
|||
mod tab;
|
||||
mod tab_bar;
|
||||
mod tooltip;
|
||||
mod typography;
|
||||
|
||||
#[cfg(feature = "stories")]
|
||||
mod stories;
|
||||
|
@ -39,7 +38,6 @@ pub use stack::*;
|
|||
pub use tab::*;
|
||||
pub use tab_bar::*;
|
||||
pub use tooltip::*;
|
||||
pub use typography::*;
|
||||
|
||||
#[cfg(feature = "stories")]
|
||||
pub use stories::*;
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
use gpui::{
|
||||
div, rems, IntoElement, ParentElement, Rems, RenderOnce, SharedString, Styled, WindowContext,
|
||||
};
|
||||
use settings::Settings;
|
||||
use theme::{ActiveTheme, ThemeSettings};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Default)]
|
||||
pub enum HeadlineSize {
|
||||
XSmall,
|
||||
Small,
|
||||
#[default]
|
||||
Medium,
|
||||
Large,
|
||||
XLarge,
|
||||
}
|
||||
|
||||
impl HeadlineSize {
|
||||
pub fn size(self) -> Rems {
|
||||
match self {
|
||||
// Based on the Major Second scale
|
||||
Self::XSmall => rems(0.88),
|
||||
Self::Small => rems(1.0),
|
||||
Self::Medium => rems(1.125),
|
||||
Self::Large => rems(1.27),
|
||||
Self::XLarge => rems(1.43),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn line_height(self) -> Rems {
|
||||
match self {
|
||||
Self::XSmall => rems(1.6),
|
||||
Self::Small => rems(1.6),
|
||||
Self::Medium => rems(1.6),
|
||||
Self::Large => rems(1.6),
|
||||
Self::XLarge => rems(1.6),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(IntoElement)]
|
||||
pub struct Headline {
|
||||
size: HeadlineSize,
|
||||
text: SharedString,
|
||||
}
|
||||
|
||||
impl RenderOnce for Headline {
|
||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
let ui_font = ThemeSettings::get_global(cx).ui_font.family.clone();
|
||||
|
||||
div()
|
||||
.font(ui_font)
|
||||
.line_height(self.size.line_height())
|
||||
.text_size(self.size.size())
|
||||
.text_color(cx.theme().colors().text)
|
||||
.child(self.text)
|
||||
}
|
||||
}
|
||||
|
||||
impl Headline {
|
||||
pub fn new(text: impl Into<SharedString>) -> Self {
|
||||
Self {
|
||||
size: HeadlineSize::default(),
|
||||
text: text.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn size(mut self, size: HeadlineSize) -> Self {
|
||||
self.size = size;
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,4 +1,8 @@
|
|||
use gpui::{rems, Rems};
|
||||
use gpui::{
|
||||
div, rems, IntoElement, ParentElement, Rems, RenderOnce, SharedString, Styled, WindowContext,
|
||||
};
|
||||
use settings::Settings;
|
||||
use theme::{ActiveTheme, ThemeSettings};
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub enum UiTextSize {
|
||||
|
@ -33,3 +37,69 @@ impl UiTextSize {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Default)]
|
||||
pub enum HeadlineSize {
|
||||
XSmall,
|
||||
Small,
|
||||
#[default]
|
||||
Medium,
|
||||
Large,
|
||||
XLarge,
|
||||
}
|
||||
|
||||
impl HeadlineSize {
|
||||
pub fn size(self) -> Rems {
|
||||
match self {
|
||||
// Based on the Major Second scale
|
||||
Self::XSmall => rems(0.88),
|
||||
Self::Small => rems(1.0),
|
||||
Self::Medium => rems(1.125),
|
||||
Self::Large => rems(1.27),
|
||||
Self::XLarge => rems(1.43),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn line_height(self) -> Rems {
|
||||
match self {
|
||||
Self::XSmall => rems(1.6),
|
||||
Self::Small => rems(1.6),
|
||||
Self::Medium => rems(1.6),
|
||||
Self::Large => rems(1.6),
|
||||
Self::XLarge => rems(1.6),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(IntoElement)]
|
||||
pub struct Headline {
|
||||
size: HeadlineSize,
|
||||
text: SharedString,
|
||||
}
|
||||
|
||||
impl RenderOnce for Headline {
|
||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||
let ui_font = ThemeSettings::get_global(cx).ui_font.family.clone();
|
||||
|
||||
div()
|
||||
.font(ui_font)
|
||||
.line_height(self.size.line_height())
|
||||
.text_size(self.size.size())
|
||||
.text_color(cx.theme().colors().text)
|
||||
.child(self.text)
|
||||
}
|
||||
}
|
||||
|
||||
impl Headline {
|
||||
pub fn new(text: impl Into<SharedString>) -> Self {
|
||||
Self {
|
||||
size: HeadlineSize::default(),
|
||||
text: text.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn size(mut self, size: HeadlineSize) -> Self {
|
||||
self.size = size;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue