change topbar/sidebar layout

This commit is contained in:
Fabrice Bellamy
2026-02-22 10:38:22 +01:00
parent 5f161c8be4
commit a034d0d22e
2 changed files with 100 additions and 122 deletions
-4
View File
@@ -73,12 +73,8 @@ impl<V: 'static> AppSidebar<V> {
.border_color(border_color)
.w(width)
.child({
#[cfg(not(target_os = "macos"))]
let header = h_flex().w_full().items_center().bg(sidebar_bg).pt_4();
#[cfg(target_os = "macos")]
let header = h_flex().w_full().items_center().bg(sidebar_bg).pt_8();
let current_width = width;
let t = ((current_width - px(48.)) / (px(255.) - px(48.))).clamp(0.0, 1.0);
+100 -118
View File
@@ -116,127 +116,109 @@ impl Render for ApplicationRoot {
let dialog_layer = Root::render_dialog_layer(window, cx);
div().size_full().overflow_hidden().child(
let title_bar = TitleBar::new().bg(cx.theme().title_bar).child(
h_flex()
.w_full()
.justify_between()
.bg(cx.theme().title_bar)
.items_center()
.cursor(gpui::CursorStyle::OpenHand)
.child(
Button::new("sidebar_toggle")
.ghost()
.icon(IconName::PanelLeft)
.on_click(cx.listener(|this, _, _, _| {
this.is_sidebar_collapsed = !this.is_sidebar_collapsed;
}))
.tooltip("Toggle Sidebar"),
),
);
let content_area = v_flex()
.min_h(px(0.))
.min_w(px(0.))
.overflow_y_scrollbar()
.flex_grow()
.bg(cx.theme().background)
.child(match self.active_view {
ActiveView::Home => {
HomeView::build(&self.state, cx.theme(), window.bounds().size.width)
.into_any_element()
}
ActiveView::Passkeys => {
let view = self.passkeys_view.get_or_insert_with(|| {
let view = cx.new(|cx| {
PasskeysView::new(
window,
cx,
self.state.device_status.clone(),
self.state.fido_info.clone(),
)
});
cx.subscribe_in(
&view,
window,
|_, _, event: &PasskeysEvent, window, cx| match event {
PasskeysEvent::Notification(msg) => {
window.push_notification(msg.to_string(), cx);
}
PasskeysEvent::CloseDialog => {
window.close_dialog(cx);
}
},
)
.detach();
view
});
view.clone().into_any_element()
}
ActiveView::Configuration => {
let view = self.config_view.get_or_insert_with(|| {
cx.new(|cx| ConfigView::new(window, cx, self.state.device_status.clone()))
});
view.clone().into_any_element()
}
ActiveView::Security => SecurityView::build(cx).into_any_element(),
ActiveView::Logs => {
let view = self
.logs_view
.get_or_insert_with(|| cx.new(|cx| LogsView::new(window, cx)));
view.clone().into_any_element()
}
ActiveView::About => AboutView::build(cx.theme()).into_any_element(),
});
let sidebar = AppSidebar::new(
self.active_view,
self.sidebar_width,
is_sidebar_collapsed,
self.state.clone(),
)
.on_select(|this: &mut Self, view, _, _| {
this.active_view = view;
})
.on_refresh(|this, window, cx| {
this.refresh_device_status(Some(window), cx);
});
#[cfg(target_os = "macos")]
let body = v_flex().size_full().child(title_bar).child(
h_flex()
.size_full()
.child(
AppSidebar::new(
self.active_view,
self.sidebar_width,
is_sidebar_collapsed,
self.state.clone(),
)
.on_select(|this: &mut Self, view, _, _| {
this.active_view = view;
})
.on_refresh(|this, window, cx| {
this.refresh_device_status(Some(window), cx);
})
.render(cx),
)
.child(
v_flex()
.size_full()
.child(TitleBar::new().bg(cx.theme().title_bar).child({
#[cfg(not(target_os = "macos"))]
let container = h_flex();
.child(sidebar.render(cx))
.child(content_area),
);
#[cfg(target_os = "macos")]
let container = {
let offset = self.sidebar_width.min(gpui::px(72.));
h_flex().ml(-offset)
};
#[cfg(not(target_os = "macos"))]
let body = h_flex()
.size_full()
.child(sidebar.render(cx))
.child(v_flex().size_full().child(title_bar).child(content_area));
container
.w_full()
.justify_between()
.bg(cx.theme().title_bar)
.items_center()
.cursor(gpui::CursorStyle::OpenHand)
.child(
Button::new("sidebar_toggle")
.ghost()
.icon(IconName::PanelLeft)
.on_click(cx.listener(|this, _, _, _| {
this.is_sidebar_collapsed = !this.is_sidebar_collapsed;
}))
.tooltip("Toggle Sidebar"),
)
}))
.child(
v_flex()
.min_h(px(0.))
.min_w(px(0.))
.overflow_y_scrollbar()
.flex_grow()
.bg(cx.theme().background)
.child(match self.active_view {
ActiveView::Home => HomeView::build(
&self.state,
cx.theme(),
window.bounds().size.width,
)
.into_any_element(),
ActiveView::Passkeys => {
let view = self.passkeys_view.get_or_insert_with(|| {
let view = cx.new(|cx| {
PasskeysView::new(
window,
cx,
self.state.device_status.clone(),
self.state.fido_info.clone(),
)
});
cx.subscribe_in(
&view,
window,
|_, _, event: &PasskeysEvent, window, cx| {
match event {
PasskeysEvent::Notification(msg) => {
window.push_notification(
msg.to_string(),
cx,
);
}
PasskeysEvent::CloseDialog => {
window.close_dialog(cx);
}
}
},
)
.detach();
view
});
view.clone().into_any_element()
}
ActiveView::Configuration => {
let view = self.config_view.get_or_insert_with(|| {
cx.new(|cx| {
ConfigView::new(
window,
cx,
self.state.device_status.clone(),
)
})
});
view.clone().into_any_element()
}
ActiveView::Security => {
SecurityView::build(cx).into_any_element()
}
ActiveView::Logs => {
let view = self.logs_view.get_or_insert_with(|| {
cx.new(|cx| LogsView::new(window, cx))
});
view.clone().into_any_element()
}
ActiveView::About => {
AboutView::build(cx.theme()).into_any_element()
}
}),
),
)
.children(dialog_layer),
)
div()
.size_full()
.overflow_hidden()
.child(body)
.children(dialog_layer)
}
}