This commit is contained in:
Antonio Scandurra 2023-10-19 23:40:31 +02:00
commit 21b4ae3fdc
36 changed files with 705 additions and 576 deletions

View file

@ -4,7 +4,7 @@ use std::sync::Arc;
use gpui3::{MouseButton, StatelesslyInteractive};
use crate::{h_stack, prelude::*};
use crate::{theme, ClickHandler, Icon, IconColor, IconElement};
use crate::{ClickHandler, Icon, IconColor, IconElement};
struct IconButtonHandlers<S: 'static + Send + Sync> {
click: Option<ClickHandler<S>>,
@ -67,7 +67,6 @@ impl<S: 'static + Send + Sync> IconButton<S> {
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let theme = theme(cx);
let color = ThemeColor::new(cx);
let icon_color = match (self.state, self.color) {
@ -75,15 +74,29 @@ impl<S: 'static + Send + Sync> IconButton<S> {
_ => self.color,
};
let (bg_color, bg_hover_color, bg_active_color) = match self.variant {
ButtonVariant::Filled => (
color.filled_element,
color.filled_element_hover,
color.filled_element_active,
),
ButtonVariant::Ghost => (
color.ghost_element,
color.ghost_element_hover,
color.ghost_element_active,
),
};
let mut button = h_stack()
// TODO: We probably need a more robust method for differentiating `IconButton`s from one another.
.id(SharedString::from(format!("{:?}", self.icon)))
.justify_center()
.rounded_md()
.py(ui_size(cx, 0.25))
.px(ui_size(cx, 6. / 14.))
.when(self.variant == ButtonVariant::Filled, |this| {
this.bg(color.filled_element)
})
.hover(|style| style.bg(theme.highest.base.hovered.background))
.bg(bg_color)
.hover(|style| style.bg(bg_hover_color))
.active(|style| style.bg(bg_active_color))
.child(IconElement::new(self.icon).color(icon_color));
if let Some(click_handler) = self.handlers.click.clone() {