use gpui::*; use gpui_component::{ button::{Button, ButtonVariants}, Root, StyledExt, }; pub struct HelloWorld; impl Render for HelloWorld { fn render(&mut self, _: &mut Window, _: &mut Context) -> impl IntoElement { div() .v_flex() .gap_2() .size_full() .items_center() .justify_center() .text_center() .child("Hello, World!") .child( Button::new("ok") .primary() .label("Let's Go!") .on_click(|_, _, _| println!("Clicked!")), ) } } fn main() { let app = Application::new(); app.run(move |cx| { gpui_component::init(cx); cx.activate(true); let mut window_size = size(px(640.), px(480.)); if let Some(display) = cx.primary_display() { let display_size = display.bounds().size; window_size.width = window_size.width.min(display_size.width * 0.85); window_size.height = window_size.height.min(display_size.height * 0.85); } let window_bounds = Bounds::centered(None, window_size, cx); cx.spawn(async move |cx| { let options = WindowOptions { window_bounds: Some(WindowBounds::Windowed(window_bounds)), titlebar: None, window_min_size: Some(gpui::Size { width: px(640.), height: px(480.), }), kind: WindowKind::Normal, #[cfg(target_os = "linux")] window_background: gpui::WindowBackgroundAppearance::Transparent, #[cfg(target_os = "linux")] window_decorations: Some(gpui::WindowDecorations::Client), ..Default::default() }; let window = cx .open_window(options, |window, cx| { let view = cx.new(|_| HelloWorld); cx.new(|cx| Root::new(view.into(), window, cx)) }) .expect("failed to open window"); window .update(cx, |_, window, _| { window.activate_window(); window.set_window_title("Example"); }) .expect("failed to update window"); Ok::<_, anyhow::Error>(()) }) .detach(); }); }