icon_external/
icon_external.rs1use gpui::{
2 App, AppContext, Application, Bounds, Context, Entity, IntoElement, ParentElement, Render,
3 Size as GpuiSize, Styled, Window, WindowBounds, WindowOptions, div, px,
4};
5use rust_embed::RustEmbed;
6use woocraft::{
7 ActiveTheme, CombinedSource, EmbeddedSource, Icon, IconName, StyledExt, h_flex, init,
8 register_icon, v_flex,
9};
10
11#[derive(RustEmbed)]
12#[folder = "examples/assets"]
13#[include = "external/**/*.svg"]
14struct ExternalAssets;
15
16#[derive(Default)]
17struct ExternalIconWindow;
18
19impl ExternalIconWindow {
20 fn view(cx: &mut App) -> Entity<Self> {
21 cx.new(|_| Self)
22 }
23}
24
25impl Render for ExternalIconWindow {
26 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
27 v_flex()
28 .size_full()
29 .p_6()
30 .gap_4()
31 .bg(cx.theme().background)
32 .text_color(cx.theme().foreground)
33 .child(
34 div()
35 .text_xl()
36 .font_semibold()
37 .child("Woocraft External Icon Source"),
38 )
39 .child(
40 div()
41 .text_sm()
42 .text_color(cx.theme().muted_foreground)
43 .child(
44 "Built-in assets use tech.woooo.woocraft/assets/* and external assets use external/*.",
45 ),
46 )
47 .child(
48 h_flex()
49 .gap_6()
50 .items_center()
51 .child(
52 v_flex()
53 .gap_2()
54 .items_center()
55 .child(Icon::new(IconName::Apps).size_10())
56 .child(div().text_sm().child("Built-in icon")),
57 )
58 .child(
59 v_flex()
60 .gap_2()
61 .items_center()
62 .child(Icon::new("external/star.svg").size_10())
63 .child(div().text_sm().child("External path icon")),
64 )
65 .child(
66 v_flex()
67 .gap_2()
68 .items_center()
69 .child(Icon::new("external-star").size_10())
70 .child(div().text_sm().child("External alias icon")),
71 ),
72 )
73 }
74}
75
76fn main() {
77 let assets = CombinedSource::new()
78 .with(woocraft::Assets)
79 .with(EmbeddedSource::<ExternalAssets>::new());
80
81 let app = Application::new().with_assets(assets);
82
83 app.run(|cx: &mut App| {
84 init(cx);
85 cx.activate(true);
86
87 register_icon("external-star", "external/star.svg");
88
89 let bounds = Bounds::centered(None, GpuiSize::new(px(760.), px(420.)), cx);
90 let window = cx
91 .open_window(
92 WindowOptions {
93 window_bounds: Some(WindowBounds::Windowed(bounds)),
94 ..Default::default()
95 },
96 |_window, cx| ExternalIconWindow::view(cx),
97 )
98 .expect("open external icon demo window failed");
99
100 window
101 .update(cx, |_, window, _| {
102 window.activate_window();
103 window.set_window_title("Woocraft External Icon Example");
104 })
105 .expect("update external icon demo window failed");
106 });
107}