feat(ui): add selected icon to combobox and refine styling
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run

This commit is contained in:
2026-11-20 19:21:38 +07:00
parent b6bfc3fc15
commit 033624101f
4 changed files with 37 additions and 5 deletions
+4 -1
View File
@@ -322,7 +322,10 @@ impl Render for DiffPane {
Resizable::new("commit-diff-split", self.split.clone())
.axis(Axis::Horizontal)
.pane_with_min(tree, px(120.))
.pane_with_min(detail, px(240.)),
.pane_with_min(detail, px(240.))
.flex_1()
.min_w_0()
.h_full(),
)
}
}
+2
View File
@@ -1,5 +1,6 @@
use gpui::{App, AppContext as _, Entity, SharedString, WeakEntity, Window};
use ui::combobox::{Combobox, ComboboxState};
use ui::icons::{IconRole, icon};
use super::RepoDetailView;
use super::helpers::sync_selector;
@@ -19,6 +20,7 @@ impl RefSwitcher {
ComboboxState::new(
Combobox::new("branch-select", "Branch", Vec::new())
.placeholder("Branch")
.selected_icon(icon(IconRole::GitBranch))
.on_change(move |value, window, cx| {
if let Some(name) = value
&& let Err(error) = branch_view.update(cx, |this, cx| {
+1 -1
View File
@@ -356,7 +356,7 @@ impl RenderOnce for Button {
.when_some(a11y_label, |button, label| button.aria_label(label))
.child(
h_flex()
.gap_2()
.gap_1()
.when(self.full_width, |content| content.flex_1())
.when(self.loading, |content| content.invisible())
.map(|content| {
+30 -3
View File
@@ -43,7 +43,7 @@ use crate::components::common::{
};
use crate::components::empty_state::EmptyState;
use crate::components::input::{Input, InputState, InputStateEvent};
use crate::icons::{IconRole, icon};
use crate::icons::{Icon, IconRole, icon};
use crate::theme::{ActiveTheme as _, COMBOBOX_MIN_WIDTH, COMBOBOX_WIDTH, POPUP_MAX_HEIGHT, Size};
actions!(
@@ -106,6 +106,8 @@ where
filter: Option<ComboboxFilter<T>>,
unmatched: UnmatchedText,
size: Size,
/// Icon shown at the field's leading edge while a value is selected.
selected_icon: Option<Icon>,
style: StyleRefinement,
}
@@ -129,6 +131,7 @@ where
filter: None,
unmatched: UnmatchedText::default(),
size: Size::default(),
selected_icon: None,
style: StyleRefinement::default(),
}
}
@@ -151,6 +154,12 @@ where
self
}
/// Shows an icon at the field's leading edge while a value is selected.
pub fn selected_icon(mut self, icon: Icon) -> Self {
self.selected_icon = Some(icon);
self
}
/// Reports the value whenever it changes.
pub fn on_change<F>(mut self, handler: F) -> Self
where
@@ -247,6 +256,8 @@ where
size: Size,
/// Width refinements from the builder, applied to the wrapper each render.
style: StyleRefinement,
/// Icon shown at the field's leading edge while a value is selected.
selected_icon: Option<Icon>,
/// The row list's scroll, kept across frames while the popup is open.
rows_scroll: UniformListScrollHandle,
/// The most recent handler report in flight; a newer report replaces it.
@@ -308,6 +319,7 @@ where
unmatched: combobox.unmatched,
size: combobox.size,
style: combobox.style,
selected_icon: combobox.selected_icon,
rows_scroll: UniformListScrollHandle::new(),
task: None,
_subscription: subscription,
@@ -336,7 +348,15 @@ where
/// Replaces the value; reports it when it actually changed.
pub fn set_selected(&mut self, value: Option<T>, window: &mut Window, cx: &mut Context<Self>) {
let changed = self.selected != value;
self.set_value(value, window, cx);
if changed {
let label = self.selected_label().unwrap_or_default();
self.query
.update(cx, |query, cx| query.set_value_silent(label, window, cx));
self.refilter("");
cx.notify();
}
}
/// Replaces the choice list and re-runs the current filter.
@@ -598,6 +618,12 @@ where
Input::new((id.clone(), "query"), self.query.clone())
.placeholder(self.placeholder.clone())
.placeholder_when_focused(true)
.fully_rounded(true)
.when_some(self.selected_icon.clone(), |input, selected_icon| {
input.when(self.selected.is_some(), |input| {
input.prefix(selected_icon.size(self.size.icon_rems()))
})
})
.with_size(self.size),
)
.child(
@@ -617,7 +643,7 @@ where
let size = self.size;
let list_state = state.clone();
let rows_id = id.clone();
let radius_sm = radius.sm;
let radius_full = radius.full;
let foreground = colors.foreground;
// Rows are `control_height`, so the row height follows the size.
@@ -654,6 +680,7 @@ where
})
.role(Role::ListBoxOption)
.aria_label(label.clone())
.w_full()
.flex()
.items_center()
.gap_2()
@@ -661,7 +688,7 @@ where
.py_1()
.h(row_height)
.control_text(size)
.rounded(radius_sm)
.rounded(radius_full)
.map(|row| paint_highlighted_row(cx, row, highlighted, false))
.on_mouse_move({
let state = state.clone();