add toast
This commit is contained in:
+9
-17
@@ -7,12 +7,11 @@
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AssetSource, Hsla, IntoElement, ParentElement as _, RenderOnce, SharedString, Styled as _,
|
||||
Window, div, px, svg,
|
||||
AssetSource, Hsla, IntoElement, ParentElement as _, Pixels, RenderOnce, SharedString,
|
||||
Styled as _, Window, div, px, svg,
|
||||
};
|
||||
|
||||
/// The semantic glyphs UI components need. Grows one role at a time as
|
||||
/// components call for it.
|
||||
/// The semantic glyphs UI components need.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum IconRole {
|
||||
Check,
|
||||
@@ -65,12 +64,11 @@ impl IconRole {
|
||||
}
|
||||
}
|
||||
|
||||
/// An icon element. Unpainted unless a color is set (gpui paints SVGs from
|
||||
/// the element's text color only).
|
||||
/// An icon element. Unpainted unless a color is set.
|
||||
#[derive(IntoElement)]
|
||||
pub struct Icon {
|
||||
role: IconRole,
|
||||
size: f32,
|
||||
size: Pixels,
|
||||
color: Option<Hsla>,
|
||||
}
|
||||
|
||||
@@ -78,13 +76,13 @@ pub struct Icon {
|
||||
pub fn icon(role: IconRole) -> Icon {
|
||||
Icon {
|
||||
role,
|
||||
size: 16.0,
|
||||
size: px(16.0),
|
||||
color: None,
|
||||
}
|
||||
}
|
||||
|
||||
impl Icon {
|
||||
pub fn size(mut self, size: f32) -> Self {
|
||||
pub fn size(mut self, size: Pixels) -> Self {
|
||||
self.size = size;
|
||||
self
|
||||
}
|
||||
@@ -97,7 +95,7 @@ impl Icon {
|
||||
|
||||
impl RenderOnce for Icon {
|
||||
fn render(self, _window: &mut Window, _cx: &mut gpui::App) -> impl IntoElement {
|
||||
div().flex_none().size(px(self.size)).child(
|
||||
div().flex_none().size(self.size).child(
|
||||
svg()
|
||||
.size_full()
|
||||
.path(self.role.asset_path())
|
||||
@@ -106,8 +104,7 @@ impl RenderOnce for Icon {
|
||||
}
|
||||
}
|
||||
|
||||
/// The asset source serving this crate's bundled glyphs. Register it on the
|
||||
/// application: `application().with_assets(IconAssets)`.
|
||||
/// The asset source serving this crate's bundled glyphs.
|
||||
pub struct IconAssets;
|
||||
|
||||
fn asset_bytes(path: &str) -> Option<&'static [u8]> {
|
||||
@@ -158,9 +155,4 @@ mod tests {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_assets_report_none() {
|
||||
assert_eq!(asset_bytes("icons/nope.svg"), None);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user