From 4f52cece6900ea4929b305abb74edf6fa712c57d Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Mon, 30 Jun 2025 15:37:43 -0400 Subject: [PATCH] Tidy & set up for pages --- crates/onboarding_ui/src/onboarding_ui.rs | 158 +++++----------------- 1 file changed, 32 insertions(+), 126 deletions(-) diff --git a/crates/onboarding_ui/src/onboarding_ui.rs b/crates/onboarding_ui/src/onboarding_ui.rs index 75a060da6a4367e1b16700b726bed7383920795d..ec01bd3ee767239bb61b705fdbc8e77586a57001 100644 --- a/crates/onboarding_ui/src/onboarding_ui.rs +++ b/crates/onboarding_ui/src/onboarding_ui.rs @@ -129,12 +129,6 @@ pub struct OnboardingUI { current_focus: OnboardingFocus, completed_pages: [bool; 4], - // Page entities - basics_page: Entity, - editing_page: Entity, - ai_setup_page: Entity, - welcome_page: Entity, - // Workspace reference for Item trait workspace: WeakEntity, } @@ -147,68 +141,16 @@ impl Focusable for OnboardingUI { } } -pub struct BasicsPage { - focus_handle: FocusHandle, - parent: WeakEntity, -} - -pub struct EditingPage { - focus_handle: FocusHandle, - parent: WeakEntity, -} - -pub struct AiSetupPage { - focus_handle: FocusHandle, - parent: WeakEntity, -} - -pub struct WelcomePage { - focus_handle: FocusHandle, - parent: WeakEntity, -} - -// Event types for communication between pages and main UI #[derive(Clone)] pub enum OnboardingEvent { PageCompleted(OnboardingPage), } -// Implement EventEmitter for all entities -impl EventEmitter for BasicsPage {} -impl EventEmitter for EditingPage {} -impl EventEmitter for AiSetupPage {} -impl EventEmitter for WelcomePage {} - -impl Focusable for BasicsPage { - fn focus_handle(&self, _cx: &App) -> FocusHandle { - self.focus_handle.clone() - } -} - -impl Focusable for EditingPage { - fn focus_handle(&self, _cx: &App) -> FocusHandle { - self.focus_handle.clone() - } -} - -impl Focusable for AiSetupPage { - fn focus_handle(&self, _cx: &App) -> FocusHandle { - self.focus_handle.clone() - } -} - -impl Focusable for WelcomePage { - fn focus_handle(&self, _cx: &App) -> FocusHandle { - self.focus_handle.clone() - } -} - -// Placeholder Render implementations impl Render for OnboardingUI { fn render( &mut self, - _window: &mut gpui::Window, - _cx: &mut Context, + window: &mut gpui::Window, + cx: &mut Context, ) -> impl gpui::IntoElement { h_flex() .id("onboarding-ui") @@ -218,82 +160,17 @@ impl Render for OnboardingUI { .h(px(500.)) .gap(px(48.)) .child(v_flex().h_full().w(px(256.)).child("nav")) - } -} - -impl Render for BasicsPage { - fn render( - &mut self, - _window: &mut gpui::Window, - _cx: &mut Context, - ) -> impl gpui::IntoElement { - gpui::div() - } -} - -impl Render for EditingPage { - fn render( - &mut self, - _window: &mut gpui::Window, - _cx: &mut Context, - ) -> impl gpui::IntoElement { - gpui::div() - } -} - -impl Render for AiSetupPage { - fn render( - &mut self, - _window: &mut gpui::Window, - _cx: &mut Context, - ) -> impl gpui::IntoElement { - gpui::div() - } -} - -impl Render for WelcomePage { - fn render( - &mut self, - _window: &mut gpui::Window, - _cx: &mut Context, - ) -> impl gpui::IntoElement { - gpui::div() + .child(self.render_active_page(window, cx)) } } impl OnboardingUI { pub fn new(workspace: &Workspace, cx: &mut Context) -> Self { - let parent_handle = cx.entity().downgrade(); - - let basics_page = cx.new(|cx| BasicsPage { - focus_handle: cx.focus_handle(), - parent: parent_handle.clone(), - }); - - let editing_page = cx.new(|cx| EditingPage { - focus_handle: cx.focus_handle(), - parent: parent_handle.clone(), - }); - - let ai_setup_page = cx.new(|cx| AiSetupPage { - focus_handle: cx.focus_handle(), - parent: parent_handle.clone(), - }); - - let welcome_page = cx.new(|cx| WelcomePage { - focus_handle: cx.focus_handle(), - parent: parent_handle.clone(), - }); - Self { focus_handle: cx.focus_handle(), current_page: OnboardingPage::Basics, current_focus: OnboardingFocus::Page, completed_pages: [false; 4], - basics_page, - editing_page, - ai_setup_page, - welcome_page, workspace: workspace.weak_handle(), } } @@ -352,6 +229,35 @@ impl OnboardingUI { self.completed_pages[index] = true; cx.notify(); } + + fn render_active_page( + &mut self, + _window: &mut gpui::Window, + _cx: &mut Context, + ) -> impl gpui::IntoElement { + match self.current_page { + OnboardingPage::Basics => self.render_basics_page(), + OnboardingPage::Editing => self.render_editing_page(), + OnboardingPage::AiSetup => self.render_ai_setup_page(), + OnboardingPage::Welcome => self.render_welcome_page(), + } + } + + fn render_basics_page(&self) -> impl gpui::IntoElement { + v_flex().h_full().w_full().child("Basics Page") + } + + fn render_editing_page(&self) -> impl gpui::IntoElement { + v_flex().h_full().w_full().child("Editing Page") + } + + fn render_ai_setup_page(&self) -> impl gpui::IntoElement { + v_flex().h_full().w_full().child("AI Setup Page") + } + + fn render_welcome_page(&self) -> impl gpui::IntoElement { + v_flex().h_full().w_full().child("Welcome Page") + } } impl Item for OnboardingUI {