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,
) {
// 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
.entry(sprite.atlas_id)
.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 {
fn from(color: Rgba) -> Self {
let r = color.r;

View file

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

View file

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

View file

@ -1,8 +1,9 @@
use crate::{collab_panel::collab_panel, theme::theme};
use gpui2::{
black,
elements::{div, div::ScrollState, img, svg},
style::{StyleHelpers, Styleable},
Element, IntoElement, ParentElement, ViewContext,
white, Element, IntoElement, ParentElement, ViewContext,
};
#[derive(Element, Default)]
@ -19,29 +20,37 @@ impl WorkspaceElement {
fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
let theme = theme(cx);
div()
return div()
.size_full()
.flex()
.flex_col()
.font("Zed Sans Extended")
.gap_0()
.justify_start()
.items_start()
.text_color(theme.lowest.base.default.foreground)
.fill(theme.middle.base.default.background)
.child(titlebar())
.child(
div()
.flex_1()
.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())
.fill(white())
.font("Helvetica")
.text_base()
.text_color(black())
.child("Hey");
// div()
// .size_full()
// .flex()
// .flex_col()
// .font("Zed Sans Extended")
// .gap_0()
// .justify_start()
// .items_start()
// .text_color(theme.lowest.base.default.foreground)
// .fill(theme.middle.base.default.background)
// .child(titlebar())
// .child(
// div()
// .flex_1()
// .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,
};
use gpui3::{
div, img, svg, view, white, Context, Element, ParentElement, RootView, StyleHelpers, View,
ViewContext, WindowContext,
black, div, img, svg, view, white, Context, Element, ParentElement, RootView, StyleHelpers,
View, ViewContext, WindowContext,
};
pub struct Workspace {
@ -28,12 +28,12 @@ impl Workspace {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<State = Self> {
let theme = rose_pine_dawn();
div()
.font("Helvetica")
.text_color(white())
.text_base()
.size_full()
.fill(theme.middle.base.default.background)
.child("Hello world")
.font("Helvetica")
.text_base()
.fill(white())
.text_color(black())
.child("Hey")
// TODO: Implement style.
//.size_full().fill(gpui3::hsla(0.83, 1., 0.5, 1.))