From c925a6aa6143cfaa4ff1217a5fddabe36241dd35 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Fri, 5 Jul 2024 00:18:36 +0800 Subject: [PATCH] Add ButtonStyle::Outline, ButtonStyle::Glost --- crates/story/src/button_story.rs | 25 +++++++++++++++++++++++++ crates/ui/src/button.rs | 14 ++++++++++++++ crates/ui/src/input.rs | 16 ++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/crates/story/src/button_story.rs b/crates/story/src/button_story.rs index e0221be1..105c0dd6 100644 --- a/crates/story/src/button_story.rs +++ b/crates/story/src/button_story.rs @@ -50,6 +50,18 @@ impl Render for ButtonStory { .label("Danger Button") .style(ButtonStyle::Danger) .on_click(Self::on_click), + ) + .child( + Button::new("button-5", cx) + .label("Outline Button") + .style(ButtonStyle::Outline) + .on_click(Self::on_click), + ) + .child( + Button::new("button-6", cx) + .label("Ghost Button") + .style(ButtonStyle::Ghost) + .on_click(Self::on_click), ), ) .child( @@ -197,6 +209,19 @@ impl Render for ButtonStory { .size(ButtonSize::Small) .style(ButtonStyle::Primary), ) + .child( + Button::new("icon-button-0-outline", cx) + .icon(IconName::Search) + .style(ButtonStyle::Outline), + ) + .child( + Button::new("icon-button-1", cx) + .icon(IconName::Info) + .style(ButtonStyle::Ghost), + ), + ) + .child( + section("Icon Button", cx) .child( Button::new("icon-button-4", cx) .icon(IconName::Info) diff --git a/crates/ui/src/button.rs b/crates/ui/src/button.rs index 1c308ba7..df3f7138 100644 --- a/crates/ui/src/button.rs +++ b/crates/ui/src/button.rs @@ -29,6 +29,8 @@ pub enum ButtonStyle { Primary, Secondary, Danger, + Outline, + Ghost, } #[derive(IntoElement)] @@ -282,6 +284,8 @@ impl ButtonStyle { ButtonStyle::Primary => cx.theme().primary, ButtonStyle::Secondary => cx.theme().secondary, ButtonStyle::Danger => cx.theme().destructive, + ButtonStyle::Outline => cx.theme().transparent, + ButtonStyle::Ghost => cx.theme().transparent, } } @@ -290,6 +294,8 @@ impl ButtonStyle { ButtonStyle::Primary => cx.theme().primary_foreground, ButtonStyle::Secondary => cx.theme().secondary_foreground, ButtonStyle::Danger => cx.theme().destructive_foreground, + ButtonStyle::Outline => cx.theme().secondary_foreground, + ButtonStyle::Ghost => cx.theme().secondary_foreground, } } @@ -298,6 +304,8 @@ impl ButtonStyle { ButtonStyle::Primary => cx.theme().primary, ButtonStyle::Secondary => cx.theme().border, ButtonStyle::Danger => cx.theme().destructive, + ButtonStyle::Outline => cx.theme().border, + ButtonStyle::Ghost => cx.theme().transparent, } } @@ -314,6 +322,8 @@ impl ButtonStyle { ButtonStyle::Primary => cx.theme().primary_hover, ButtonStyle::Secondary => cx.theme().secondary_hover, ButtonStyle::Danger => cx.theme().destructive_hover, + ButtonStyle::Outline => cx.theme().secondary_hover, + ButtonStyle::Ghost => cx.theme().secondary_hover, }; let border = self.border_color(cx); let fg = self.text_color(cx); @@ -326,6 +336,8 @@ impl ButtonStyle { ButtonStyle::Primary => cx.theme().primary_active, ButtonStyle::Secondary => cx.theme().secondary_active, ButtonStyle::Danger => cx.theme().destructive_active, + ButtonStyle::Outline => cx.theme().secondary_active, + ButtonStyle::Ghost => cx.theme().secondary_active, }; let border = self.border_color(cx); let fg = self.text_color(cx); @@ -338,6 +350,8 @@ impl ButtonStyle { ButtonStyle::Primary => cx.theme().primary_active, ButtonStyle::Secondary => cx.theme().secondary_active, ButtonStyle::Danger => cx.theme().destructive_active, + ButtonStyle::Outline => cx.theme().secondary_active, + ButtonStyle::Ghost => cx.theme().secondary_active, }; let border = self.border_color(cx); let fg = self.text_color(cx); diff --git a/crates/ui/src/input.rs b/crates/ui/src/input.rs index f74a0798..844080ae 100644 --- a/crates/ui/src/input.rs +++ b/crates/ui/src/input.rs @@ -1,6 +1,8 @@ use std::ops::Range; use crate::event::InterativeElementExt as _; +use crate::popover::Popover; +use crate::popup_menu::PopupMenu; use crate::theme::ActiveTheme; use crate::StyledExt as _; use blink_cursor::BlinkCursor; @@ -369,6 +371,20 @@ impl TextInput { blink_cursor.pause(cx); }); } + + fn render_content_menu(&self, cx: &mut ViewContext) -> impl IntoElement { + let focus_handle = self.focus_handle.clone(); + + PopupMenu::build(cx, |mut this, _| { + this.content(focus_handle) + .menu("Copy", Box::new(Copy)) + .menu("Cut", Box::new(Cut)) + .menu("Paste", Box::new(Paste)) + .separator() + .menu("Search", Box::new(SelectAll)); + this + }) + } } impl ViewInputHandler for TextInput {