wip: connect to github

This commit is contained in:
2026-04-23 11:18:43 +01:00
parent 302d0d3222
commit b327648d31
12 changed files with 399 additions and 97 deletions

View File

@@ -3,23 +3,20 @@ use gpui::{
StatefulInteractiveElement, Styled, div, prelude::FluentBuilder,
};
use crate::{app, component::text::Text};
use crate::{app, component::text::TextContent, theme};
#[derive(gpui::IntoElement)]
pub struct Button {
id: gpui::ElementId,
text_color: gpui::Rgba,
label: Option<gpui::AnyElement>,
leading: Option<gpui::Svg>,
trailing: Option<gpui::Svg>,
on_click: Option<Box<dyn Fn(&gpui::ClickEvent, &mut gpui::Window, &mut gpui::App)>>,
}
pub fn button<E>(id: impl Into<gpui::ElementId>, cx: &gpui::Context<E>) -> Button {
let theme = app::current_theme(cx);
pub fn button(id: impl Into<gpui::ElementId>) -> Button {
Button {
id: id.into(),
text_color: theme.colors.accent_text,
label: None,
leading: None,
trailing: None,
@@ -28,40 +25,53 @@ pub fn button<E>(id: impl Into<gpui::ElementId>, cx: &gpui::Context<E>) -> Butto
}
impl Button {
pub fn label(mut self, s: impl Text) -> Self {
pub fn label(mut self, s: impl TextContent) -> Self {
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.leading = Some(s.size_3());
self
}
pub fn trailing(mut self, s: gpui::Svg) -> Self {
self.trailing = Some(s.text_color(self.text_color));
self.trailing = Some(s.size_3());
self
}
pub fn on_click(mut self, fn: impl Fn(&gpui::ClickEvent, &mut gpui::Window, &mut gpui::App)) -> Self {
pub fn on_click(
mut self,
f: impl Fn(&gpui::ClickEvent, &mut gpui::Window, &mut gpui::App) + 'static,
) -> Self {
self.on_click = Some(Box::new(f));
self
}
}
impl gpui::RenderOnce for Button {
fn render(self, _window: &mut gpui::Window, cx: &mut gpui::App) -> impl gpui::IntoElement {
let theme = app::current_theme(cx);
let mut children: Vec<AnyElement> = Vec::with_capacity(3);
if let Some(leading) = self.leading {
children.push(leading.into_any_element());
children.push(
leading
.text_color(theme.colors.accent_text)
.into_any_element(),
);
}
if let Some(label) = self.label {
children.push(label);
}
if let Some(trailing) = self.trailing {
children.push(trailing.into_any_element());
children.push(
trailing
.text_color(theme.colors.accent_text)
.into_any_element(),
);
}
let theme = cx.global::<app::Global>().current_theme;
div()
.id(self.id)
.flex()

3
src/component/mod.rs Normal file
View File

@@ -0,0 +1,3 @@
pub(crate) mod button;
pub(crate) mod font_icon;
pub(crate) mod text;

View File

@@ -1,13 +1,177 @@
use crate::app;
use gpui::{ParentElement, Styled, div};
pub trait Text: gpui::IntoElement {}
impl Text for &'static str {}
impl Text for String {}
impl Text for gpui::SharedString {}
pub fn text<'a, Content: Text, T>(s: Content, cx: &gpui::Context<T>) -> gpui::Div {
let theme = cx.global::<app::Global>().current_theme;
div().text_color(theme.colors.text).child(s)
#[derive(gpui::IntoElement)]
pub(crate) struct Text {
content: gpui::AnyElement,
font_weight: gpui::FontWeight,
opacity: f32,
text_align: gpui::TextAlign,
text_size: Option<gpui::AbsoluteLength>,
line_height: gpui::DefiniteLength,
styled: Option<Box<dyn Fn(gpui::Div) -> gpui::Div>>,
}
pub(crate) trait TextContent: gpui::IntoElement {}
impl TextContent for &'static str {}
impl TextContent for String {}
impl TextContent for gpui::SharedString {}
pub(crate) fn text(content: impl TextContent) -> Text {
Text {
content: content.into_any_element(),
font_weight: gpui::FontWeight::NORMAL,
opacity: 1.,
text_align: gpui::TextAlign::Left,
text_size: None,
line_height: gpui::relative(1.5),
styled: None,
}
}
impl Text {
pub(crate) fn light(mut self) -> Self {
self.font_weight = gpui::FontWeight::LIGHT;
self
}
pub(crate) fn medium(mut self) -> Self {
self.font_weight = gpui::FontWeight::MEDIUM;
self
}
pub(crate) fn bold(mut self) -> Self {
self.font_weight = gpui::FontWeight::BOLD;
self
}
pub(crate) fn opacity(mut self, opacity: f32) -> Self {
self.opacity = opacity;
self
}
pub(crate) fn text_size(mut self, size: impl Into<gpui::AbsoluteLength>) -> Self {
self.text_size = Some(size.into());
self
}
pub(crate) fn text_xs(self) -> Self {
self.text_size(gpui::rems(0.75))
}
pub(crate) fn text_sm(self) -> Self {
self.text_size(gpui::rems(0.875))
}
pub(crate) fn text_base(self) -> Self {
self.text_size(gpui::rems(1.0))
}
pub(crate) fn text_lg(self) -> Self {
self.text_size(gpui::rems(1.125))
}
pub(crate) fn text_xl(self) -> Self {
self.text_size(gpui::rems(1.25))
}
pub(crate) fn text_2xl(self) -> Self {
self.text_size(gpui::rems(1.5))
}
pub(crate) fn text_3xl(self) -> Self {
self.text_size(gpui::rems(1.875))
}
pub(crate) fn line_height(mut self, line_height: impl Into<gpui::DefiniteLength>) -> Self {
self.line_height = line_height.into();
self
}
pub(crate) fn leading_none(self) -> Self {
self.line_height(gpui::relative(1.0))
}
pub(crate) fn leading_tight(self) -> Self {
self.line_height(gpui::relative(1.25))
}
pub(crate) fn leading_snug(self) -> Self {
self.line_height(gpui::relative(1.375))
}
pub(crate) fn leading_normal(self) -> Self {
self.line_height(gpui::relative(1.5))
}
pub(crate) fn leading_relaxed(self) -> Self {
self.line_height(gpui::relative(1.625))
}
pub(crate) fn leading_loose(self) -> Self {
self.line_height(gpui::relative(2.0))
}
pub(crate) fn leading_3(self) -> Self {
self.line_height(gpui::rems(0.75))
}
pub(crate) fn leading_4(self) -> Self {
self.line_height(gpui::rems(1.0))
}
pub(crate) fn leading_5(self) -> Self {
self.line_height(gpui::rems(1.25))
}
pub(crate) fn leading_6(self) -> Self {
self.line_height(gpui::rems(1.5))
}
pub(crate) fn leading_7(self) -> Self {
self.line_height(gpui::rems(1.75))
}
pub(crate) fn leading_8(self) -> Self {
self.line_height(gpui::rems(2.0))
}
pub(crate) fn leading_9(self) -> Self {
self.line_height(gpui::rems(2.25))
}
pub(crate) fn leading_10(self) -> Self {
self.line_height(gpui::rems(2.5))
}
pub(crate) fn styled(mut self, styled: impl Fn(gpui::Div) -> gpui::Div + 'static) -> Self {
self.styled = Some(Box::new(styled));
self
}
pub(crate) fn centered(mut self) -> Self {
self.text_align = gpui::TextAlign::Center;
self
}
}
impl gpui::RenderOnce for Text {
fn render(self, _window: &mut gpui::Window, cx: &mut gpui::App) -> impl gpui::IntoElement {
let theme = app::current_theme(cx);
let mut div = div()
.text_color(theme.colors.text)
.font_weight(self.font_weight)
.opacity(self.opacity)
.text_align(self.text_align)
.line_height(self.line_height)
.child(self.content);
if let Some(text_size) = self.text_size {
div = div.text_size(text_size);
}
if let Some(styled) = self.styled {
div = styled(div);
}
div
}
}