forked from zed-industries/zed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…ed-industries#23157) This PR moves the `IconDecoration` and `DecoratedIcon` components to their own modules. Release Notes: - N/A
- Loading branch information
1 parent
167c564
commit de6216a
Showing
3 changed files
with
266 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use gpui::{IntoElement, Point}; | ||
|
||
use crate::{ | ||
prelude::*, traits::component_preview::ComponentPreview, IconDecoration, IconDecorationKind, | ||
}; | ||
|
||
#[derive(IntoElement)] | ||
pub struct DecoratedIcon { | ||
icon: Icon, | ||
decoration: Option<IconDecoration>, | ||
} | ||
|
||
impl DecoratedIcon { | ||
pub fn new(icon: Icon, decoration: Option<IconDecoration>) -> Self { | ||
Self { icon, decoration } | ||
} | ||
} | ||
|
||
impl RenderOnce for DecoratedIcon { | ||
fn render(self, _cx: &mut WindowContext) -> impl IntoElement { | ||
div() | ||
.relative() | ||
.size(self.icon.size) | ||
.child(self.icon) | ||
.children(self.decoration) | ||
} | ||
} | ||
|
||
impl ComponentPreview for DecoratedIcon { | ||
fn examples(cx: &mut WindowContext) -> Vec<ComponentExampleGroup<Self>> { | ||
let icon_1 = Icon::new(IconName::FileDoc); | ||
let icon_2 = Icon::new(IconName::FileDoc); | ||
let icon_3 = Icon::new(IconName::FileDoc); | ||
let icon_4 = Icon::new(IconName::FileDoc); | ||
|
||
let decoration_x = IconDecoration::new( | ||
IconDecorationKind::X, | ||
cx.theme().colors().surface_background, | ||
cx, | ||
) | ||
.color(cx.theme().status().error) | ||
.position(Point { | ||
x: px(-2.), | ||
y: px(-2.), | ||
}); | ||
|
||
let decoration_triangle = IconDecoration::new( | ||
IconDecorationKind::Triangle, | ||
cx.theme().colors().surface_background, | ||
cx, | ||
) | ||
.color(cx.theme().status().error) | ||
.position(Point { | ||
x: px(-2.), | ||
y: px(-2.), | ||
}); | ||
|
||
let decoration_dot = IconDecoration::new( | ||
IconDecorationKind::Dot, | ||
cx.theme().colors().surface_background, | ||
cx, | ||
) | ||
.color(cx.theme().status().error) | ||
.position(Point { | ||
x: px(-2.), | ||
y: px(-2.), | ||
}); | ||
|
||
let examples = vec![ | ||
single_example("no_decoration", DecoratedIcon::new(icon_1, None)), | ||
single_example( | ||
"with_decoration", | ||
DecoratedIcon::new(icon_2, Some(decoration_x)), | ||
), | ||
single_example( | ||
"with_decoration", | ||
DecoratedIcon::new(icon_3, Some(decoration_triangle)), | ||
), | ||
single_example( | ||
"with_decoration", | ||
DecoratedIcon::new(icon_4, Some(decoration_dot)), | ||
), | ||
]; | ||
|
||
vec![example_group(examples)] | ||
} | ||
} |
Oops, something went wrong.