Files
oak-gpui/crates/panel/src/panel.rs
T
976fc3ee97 git_ui: Design Polish (#26361)
Polish PR

- [ ] Horizontal scrollbar for git panel
- [ ] Allow shift clicking a checkbox in any section to stage the whole
section
- [ ] Clean up design of no changes/pending push state in panel
- [x] Ensure checkbox placeholder dot is centered in the checkbox
- [x] Improve spacing between elements in git panel entries
- [x] Update git branch icon to match branch selector text when disabled
- [x] Truncate last commit message less aggressively in panel
- [x] Clean up new panel header design
- [x] Remove `_background` version control keys (backgrounds are derived
from the foreground colors)

### Previous message truncation:

Before:

![CleanShot 2025-03-10 at 11 54
32@2x](https://github.com/user-attachments/assets/46b18f66-bb5c-435e-a0da-6cc931bd8a15)

After:

![CleanShot 2025-03-10 at 11 55
24@2x](https://github.com/user-attachments/assets/fcf688c7-b949-41a2-a7b8-1a198eb7fa4a)

### Make branch icon match when menu is disabled

Before:

![CleanShot 2025-03-10 at 12 02
14@2x](https://github.com/user-attachments/assets/1990f4b3-c2f0-4e02-89ad-211aaebb3821)

After:

![CleanShot 2025-03-10 at 12 02
53@2x](https://github.com/user-attachments/assets/9b1caf65-c48f-44c9-924b-484892fb543f)

Release Notes:

- N/A *or* Added/Fixed/Improved ...

---------

Co-authored-by: Cole Miller <cole@zed.dev>
Co-authored-by: Cole Miller <m@cole-miller.net>
Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
2025-03-10 13:19:02 -07:00

128 lines
4.0 KiB
Rust

//! # panel
use editor::{Editor, EditorElement, EditorStyle};
use gpui::{actions, Entity, TextStyle};
use settings::Settings;
use theme::ThemeSettings;
use ui::{prelude::*, Tab};
actions!(panel, [NextPanelTab, PreviousPanelTab]);
pub trait PanelHeader: workspace::Panel {
fn header_height(&self, cx: &mut App) -> Pixels {
Tab::container_height(cx)
}
fn panel_header_container(&self, _window: &mut Window, cx: &mut App) -> Div {
h_flex()
.h(self.header_height(cx))
.w_full()
.px_1()
.flex_none()
}
}
/// Implement this trait to enable a panel to have tabs.
pub trait PanelTabs: PanelHeader {
/// Returns the index of the currently selected tab.
fn selected_tab(&self, cx: &mut App) -> usize;
/// Selects the tab at the given index.
fn select_tab(&self, cx: &mut App, index: usize);
/// Moves to the next tab.
fn next_tab(&self, _: NextPanelTab, cx: &mut App) -> Self;
/// Moves to the previous tab.
fn previous_tab(&self, _: PreviousPanelTab, cx: &mut App) -> Self;
}
#[derive(IntoElement)]
pub struct PanelTab {}
impl RenderOnce for PanelTab {
fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
div()
}
}
pub fn panel_button(label: impl Into<SharedString>) -> ui::Button {
let label = label.into();
let id = ElementId::Name(label.clone().to_lowercase().replace(' ', "_").into());
ui::Button::new(id, label)
.label_size(ui::LabelSize::Small)
.icon_size(ui::IconSize::Small)
// TODO: Change this once we use on_surface_bg in button_like
.layer(ui::ElevationIndex::ModalSurface)
.size(ui::ButtonSize::Compact)
}
pub fn panel_filled_button(label: impl Into<SharedString>) -> ui::Button {
panel_button(label).style(ui::ButtonStyle::Filled)
}
pub fn panel_icon_button(id: impl Into<SharedString>, icon: IconName) -> ui::IconButton {
let id = ElementId::Name(id.into());
ui::IconButton::new(id, icon)
// TODO: Change this once we use on_surface_bg in button_like
.layer(ui::ElevationIndex::ModalSurface)
.size(ui::ButtonSize::Compact)
}
pub fn panel_filled_icon_button(id: impl Into<SharedString>, icon: IconName) -> ui::IconButton {
panel_icon_button(id, icon).style(ui::ButtonStyle::Filled)
}
pub fn panel_editor_container(_window: &mut Window, cx: &mut App) -> Div {
v_flex()
.size_full()
.gap(px(8.))
.p_2()
.bg(cx.theme().colors().editor_background)
}
pub fn panel_editor_style(monospace: bool, window: &Window, cx: &App) -> EditorStyle {
let settings = ThemeSettings::get_global(cx);
let font_size = TextSize::Small.rems(cx).to_pixels(window.rem_size());
let (font_family, font_fallbacks, font_features, font_weight, line_height) = if monospace {
(
settings.buffer_font.family.clone(),
settings.buffer_font.fallbacks.clone(),
settings.buffer_font.features.clone(),
settings.buffer_font.weight,
font_size * settings.buffer_line_height.value(),
)
} else {
(
settings.ui_font.family.clone(),
settings.ui_font.fallbacks.clone(),
settings.ui_font.features.clone(),
settings.ui_font.weight,
window.line_height(),
)
};
EditorStyle {
background: cx.theme().colors().editor_background,
local_player: cx.theme().players().local(),
text: TextStyle {
color: cx.theme().colors().text,
font_family,
font_fallbacks,
font_features,
font_size: TextSize::Small.rems(cx).into(),
font_weight,
line_height: line_height.into(),
..Default::default()
},
..Default::default()
}
}
pub fn panel_editor_element(
editor: &Entity<Editor>,
monospace: bool,
window: &mut Window,
cx: &mut App,
) -> EditorElement {
EditorElement::new(editor, panel_editor_style(monospace, window, cx))
}