Element refinement passing on ui2

This commit is contained in:
Nathan Sobo 2023-11-18 20:05:47 -07:00
parent be33f000e2
commit adc355a1e6
87 changed files with 2066 additions and 1372 deletions

View file

@ -1,4 +1,4 @@
use gpui::{rems, svg};
use gpui::{rems, svg, RenderOnce, Svg};
use strum::EnumIter;
use crate::prelude::*;
@ -129,13 +129,30 @@ impl Icon {
}
}
#[derive(Component)]
#[derive(RenderOnce)]
pub struct IconElement {
path: SharedString,
color: TextColor,
size: IconSize,
}
impl<V: 'static> Component<V> for IconElement {
type Rendered = Svg<V>;
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
let svg_size = match self.size {
IconSize::Small => rems(0.75),
IconSize::Medium => rems(0.9375),
};
svg()
.size(svg_size)
.flex_none()
.path(self.path)
.text_color(self.color.color(cx))
}
}
impl IconElement {
pub fn new(icon: Icon) -> Self {
Self {
@ -191,7 +208,7 @@ mod stories {
pub struct IconStory;
impl Render for IconStory {
impl Render<Self> for IconStory {
type Element = Div<Self>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {