Improve ActiveTheme trait to impl ViewContent and ModelContext to support auto import. (#49)

This commit is contained in:
Jason Lee 2024-07-19 11:20:45 +08:00 committed by GitHub
parent e95971624e
commit 613cfebb65
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View file

@ -25,7 +25,7 @@ use crate::{
h_flex,
list::{self, List, ListDelegate, ListItem},
styled_ext::Sizeful,
theme::ActiveTheme,
theme::ActiveTheme as _,
Clickable as _, Icon, IconName, Size, StyledExt,
};

View file

@ -1,5 +1,8 @@
use std::ops::Deref;
use gpui::{
hsla, point, AppContext, BoxShadow, Global, Hsla, Pixels, SharedString, WindowAppearance,
hsla, point, AppContext, BoxShadow, Global, Hsla, ModelContext, Pixels, SharedString,
ViewContext, WindowAppearance,
};
pub trait ActiveTheme {
@ -12,6 +15,18 @@ impl ActiveTheme for AppContext {
}
}
impl<'a, V> ActiveTheme for ViewContext<'a, V> {
fn theme(&self) -> &Theme {
self.deref().theme()
}
}
impl<'a, V> ActiveTheme for ModelContext<'a, V> {
fn theme(&self) -> &Theme {
self.deref().theme()
}
}
/// Make a [gpui::Hsla] color.
///
/// h - 0 - 360.0