Put Theme behind an Arc (#3017)

This PR puts the `Theme` returned from the `theme` function behind an
`Arc`.

### Motivation

While working on wiring up window focus events for the `TitleBar`
component we ran into issues where `theme` was holding an immutable
borrow to the `ViewContext` for the entirety of the `render` scope,
which prevented having mutable borrows in the same scope.

### Explanation

To avoid this, we can make `theme` return an `Arc<Theme>` to allow for
cheap clones and avoiding the issues with the borrow checker.

Release Notes:

- N/A

Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
This commit is contained in:
Marshall Bowers 2023-09-22 13:35:30 -04:00 committed by GitHub
parent d8c6adf338
commit 71c1e36d1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 22 deletions

View file

@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::fmt;
use std::marker::PhantomData;
use std::sync::Arc;
use gpui2::color::Hsla;
use gpui2::element::Element;
@ -190,6 +191,6 @@ fn preferred_theme<V: 'static>(cx: &AppContext) -> Theme {
.clone()
}
pub fn theme<'a>(cx: &'a WindowContext) -> &'a Theme {
pub fn theme(cx: &WindowContext) -> Arc<Theme> {
cx.theme::<Theme>()
}