Update Dropdown title to use SharedString (#95)

This commit is contained in:
Jason Lee 2024-08-01 11:00:18 +08:00 committed by GitHub
parent c91f71ae21
commit 0e3736e312
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 17 deletions

1
assets/icons/close.svg Normal file
View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-x"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>

After

Width:  |  Height:  |  Size: 256 B

View file

@ -1,5 +1,3 @@
use std::borrow::Cow;
use gpui::{
px, IntoElement, ParentElement, Render, SharedString, Styled, View, ViewContext, VisualContext,
WindowContext,
@ -13,24 +11,24 @@ use ui::{
};
struct Country {
name: String,
code: String,
name: SharedString,
code: SharedString,
}
impl Country {
pub fn new(name: &str, code: &str) -> Self {
pub fn new(name: impl Into<SharedString>, code: impl Into<SharedString>) -> Self {
Self {
name: name.to_string(),
code: code.to_string(),
name: name.into(),
code: code.into(),
}
}
}
impl DropdownItem for Country {
type Value = String;
type Value = SharedString;
fn title(&self) -> Cow<'_, str> {
self.name.as_str().into()
fn title(&self) -> SharedString {
self.name.clone()
}
fn value(&self) -> &Self::Value {

View file

@ -1,5 +1,3 @@
use std::borrow::Cow;
use gpui::{
actions, deferred, div, prelude::FluentBuilder, px, rems, AnyElement, AppContext, ClickEvent,
DismissEvent, Div, Element, ElementId, EventEmitter, FocusHandle, Focusable, FocusableView,
@ -31,15 +29,15 @@ pub fn init(cx: &mut AppContext) {
/// A trait for items that can be displayed in a dropdown.
pub trait DropdownItem {
type Value: Clone;
fn title(&self) -> Cow<'_, str>;
fn title(&self) -> SharedString;
fn value(&self) -> &Self::Value;
}
impl DropdownItem for String {
type Value = Self;
fn title(&self) -> Cow<'_, str> {
self.as_str().into()
fn title(&self) -> SharedString {
SharedString::from(self.to_string())
}
fn value(&self) -> &Self::Value {
@ -50,8 +48,8 @@ impl DropdownItem for String {
impl DropdownItem for SharedString {
type Value = Self;
fn title(&self) -> Cow<'_, str> {
self.as_ref().into()
fn title(&self) -> SharedString {
SharedString::from(self.to_string())
}
fn value(&self) -> &Self::Value {