From 613cfebb6515b927395187a3348351d080c4ce4d Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Fri, 19 Jul 2024 11:20:45 +0800 Subject: [PATCH] Improve ActiveTheme trait to impl ViewContent and ModelContext to support auto import. (#49) --- crates/ui/src/dropdown.rs | 2 +- crates/ui/src/theme.rs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/ui/src/dropdown.rs b/crates/ui/src/dropdown.rs index 0b0ba324..2b6d5fc2 100644 --- a/crates/ui/src/dropdown.rs +++ b/crates/ui/src/dropdown.rs @@ -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, }; diff --git a/crates/ui/src/theme.rs b/crates/ui/src/theme.rs index c9a27eb0..3eb5e9ed 100644 --- a/crates/ui/src/theme.rs +++ b/crates/ui/src/theme.rs @@ -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