Encode rem values derived from pixels using rems_from_px (#9367)

This PR adds a new `rems_from_px` helper function that can be used to
compute rem values based on a pixel value.

This is something we do fairly commonly, where we want to express a size
that is a given pixel size at the base rem size (e.g., "14px when the
rem size is 16px").

`rems_from_px` helps make the intent more explicit, as well as prevent
the base rem size from being duplicated everywhere.

Note: Ideally we would want `rems_from_px` to be `const`, but that
depends on https://github.com/rust-lang/rust/issues/57241.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-03-14 16:39:55 -04:00 committed by GitHub
parent a78576a6db
commit 404adbce5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 54 additions and 35 deletions

View file

@ -1,5 +1,5 @@
use crate::{h_flex, prelude::*, Icon, IconName, IconSize};
use gpui::{relative, rems, Action, FocusHandle, IntoElement, Keystroke};
use gpui::{relative, Action, FocusHandle, IntoElement, Keystroke};
/// The way a [`KeyBinding`] should be displayed.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
@ -158,12 +158,15 @@ impl RenderOnce for Key {
.py_0()
.map(|this| {
if single_char {
this.w(rems(14. / 16.)).flex().flex_none().justify_center()
this.w(rems_from_px(14.))
.flex()
.flex_none()
.justify_center()
} else {
this.px_0p5()
}
})
.h(rems(14. / 16.))
.h(rems_from_px(14.))
.text_ui()
.line_height(relative(1.))
.text_color(cx.theme().colors().text_muted)
@ -184,7 +187,7 @@ pub struct KeyIcon {
impl RenderOnce for KeyIcon {
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
div().w(rems(14. / 16.)).child(
div().w(rems_from_px(14.)).child(
Icon::new(self.icon)
.size(IconSize::Small)
.color(Color::Muted),