This commit is contained in:
Nathan Sobo 2023-10-03 14:25:29 -06:00
parent d3916b84c9
commit 45429b5400
6 changed files with 63 additions and 39 deletions

View file

@ -631,7 +631,9 @@ impl Renderer {
glyph.origin, glyph.origin,
) { ) {
// Snap sprite to pixel grid. // Snap sprite to pixel grid.
let origin = (glyph.origin * scale_factor).floor() + sprite.offset.to_f32(); let origin = dbg!(
dbg!((glyph.origin * scale_factor).floor()) + dbg!(sprite.offset.to_f32())
);
sprites_by_atlas sprites_by_atlas
.entry(sprite.atlas_id) .entry(sprite.atlas_id)
.or_insert_with(Vec::new) .or_insert_with(Vec::new)

View file

@ -160,6 +160,15 @@ pub fn black() -> Hsla {
} }
} }
pub fn white() -> Hsla {
Hsla {
h: 0.,
s: 0.,
l: 1.,
a: 1.,
}
}
impl From<Rgba> for Hsla { impl From<Rgba> for Hsla {
fn from(color: Rgba) -> Self { fn from(color: Rgba) -> Self {
let r = color.r; let r = color.r;

View file

@ -484,10 +484,6 @@ impl Pixels {
Self(self.0.round()) Self(self.0.round())
} }
pub fn floor(&self) -> Self {
Self(self.0.floor())
}
pub fn scale(&self, factor: f32) -> ScaledPixels { pub fn scale(&self, factor: f32) -> ScaledPixels {
ScaledPixels(self.0 * factor) ScaledPixels(self.0 * factor)
} }
@ -604,6 +600,12 @@ impl From<u64> for DevicePixels {
#[repr(transparent)] #[repr(transparent)]
pub struct ScaledPixels(pub(crate) f32); pub struct ScaledPixels(pub(crate) f32);
impl ScaledPixels {
pub fn floor(&self) -> Self {
Self(self.0.floor())
}
}
impl Eq for ScaledPixels {} impl Eq for ScaledPixels {}
impl Debug for ScaledPixels { impl Debug for ScaledPixels {

View file

@ -176,10 +176,10 @@ impl<'a, 'w> WindowContext<'a, 'w> {
color: Hsla, color: Hsla,
) -> Result<()> { ) -> Result<()> {
let scale_factor = self.scale_factor(); let scale_factor = self.scale_factor();
let origin = origin.scale(scale_factor); let glyph_origin = origin.scale(scale_factor);
let subpixel_variant = Point { let subpixel_variant = Point {
x: (origin.x.0.fract() * SUBPIXEL_VARIANTS as f32).floor() as u8, x: (glyph_origin.x.0.fract() * SUBPIXEL_VARIANTS as f32).floor() as u8,
y: (origin.y.0.fract() * SUBPIXEL_VARIANTS as f32).floor() as u8, y: (glyph_origin.y.0.fract() * SUBPIXEL_VARIANTS as f32).floor() as u8,
}; };
let params = GlyphRasterizationParams { let params = GlyphRasterizationParams {
font_id, font_id,
@ -193,10 +193,12 @@ impl<'a, 'w> WindowContext<'a, 'w> {
if !raster_bounds.is_zero() { if !raster_bounds.is_zero() {
let layer_id = self.current_layer_id(); let layer_id = self.current_layer_id();
let offset = raster_bounds.origin.map(Into::into);
let bounds = Bounds { let bounds = Bounds {
origin: origin + raster_bounds.origin.map(Into::into), origin: dbg!(dbg!(glyph_origin.map(|px| px.floor())) + dbg!(offset)),
size: raster_bounds.size.map(Into::into), size: raster_bounds.size.map(Into::into),
}; };
let tile = self let tile = self
.window .window
.glyph_atlas .glyph_atlas

View file

@ -1,8 +1,9 @@
use crate::{collab_panel::collab_panel, theme::theme}; use crate::{collab_panel::collab_panel, theme::theme};
use gpui2::{ use gpui2::{
black,
elements::{div, div::ScrollState, img, svg}, elements::{div, div::ScrollState, img, svg},
style::{StyleHelpers, Styleable}, style::{StyleHelpers, Styleable},
Element, IntoElement, ParentElement, ViewContext, white, Element, IntoElement, ParentElement, ViewContext,
}; };
#[derive(Element, Default)] #[derive(Element, Default)]
@ -19,29 +20,37 @@ impl WorkspaceElement {
fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> { fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
let theme = theme(cx); let theme = theme(cx);
div() return div()
.size_full() .size_full()
.flex() .fill(white())
.flex_col() .font("Helvetica")
.font("Zed Sans Extended") .text_base()
.gap_0() .text_color(black())
.justify_start() .child("Hey");
.items_start()
.text_color(theme.lowest.base.default.foreground) // div()
.fill(theme.middle.base.default.background) // .size_full()
.child(titlebar()) // .flex()
.child( // .flex_col()
div() // .font("Zed Sans Extended")
.flex_1() // .gap_0()
.w_full() // .justify_start()
.flex() // .items_start()
.flex_row() // .text_color(theme.lowest.base.default.foreground)
.overflow_hidden() // .fill(theme.middle.base.default.background)
.child(collab_panel(self.left_scroll_state.clone())) // .child(titlebar())
.child(div().h_full().flex_1()) // .child(
.child(collab_panel(self.right_scroll_state.clone())), // div()
) // .flex_1()
.child(statusbar()) // .w_full()
// .flex()
// .flex_row()
// .overflow_hidden()
// .child(collab_panel(self.left_scroll_state.clone()))
// .child(div().h_full().flex_1())
// .child(collab_panel(self.right_scroll_state.clone())),
// )
// .child(statusbar())
} }
} }

View file

@ -4,8 +4,8 @@ use crate::{
themes::rose_pine_dawn, themes::rose_pine_dawn,
}; };
use gpui3::{ use gpui3::{
div, img, svg, view, white, Context, Element, ParentElement, RootView, StyleHelpers, View, black, div, img, svg, view, white, Context, Element, ParentElement, RootView, StyleHelpers,
ViewContext, WindowContext, View, ViewContext, WindowContext,
}; };
pub struct Workspace { pub struct Workspace {
@ -28,12 +28,12 @@ impl Workspace {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<State = Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<State = Self> {
let theme = rose_pine_dawn(); let theme = rose_pine_dawn();
div() div()
.font("Helvetica")
.text_color(white())
.text_base()
.size_full() .size_full()
.fill(theme.middle.base.default.background) .font("Helvetica")
.child("Hello world") .text_base()
.fill(white())
.text_color(black())
.child("Hey")
// TODO: Implement style. // TODO: Implement style.
//.size_full().fill(gpui3::hsla(0.83, 1., 0.5, 1.)) //.size_full().fill(gpui3::hsla(0.83, 1., 0.5, 1.))