Add border to button

This commit is contained in:
Jason Lee 2024-06-24 19:14:11 +08:00
parent 3a745d2abe
commit 5c1f71a176
4 changed files with 29 additions and 8 deletions

View file

@ -116,7 +116,6 @@ impl Clickable for Button {
impl RenderOnce for Button { impl RenderOnce for Button {
fn render(self, cx: &mut WindowContext) -> impl IntoElement { fn render(self, cx: &mut WindowContext) -> impl IntoElement {
let theme = cx.global::<Theme>();
let style: ButtonStyle = self.style; let style: ButtonStyle = self.style;
let normal_style = style.normal(cx); let normal_style = style.normal(cx);
@ -164,6 +163,7 @@ impl RenderOnce for Button {
.border_1() .border_1()
.border_color(normal_style.border) .border_color(normal_style.border)
.bg(normal_style.bg) .bg(normal_style.bg)
.shadow_sm()
.child({ .child({
let text_color = if self.disabled { let text_color = if self.disabled {
normal_style.fg.opacity(0.6) normal_style.fg.opacity(0.6)
@ -215,6 +215,7 @@ impl ButtonStyle {
ButtonStyle::Secondary => theme.secondary, ButtonStyle::Secondary => theme.secondary,
ButtonStyle::Danger => theme.destructive, ButtonStyle::Danger => theme.destructive,
} }
.darken(0.05)
} }
fn normal(&self, cx: &WindowContext) -> ButtonStyles { fn normal(&self, cx: &WindowContext) -> ButtonStyles {
@ -235,9 +236,9 @@ impl ButtonStyle {
} }
fn active(&self, cx: &WindowContext) -> ButtonStyles { fn active(&self, cx: &WindowContext) -> ButtonStyles {
let bg = self.bg_color(cx); let bg = self.bg_color(cx).darken(0.05);
let border = self.border_color(cx); let border = self.border_color(cx).darken(0.05);
let fg = self.text_color(cx); let fg = self.text_color(cx).darken(0.05);
ButtonStyles { bg, border, fg } ButtonStyles { bg, border, fg }
} }

View file

@ -235,7 +235,7 @@ impl RenderOnce for TextField {
.bg(if disabled { .bg(if disabled {
theme.muted theme.muted
} else { } else {
theme.transparent theme.background
}) })
.child(view) .child(view)
} }

View file

@ -313,15 +313,19 @@ impl Render for TextView {
text = "".repeat(text.len()); text = "".repeat(text.len());
} }
let mut selection_style = HighlightStyle::default(); let selection_style = HighlightStyle {
selection_style.background_color = Some(theme.ring); background_color: Some(theme.ring),
selection_style.color = Some(theme.ring.invert()); color: Some(theme.ring.invert()),
..Default::default()
};
let mut highlights = vec![(self.char_range_to_text_range(&text), selection_style)]; let mut highlights = vec![(self.char_range_to_text_range(&text), selection_style)];
if text.is_empty() { if text.is_empty() {
text = self.placeholder.to_string(); text = self.placeholder.to_string();
style.color = theme.muted_foreground; style.color = theme.muted_foreground;
} else {
style.color = theme.foreground;
} }
if !self.focused { if !self.focused {

View file

@ -1,3 +1,5 @@
use std::cmp::min;
use gpui::{AppContext, Global, Hsla, Rgba}; use gpui::{AppContext, Global, Hsla, Rgba};
use serde_json::json; use serde_json::json;
@ -14,6 +16,8 @@ pub trait Colorize {
fn opacity(&self, opacity: f32) -> Hsla; fn opacity(&self, opacity: f32) -> Hsla;
fn divide(&self, divisor: f32) -> Hsla; fn divide(&self, divisor: f32) -> Hsla;
fn invert(&self) -> Hsla; fn invert(&self) -> Hsla;
fn lighten(&self, amount: f32) -> Hsla;
fn darken(&self, amount: f32) -> Hsla;
} }
impl Colorize for Hsla { impl Colorize for Hsla {
@ -46,6 +50,18 @@ impl Colorize for Hsla {
a: self.a, a: self.a,
} }
} }
fn lighten(&self, amount: f32) -> Hsla {
let l = (self.l + amount).min(1.0);
Hsla { l, ..*self }
}
fn darken(&self, amount: f32) -> Hsla {
let l = (self.l - amount).max(0.0);
Hsla { l, ..*self }
}
} }
// @layer base { // @layer base {