Add new Button and IconButton components (#3448)
This PR adds new `Button` and `IconButton` components built on top of our new button abstractions. Both of these buttons are built from the common `ButtonLike` base, and implement the `ButtonCommon` (name TBD) trait in order to provide a common interface. There are still some visual tweaks that we'll need to make to the new buttons, but those should be straightforward to make after we land this. Release Notes: - N/A
This commit is contained in:
@@ -18,7 +18,7 @@ use project::search::SearchQuery;
|
||||
use serde::Deserialize;
|
||||
use std::{any::Any, sync::Arc};
|
||||
|
||||
use ui::{h_stack, ButtonGroup, Icon, IconButton, IconElement};
|
||||
use ui::{h_stack, Icon, IconButton, IconElement};
|
||||
use util::ResultExt;
|
||||
use workspace::{
|
||||
item::ItemHandle,
|
||||
@@ -214,10 +214,11 @@ impl Render for BufferSearchBar {
|
||||
.child(
|
||||
h_stack()
|
||||
.flex_none()
|
||||
.child(ButtonGroup::new(vec![
|
||||
search_button_for_mode(SearchMode::Text),
|
||||
search_button_for_mode(SearchMode::Regex),
|
||||
]))
|
||||
.child(
|
||||
h_stack()
|
||||
.child(search_button_for_mode(SearchMode::Text))
|
||||
.child(search_button_for_mode(SearchMode::Regex)),
|
||||
)
|
||||
.when(supported_options.replacement, |this| {
|
||||
this.child(super::toggle_replace_button(self.replace_enabled))
|
||||
}),
|
||||
@@ -586,8 +587,7 @@ impl BufferSearchBar {
|
||||
|
||||
// let style = theme.search.action_button.clone();
|
||||
|
||||
IconButton::new(0, ui::Icon::SelectAll)
|
||||
.on_click(|_, cx| cx.dispatch_action(Box::new(SelectAllMatches)))
|
||||
IconButton::new(0, ui::Icon::SelectAll).action(Box::new(SelectAllMatches))
|
||||
}
|
||||
|
||||
pub fn activate_search_mode(&mut self, mode: SearchMode, cx: &mut ViewContext<Self>) {
|
||||
|
||||
@@ -3,7 +3,8 @@ pub use buffer_search::BufferSearchBar;
|
||||
use gpui::{actions, Action, AppContext, IntoElement};
|
||||
pub use mode::SearchMode;
|
||||
use project::search::SearchQuery;
|
||||
use ui::ButtonVariant;
|
||||
use ui::prelude::*;
|
||||
use ui::{ButtonStyle2, Icon, IconButton};
|
||||
//pub use project_search::{ProjectSearchBar, ProjectSearchView};
|
||||
// use theme::components::{
|
||||
// action_button::Button, svg::Svg, ComponentExt, IconButtonStyle, ToggleIconButtonStyle,
|
||||
@@ -83,35 +84,35 @@ impl SearchOptions {
|
||||
}
|
||||
|
||||
pub fn as_button(&self, active: bool) -> impl IntoElement {
|
||||
ui::IconButton::new(0, self.icon())
|
||||
IconButton::new(0, self.icon())
|
||||
.on_click({
|
||||
let action = self.to_toggle_action();
|
||||
move |_, cx| {
|
||||
cx.dispatch_action(action.boxed_clone());
|
||||
}
|
||||
})
|
||||
.variant(ui::ButtonVariant::Ghost)
|
||||
.when(active, |button| button.variant(ButtonVariant::Filled))
|
||||
.style(ButtonStyle2::Subtle)
|
||||
.when(active, |button| button.style(ButtonStyle2::Filled))
|
||||
}
|
||||
}
|
||||
|
||||
fn toggle_replace_button(active: bool) -> impl IntoElement {
|
||||
// todo: add toggle_replace button
|
||||
ui::IconButton::new(0, ui::Icon::Replace)
|
||||
IconButton::new(0, Icon::Replace)
|
||||
.on_click(|_, cx| {
|
||||
cx.dispatch_action(Box::new(ToggleReplace));
|
||||
cx.notify();
|
||||
})
|
||||
.variant(ui::ButtonVariant::Ghost)
|
||||
.when(active, |button| button.variant(ButtonVariant::Filled))
|
||||
.style(ButtonStyle2::Subtle)
|
||||
.when(active, |button| button.style(ButtonStyle2::Filled))
|
||||
}
|
||||
|
||||
fn render_replace_button(
|
||||
action: impl Action + 'static + Send + Sync,
|
||||
icon: ui::Icon,
|
||||
icon: Icon,
|
||||
) -> impl IntoElement {
|
||||
// todo: add tooltip
|
||||
ui::IconButton::new(0, icon).on_click(move |_, cx| {
|
||||
IconButton::new(0, icon).on_click(move |_, cx| {
|
||||
cx.dispatch_action(action.boxed_clone());
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use gpui::{ClickEvent, IntoElement, WindowContext};
|
||||
use ui::{Button, ButtonVariant, IconButton};
|
||||
use ui::prelude::*;
|
||||
use ui::{Button, IconButton};
|
||||
|
||||
use crate::mode::SearchMode;
|
||||
|
||||
@@ -23,13 +24,7 @@ pub(crate) fn render_search_mode_button(
|
||||
is_active: bool,
|
||||
on_click: impl Fn(&ClickEvent, &mut WindowContext) + 'static,
|
||||
) -> Button {
|
||||
let button_variant = if is_active {
|
||||
ButtonVariant::Filled
|
||||
} else {
|
||||
ButtonVariant::Ghost
|
||||
};
|
||||
|
||||
Button::new(mode.label())
|
||||
Button::new(mode.label(), mode.label())
|
||||
.selected(is_active)
|
||||
.on_click(on_click)
|
||||
.variant(button_variant)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user