77pub mod portal;
88pub mod style;
99
10+ use :: iced:: Alignment ;
1011use cosmic_config:: { CosmicConfigEntry , config_subscription} ;
1112use cosmic_theme:: { Component , LayeredTheme , Spacing , ThemeMode } ;
1213use iced_futures:: Subscription ;
@@ -47,6 +48,7 @@ pub(crate) static THEME: Mutex<Theme> = Mutex::new(Theme {
4748 theme_type : ThemeType :: Dark ,
4849 layer : cosmic_theme:: Layer :: Background ,
4950 transparent : false ,
51+ list_item_position : None ,
5052} ) ;
5153
5254/// Currently-defined theme.
@@ -83,34 +85,6 @@ pub fn is_high_contrast() -> bool {
8385 active_type ( ) . is_high_contrast ( )
8486}
8587
86- // /// Watches for changes to the system's theme preference.
87- // #[cold]
88- // pub fn subscription(is_dark: bool) -> Subscription<crate::theme::Theme> {
89- // config_subscription::<_, crate::cosmic_theme::Theme>(
90- // (
91- // std::any::TypeId::of::<crate::cosmic_theme::Theme>(),
92- // is_dark,
93- // ),
94- // if is_dark {
95- // cosmic_theme::DARK_THEME_ID
96- // } else {
97- // cosmic_theme::LIGHT_THEME_ID
98- // }
99- // .into(),
100- // crate::cosmic_theme::Theme::VERSION,
101- // )
102- // .map(|res| {
103- // for error in res.errors.into_iter().filter(cosmic_config::Error::is_err) {
104- // tracing::error!(
105- // ?error,
106- // "error while watching system theme preference changes"
107- // );
108- // }
109-
110- // Theme::system(Arc::new(res.config))
111- // })
112- // }
113-
11488pub fn system_dark ( ) -> Theme {
11589 let Ok ( helper) = crate :: cosmic_theme:: Theme :: dark_config ( ) else {
11690 return Theme :: dark ( ) ;
@@ -211,6 +185,8 @@ pub struct Theme {
211185 pub theme_type : ThemeType ,
212186 pub layer : cosmic_theme:: Layer ,
213187 pub transparent : bool ,
188+ /// Only meaningful for widgets that must be in a list. Otherwise it should be ignored.
189+ pub list_item_position : Option < ( Alignment , usize ) > ,
214190}
215191
216192impl Theme {
@@ -281,9 +257,9 @@ impl Theme {
281257 /// can be used in a component that is intended to be a child of a `CosmicContainer`
282258 pub fn current_container ( & self ) -> & cosmic_theme:: Container {
283259 match self . layer {
284- cosmic_theme:: Layer :: Background => & self . cosmic ( ) . background ( self . transparent ) ,
285- cosmic_theme:: Layer :: Primary => & self . cosmic ( ) . primary ( self . transparent ) ,
286- cosmic_theme:: Layer :: Secondary => & self . cosmic ( ) . secondary ( self . transparent ) ,
260+ cosmic_theme:: Layer :: Background => self . cosmic ( ) . background ( self . transparent ) ,
261+ cosmic_theme:: Layer :: Primary => self . cosmic ( ) . primary ( self . transparent ) ,
262+ cosmic_theme:: Layer :: Secondary => self . cosmic ( ) . secondary ( self . transparent ) ,
287263 }
288264 }
289265
@@ -292,6 +268,14 @@ impl Theme {
292268 pub fn set_theme ( & mut self , theme : ThemeType ) {
293269 self . theme_type = theme;
294270 }
271+
272+ #[ inline]
273+ /// Clone theme with a list position
274+ pub fn with_list_item_position ( & self , position : Option < ( Alignment , usize ) > ) -> Self {
275+ let mut new = self . clone ( ) ;
276+ new. list_item_position = position;
277+ new
278+ }
295279}
296280
297281impl LayeredTheme for Theme {
0 commit comments