wip
This commit is contained in:
@@ -1,14 +1,24 @@
|
||||
use gpui::{FontWeight, InteractiveElement, ParentElement, Styled, div};
|
||||
use gpui::{AnyElement, FontWeight, InteractiveElement, ParentElement, Styled, div};
|
||||
|
||||
use crate::{app, component::text::Text};
|
||||
|
||||
pub struct Button(gpui::Stateful<gpui::Div>);
|
||||
pub struct Button {
|
||||
div: gpui::Stateful<gpui::Div>,
|
||||
text_color: gpui::Rgba,
|
||||
label: Option<gpui::AnyElement>,
|
||||
leading: Option<gpui::Svg>,
|
||||
trailing: Option<gpui::Svg>,
|
||||
}
|
||||
|
||||
pub fn button<T>(id: impl Into<gpui::ElementId>, cx: &gpui::Context<T>) -> Button {
|
||||
pub fn button<E>(id: impl Into<gpui::ElementId>, cx: &gpui::Context<E>) -> Button {
|
||||
let theme = app::current_theme(cx);
|
||||
Button(
|
||||
div()
|
||||
Button {
|
||||
div: div()
|
||||
.id(id)
|
||||
.flex()
|
||||
.flex_row()
|
||||
.gap_2()
|
||||
.items_center()
|
||||
.rounded_sm()
|
||||
.bg(theme.colors.accent)
|
||||
.text_xs()
|
||||
@@ -16,12 +26,26 @@ pub fn button<T>(id: impl Into<gpui::ElementId>, cx: &gpui::Context<T>) -> Butto
|
||||
.font_weight(FontWeight(500.))
|
||||
.px_2p5()
|
||||
.py_0p5(),
|
||||
)
|
||||
text_color: theme.colors.accent_text,
|
||||
label: None,
|
||||
leading: None,
|
||||
trailing: None,
|
||||
}
|
||||
}
|
||||
|
||||
impl Button {
|
||||
pub fn label(mut self, s: impl Text) -> Self {
|
||||
self.0 = self.0.child(s);
|
||||
self.label = Some(s.into_any_element());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn leading(mut self, s: gpui::Svg) -> Self {
|
||||
self.leading = Some(s.size_3().text_color(self.text_color));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn trailing(mut self, s: gpui::Svg) -> Self {
|
||||
self.trailing = Some(s.text_color(self.text_color));
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -30,6 +54,16 @@ impl gpui::IntoElement for Button {
|
||||
type Element = gpui::Stateful<gpui::Div>;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self.0
|
||||
let mut children: Vec<AnyElement> = Vec::with_capacity(3);
|
||||
if let Some(leading) = self.leading {
|
||||
children.push(leading.into_any_element());
|
||||
}
|
||||
if let Some(label) = self.label {
|
||||
children.push(label);
|
||||
}
|
||||
if let Some(trailing) = self.trailing {
|
||||
children.push(trailing.into_any_element());
|
||||
}
|
||||
self.div.children(children)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,9 +26,10 @@ macro_rules! define_font_icons {
|
||||
};
|
||||
}
|
||||
|
||||
define_font_icons!(ChevronDown, FolderGit);
|
||||
define_font_icons!(ChevronDown, FolderGit, Github);
|
||||
|
||||
pub fn font_icon<T>(icon: FontIcon, cx: &gpui::Context<T>) -> gpui::Svg {
|
||||
let theme = cx.global::<app::Global>().current_theme;
|
||||
println!("{}", icon_path(icon));
|
||||
svg().path(icon_path(icon)).text_color(theme.colors.text)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user