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