gtk4/auto/css_provider.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4#![allow(deprecated)]
5
6#[cfg(feature = "v4_22")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
8use crate::ReducedMotion;
9use crate::{ffi, CssSection, StyleProvider};
10#[cfg(feature = "v4_20")]
11#[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
12use crate::{InterfaceColorScheme, InterfaceContrast};
13use glib::{
14 object::ObjectType as _,
15 prelude::*,
16 signal::{connect_raw, SignalHandlerId},
17 translate::*,
18};
19use std::boxed::Box as Box_;
20
21glib::wrapper! {
22 /// A style provider for CSS.
23 ///
24 /// It is able to parse CSS-like input in order to style widgets.
25 ///
26 /// An application can make GTK parse a specific CSS style sheet by calling
27 /// [`load_from_file()`][Self::load_from_file()] or
28 /// [`load_from_resource()`][Self::load_from_resource()]
29 /// and adding the provider with [`StyleContextExt::add_provider()`][crate::prelude::StyleContextExt::add_provider()] or
30 /// [`StyleContext::add_provider_for_display()`][crate::StyleContext::add_provider_for_display()].
31 ///
32 /// In addition, certain files will be read when GTK is initialized.
33 /// First, the file `$XDG_CONFIG_HOME/gtk-4.0/gtk.css` is loaded if it
34 /// exists. Then, GTK loads the first existing file among
35 /// `XDG_DATA_HOME/themes/THEME/gtk-VERSION/gtk-VARIANT.css`,
36 /// `$HOME/.themes/THEME/gtk-VERSION/gtk-VARIANT.css`,
37 /// `$XDG_DATA_DIRS/themes/THEME/gtk-VERSION/gtk-VARIANT.css` and
38 /// `DATADIR/share/themes/THEME/gtk-VERSION/gtk-VARIANT.css`,
39 /// where `THEME` is the name of the current theme (see the
40 /// [`gtk-theme-name`][struct@crate::Settings#gtk-theme-name] setting), `VARIANT` is the
41 /// variant to load (see the
42 /// [`gtk-application-prefer-dark-theme`][struct@crate::Settings#gtk-application-prefer-dark-theme] setting),
43 /// `DATADIR` is the prefix configured when GTK was compiled (unless
44 /// overridden by the `GTK_DATA_PREFIX` environment variable), and
45 /// `VERSION` is the GTK version number. If no file is found for the
46 /// current version, GTK tries older versions all the way back to 4.0.
47 ///
48 /// To track errors while loading CSS, connect to the
49 /// [`parsing-error`][struct@crate::CssProvider#parsing-error] signal.
50 ///
51 /// ## Properties
52 ///
53 ///
54 /// #### `prefers-color-scheme`
55 /// Define the color scheme used for rendering the user interface.
56 ///
57 /// The UI can be set to either [enum@Gtk.InterfaceColorScheme.LIGHT],
58 /// or [enum@Gtk.InterfaceColorScheme.DARK] mode. Other values will
59 /// be interpreted the same as [enum@Gtk.InterfaceColorScheme.LIGHT].
60 ///
61 /// This setting is be available for media queries in CSS:
62 ///
63 /// ```css
64 /// @media (prefers-color-scheme: dark) {
65 /// // some dark mode styling
66 /// }
67 /// ```
68 ///
69 /// Changing this setting will reload the style sheet.
70 ///
71 /// Readable | Writeable
72 ///
73 ///
74 /// #### `prefers-contrast`
75 /// Define the contrast mode to use for the user interface.
76 ///
77 /// When set to [enum@Gtk.InterfaceContrast.MORE] or
78 /// [enum@Gtk.InterfaceContrast.LESS], the UI is rendered in
79 /// high or low contrast.
80 ///
81 /// When set to [enum@Gtk.InterfaceContrast.NO_PREFERENCE] (the default),
82 /// the user interface will be rendered in default mode.
83 ///
84 /// This setting is be available for media queries in CSS:
85 ///
86 /// ```css
87 /// @media (prefers-contrast: more) {
88 /// // some style with high contrast
89 /// }
90 /// ```
91 ///
92 /// Changing this setting will reload the style sheet.
93 ///
94 /// Readable | Writeable
95 ///
96 ///
97 /// #### `prefers-reduced-motion`
98 /// Define the type of reduced motion to use for the user interface.
99 ///
100 /// When set to [enum@Gtk.ReducedMotion.REDUCE] the UI is rendered in
101 /// with reduced motion animations.
102 ///
103 /// When set to [enum@Gtk.ReducedMotion.NO_PREFERENCE] (the default),
104 /// the user interface will be rendered in default mode.
105 ///
106 /// This setting is be available for media queries in CSS:
107 ///
108 /// ```css
109 /// @media (prefers-reduced-motion: reduce) {
110 /// // some style with reduced motion
111 /// }
112 /// ```
113 ///
114 /// Changing this setting will reload the style sheet.
115 ///
116 /// Readable | Writeable
117 ///
118 /// ## Signals
119 ///
120 ///
121 /// #### `parsing-error`
122 /// Signals that a parsing error occurred.
123 ///
124 /// The expected error values are in the [`CssParserError`][crate::CssParserError]
125 /// and [`CssParserWarning`][crate::CssParserWarning] enumerations.
126 ///
127 /// The @path, @line and @position describe the actual location of
128 /// the error as accurately as possible.
129 ///
130 /// Parsing errors are never fatal, so the parsing will resume after
131 /// the error. Errors may however cause parts of the given data or
132 /// even all of it to not be parsed at all. So it is a useful idea
133 /// to check that the parsing succeeds by connecting to this signal.
134 ///
135 /// Errors in the [`CssParserWarning`][crate::CssParserWarning] enumeration should not
136 /// be treated as fatal errors.
137 ///
138 /// Note that this signal may be emitted at any time as the css provider
139 /// may opt to defer parsing parts or all of the input to a later time
140 /// than when a loading function was called.
141 ///
142 ///
143 /// <details><summary><h4>StyleProvider</h4></summary>
144 ///
145 ///
146 /// #### `gtk-private-changed`
147 ///
148 /// </details>
149 ///
150 /// # Implements
151 ///
152 /// [`trait@glib::ObjectExt`], [`StyleProviderExt`][trait@crate::prelude::StyleProviderExt]
153 #[doc(alias = "GtkCssProvider")]
154 pub struct CssProvider(Object<ffi::GtkCssProvider, ffi::GtkCssProviderClass>) @implements StyleProvider;
155
156 match fn {
157 type_ => || ffi::gtk_css_provider_get_type(),
158 }
159}
160
161impl CssProvider {
162 /// Returns a newly created [`CssProvider`][crate::CssProvider].
163 ///
164 /// # Returns
165 ///
166 /// A new [`CssProvider`][crate::CssProvider]
167 #[doc(alias = "gtk_css_provider_new")]
168 pub fn new() -> CssProvider {
169 assert_initialized_main_thread!();
170 unsafe { from_glib_full(ffi::gtk_css_provider_new()) }
171 }
172
173 // rustdoc-stripper-ignore-next
174 /// Creates a new builder-pattern struct instance to construct [`CssProvider`] objects.
175 ///
176 /// This method returns an instance of [`CssProviderBuilder`](crate::builders::CssProviderBuilder) which can be used to create [`CssProvider`] objects.
177 pub fn builder() -> CssProviderBuilder {
178 CssProviderBuilder::new()
179 }
180
181 /// Loads @data into @self.
182 ///
183 /// This clears any previously loaded information.
184 /// ## `data`
185 /// `GBytes` containing the data to load
186 #[cfg(feature = "v4_12")]
187 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
188 #[doc(alias = "gtk_css_provider_load_from_bytes")]
189 pub fn load_from_bytes(&self, data: &glib::Bytes) {
190 unsafe {
191 ffi::gtk_css_provider_load_from_bytes(self.to_glib_none().0, data.to_glib_none().0);
192 }
193 }
194
195 /// Loads @data into @self.
196 ///
197 /// This clears any previously loaded information.
198 ///
199 /// # Deprecated since 4.12
200 ///
201 /// Use [`load_from_string()`][Self::load_from_string()]
202 /// or [`load_from_bytes()`][Self::load_from_bytes()] instead
203 /// ## `data`
204 /// CSS data to be parsed
205 /// ## `length`
206 /// the length of @data in bytes, or -1 for NUL terminated strings
207 #[cfg_attr(feature = "v4_12", deprecated = "Since 4.12")]
208 #[allow(deprecated)]
209 #[doc(alias = "gtk_css_provider_load_from_data")]
210 pub fn load_from_data(&self, data: &str) {
211 let length = data.len() as _;
212 unsafe {
213 ffi::gtk_css_provider_load_from_data(
214 self.to_glib_none().0,
215 data.to_glib_none().0,
216 length,
217 );
218 }
219 }
220
221 /// Loads the data contained in @file into @self.
222 ///
223 /// This clears any previously loaded information.
224 /// ## `file`
225 /// `GFile` pointing to a file to load
226 #[doc(alias = "gtk_css_provider_load_from_file")]
227 pub fn load_from_file(&self, file: &impl IsA<gio::File>) {
228 unsafe {
229 ffi::gtk_css_provider_load_from_file(
230 self.to_glib_none().0,
231 file.as_ref().to_glib_none().0,
232 );
233 }
234 }
235
236 /// Loads the data contained in @path into @self.
237 ///
238 /// This clears any previously loaded information.
239 /// ## `path`
240 /// the path of a filename to load, in the GLib filename encoding
241 #[doc(alias = "gtk_css_provider_load_from_path")]
242 pub fn load_from_path(&self, path: impl AsRef<std::path::Path>) {
243 unsafe {
244 ffi::gtk_css_provider_load_from_path(
245 self.to_glib_none().0,
246 path.as_ref().to_glib_none().0,
247 );
248 }
249 }
250
251 /// Loads the data contained in the resource at @resource_path into
252 /// the @self.
253 ///
254 /// This clears any previously loaded information.
255 /// ## `resource_path`
256 /// a `GResource` resource path
257 #[doc(alias = "gtk_css_provider_load_from_resource")]
258 pub fn load_from_resource(&self, resource_path: &str) {
259 unsafe {
260 ffi::gtk_css_provider_load_from_resource(
261 self.to_glib_none().0,
262 resource_path.to_glib_none().0,
263 );
264 }
265 }
266
267 /// Loads @string into @self.
268 ///
269 /// This clears any previously loaded information.
270 /// ## `string`
271 /// the CSS to load
272 #[cfg(feature = "v4_12")]
273 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
274 #[doc(alias = "gtk_css_provider_load_from_string")]
275 pub fn load_from_string(&self, string: &str) {
276 unsafe {
277 ffi::gtk_css_provider_load_from_string(self.to_glib_none().0, string.to_glib_none().0);
278 }
279 }
280
281 /// Loads a theme from the usual theme paths.
282 ///
283 /// The actual process of finding the theme might change between
284 /// releases, but it is guaranteed that this function uses the same
285 /// mechanism to load the theme that GTK uses for loading its own theme.
286 ///
287 /// # Deprecated since 4.20
288 ///
289 /// Using any of the other theme loaders, combine with media queries.
290 /// ## `name`
291 /// A theme name
292 /// ## `variant`
293 /// variant to load, for example, "dark", or
294 /// [`None`] for the default
295 #[cfg_attr(feature = "v4_20", deprecated = "Since 4.20")]
296 #[allow(deprecated)]
297 #[doc(alias = "gtk_css_provider_load_named")]
298 pub fn load_named(&self, name: &str, variant: Option<&str>) {
299 unsafe {
300 ffi::gtk_css_provider_load_named(
301 self.to_glib_none().0,
302 name.to_glib_none().0,
303 variant.to_glib_none().0,
304 );
305 }
306 }
307
308 /// Converts the @self into a string representation in CSS
309 /// format.
310 ///
311 /// Using [`load_from_string()`][Self::load_from_string()] with the return
312 /// value from this function on a new provider created with
313 /// [`new()`][Self::new()] will basically create a duplicate
314 /// of this @self.
315 ///
316 /// # Returns
317 ///
318 /// a new string representing the @self.
319 #[doc(alias = "gtk_css_provider_to_string")]
320 #[doc(alias = "to_string")]
321 pub fn to_str(&self) -> glib::GString {
322 unsafe { from_glib_full(ffi::gtk_css_provider_to_string(self.to_glib_none().0)) }
323 }
324
325 /// Define the color scheme used for rendering the user interface.
326 ///
327 /// The UI can be set to either [enum@Gtk.InterfaceColorScheme.LIGHT],
328 /// or [enum@Gtk.InterfaceColorScheme.DARK] mode. Other values will
329 /// be interpreted the same as [enum@Gtk.InterfaceColorScheme.LIGHT].
330 ///
331 /// This setting is be available for media queries in CSS:
332 ///
333 /// ```css
334 /// @media (prefers-color-scheme: dark) {
335 /// // some dark mode styling
336 /// }
337 /// ```
338 ///
339 /// Changing this setting will reload the style sheet.
340 #[cfg(feature = "v4_20")]
341 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
342 #[doc(alias = "prefers-color-scheme")]
343 pub fn prefers_color_scheme(&self) -> InterfaceColorScheme {
344 ObjectExt::property(self, "prefers-color-scheme")
345 }
346
347 /// Define the color scheme used for rendering the user interface.
348 ///
349 /// The UI can be set to either [enum@Gtk.InterfaceColorScheme.LIGHT],
350 /// or [enum@Gtk.InterfaceColorScheme.DARK] mode. Other values will
351 /// be interpreted the same as [enum@Gtk.InterfaceColorScheme.LIGHT].
352 ///
353 /// This setting is be available for media queries in CSS:
354 ///
355 /// ```css
356 /// @media (prefers-color-scheme: dark) {
357 /// // some dark mode styling
358 /// }
359 /// ```
360 ///
361 /// Changing this setting will reload the style sheet.
362 #[cfg(feature = "v4_20")]
363 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
364 #[doc(alias = "prefers-color-scheme")]
365 pub fn set_prefers_color_scheme(&self, prefers_color_scheme: InterfaceColorScheme) {
366 ObjectExt::set_property(self, "prefers-color-scheme", prefers_color_scheme)
367 }
368
369 /// Define the contrast mode to use for the user interface.
370 ///
371 /// When set to [enum@Gtk.InterfaceContrast.MORE] or
372 /// [enum@Gtk.InterfaceContrast.LESS], the UI is rendered in
373 /// high or low contrast.
374 ///
375 /// When set to [enum@Gtk.InterfaceContrast.NO_PREFERENCE] (the default),
376 /// the user interface will be rendered in default mode.
377 ///
378 /// This setting is be available for media queries in CSS:
379 ///
380 /// ```css
381 /// @media (prefers-contrast: more) {
382 /// // some style with high contrast
383 /// }
384 /// ```
385 ///
386 /// Changing this setting will reload the style sheet.
387 #[cfg(feature = "v4_20")]
388 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
389 #[doc(alias = "prefers-contrast")]
390 pub fn prefers_contrast(&self) -> InterfaceContrast {
391 ObjectExt::property(self, "prefers-contrast")
392 }
393
394 /// Define the contrast mode to use for the user interface.
395 ///
396 /// When set to [enum@Gtk.InterfaceContrast.MORE] or
397 /// [enum@Gtk.InterfaceContrast.LESS], the UI is rendered in
398 /// high or low contrast.
399 ///
400 /// When set to [enum@Gtk.InterfaceContrast.NO_PREFERENCE] (the default),
401 /// the user interface will be rendered in default mode.
402 ///
403 /// This setting is be available for media queries in CSS:
404 ///
405 /// ```css
406 /// @media (prefers-contrast: more) {
407 /// // some style with high contrast
408 /// }
409 /// ```
410 ///
411 /// Changing this setting will reload the style sheet.
412 #[cfg(feature = "v4_20")]
413 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
414 #[doc(alias = "prefers-contrast")]
415 pub fn set_prefers_contrast(&self, prefers_contrast: InterfaceContrast) {
416 ObjectExt::set_property(self, "prefers-contrast", prefers_contrast)
417 }
418
419 /// Define the type of reduced motion to use for the user interface.
420 ///
421 /// When set to [enum@Gtk.ReducedMotion.REDUCE] the UI is rendered in
422 /// with reduced motion animations.
423 ///
424 /// When set to [enum@Gtk.ReducedMotion.NO_PREFERENCE] (the default),
425 /// the user interface will be rendered in default mode.
426 ///
427 /// This setting is be available for media queries in CSS:
428 ///
429 /// ```css
430 /// @media (prefers-reduced-motion: reduce) {
431 /// // some style with reduced motion
432 /// }
433 /// ```
434 ///
435 /// Changing this setting will reload the style sheet.
436 #[cfg(feature = "v4_22")]
437 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
438 #[doc(alias = "prefers-reduced-motion")]
439 pub fn prefers_reduced_motion(&self) -> ReducedMotion {
440 ObjectExt::property(self, "prefers-reduced-motion")
441 }
442
443 /// Define the type of reduced motion to use for the user interface.
444 ///
445 /// When set to [enum@Gtk.ReducedMotion.REDUCE] the UI is rendered in
446 /// with reduced motion animations.
447 ///
448 /// When set to [enum@Gtk.ReducedMotion.NO_PREFERENCE] (the default),
449 /// the user interface will be rendered in default mode.
450 ///
451 /// This setting is be available for media queries in CSS:
452 ///
453 /// ```css
454 /// @media (prefers-reduced-motion: reduce) {
455 /// // some style with reduced motion
456 /// }
457 /// ```
458 ///
459 /// Changing this setting will reload the style sheet.
460 #[cfg(feature = "v4_22")]
461 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
462 #[doc(alias = "prefers-reduced-motion")]
463 pub fn set_prefers_reduced_motion(&self, prefers_reduced_motion: ReducedMotion) {
464 ObjectExt::set_property(self, "prefers-reduced-motion", prefers_reduced_motion)
465 }
466
467 /// Signals that a parsing error occurred.
468 ///
469 /// The expected error values are in the [`CssParserError`][crate::CssParserError]
470 /// and [`CssParserWarning`][crate::CssParserWarning] enumerations.
471 ///
472 /// The @path, @line and @position describe the actual location of
473 /// the error as accurately as possible.
474 ///
475 /// Parsing errors are never fatal, so the parsing will resume after
476 /// the error. Errors may however cause parts of the given data or
477 /// even all of it to not be parsed at all. So it is a useful idea
478 /// to check that the parsing succeeds by connecting to this signal.
479 ///
480 /// Errors in the [`CssParserWarning`][crate::CssParserWarning] enumeration should not
481 /// be treated as fatal errors.
482 ///
483 /// Note that this signal may be emitted at any time as the css provider
484 /// may opt to defer parsing parts or all of the input to a later time
485 /// than when a loading function was called.
486 /// ## `section`
487 /// section the error happened in
488 /// ## `error`
489 /// The parsing error
490 #[doc(alias = "parsing-error")]
491 pub fn connect_parsing_error<F: Fn(&Self, &CssSection, &glib::Error) + 'static>(
492 &self,
493 f: F,
494 ) -> SignalHandlerId {
495 unsafe extern "C" fn parsing_error_trampoline<
496 F: Fn(&CssProvider, &CssSection, &glib::Error) + 'static,
497 >(
498 this: *mut ffi::GtkCssProvider,
499 section: *mut ffi::GtkCssSection,
500 error: *mut glib::ffi::GError,
501 f: glib::ffi::gpointer,
502 ) {
503 let f: &F = &*(f as *const F);
504 f(
505 &from_glib_borrow(this),
506 &from_glib_borrow(section),
507 &from_glib_borrow(error),
508 )
509 }
510 unsafe {
511 let f: Box_<F> = Box_::new(f);
512 connect_raw(
513 self.as_ptr() as *mut _,
514 c"parsing-error".as_ptr() as *const _,
515 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
516 parsing_error_trampoline::<F> as *const (),
517 )),
518 Box_::into_raw(f),
519 )
520 }
521 }
522
523 #[cfg(feature = "v4_20")]
524 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
525 #[doc(alias = "prefers-color-scheme")]
526 pub fn connect_prefers_color_scheme_notify<F: Fn(&Self) + 'static>(
527 &self,
528 f: F,
529 ) -> SignalHandlerId {
530 unsafe extern "C" fn notify_prefers_color_scheme_trampoline<
531 F: Fn(&CssProvider) + 'static,
532 >(
533 this: *mut ffi::GtkCssProvider,
534 _param_spec: glib::ffi::gpointer,
535 f: glib::ffi::gpointer,
536 ) {
537 let f: &F = &*(f as *const F);
538 f(&from_glib_borrow(this))
539 }
540 unsafe {
541 let f: Box_<F> = Box_::new(f);
542 connect_raw(
543 self.as_ptr() as *mut _,
544 c"notify::prefers-color-scheme".as_ptr() as *const _,
545 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
546 notify_prefers_color_scheme_trampoline::<F> as *const (),
547 )),
548 Box_::into_raw(f),
549 )
550 }
551 }
552
553 #[cfg(feature = "v4_20")]
554 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
555 #[doc(alias = "prefers-contrast")]
556 pub fn connect_prefers_contrast_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
557 unsafe extern "C" fn notify_prefers_contrast_trampoline<F: Fn(&CssProvider) + 'static>(
558 this: *mut ffi::GtkCssProvider,
559 _param_spec: glib::ffi::gpointer,
560 f: glib::ffi::gpointer,
561 ) {
562 let f: &F = &*(f as *const F);
563 f(&from_glib_borrow(this))
564 }
565 unsafe {
566 let f: Box_<F> = Box_::new(f);
567 connect_raw(
568 self.as_ptr() as *mut _,
569 c"notify::prefers-contrast".as_ptr() as *const _,
570 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
571 notify_prefers_contrast_trampoline::<F> as *const (),
572 )),
573 Box_::into_raw(f),
574 )
575 }
576 }
577
578 #[cfg(feature = "v4_22")]
579 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
580 #[doc(alias = "prefers-reduced-motion")]
581 pub fn connect_prefers_reduced_motion_notify<F: Fn(&Self) + 'static>(
582 &self,
583 f: F,
584 ) -> SignalHandlerId {
585 unsafe extern "C" fn notify_prefers_reduced_motion_trampoline<
586 F: Fn(&CssProvider) + 'static,
587 >(
588 this: *mut ffi::GtkCssProvider,
589 _param_spec: glib::ffi::gpointer,
590 f: glib::ffi::gpointer,
591 ) {
592 let f: &F = &*(f as *const F);
593 f(&from_glib_borrow(this))
594 }
595 unsafe {
596 let f: Box_<F> = Box_::new(f);
597 connect_raw(
598 self.as_ptr() as *mut _,
599 c"notify::prefers-reduced-motion".as_ptr() as *const _,
600 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
601 notify_prefers_reduced_motion_trampoline::<F> as *const (),
602 )),
603 Box_::into_raw(f),
604 )
605 }
606 }
607}
608
609impl Default for CssProvider {
610 fn default() -> Self {
611 Self::new()
612 }
613}
614
615impl std::fmt::Display for CssProvider {
616 #[inline]
617 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
618 f.write_str(&self.to_str())
619 }
620}
621
622// rustdoc-stripper-ignore-next
623/// A [builder-pattern] type to construct [`CssProvider`] objects.
624///
625/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
626#[must_use = "The builder must be built to be used"]
627pub struct CssProviderBuilder {
628 builder: glib::object::ObjectBuilder<'static, CssProvider>,
629}
630
631impl CssProviderBuilder {
632 fn new() -> Self {
633 Self {
634 builder: glib::object::Object::builder(),
635 }
636 }
637
638 /// Define the color scheme used for rendering the user interface.
639 ///
640 /// The UI can be set to either [enum@Gtk.InterfaceColorScheme.LIGHT],
641 /// or [enum@Gtk.InterfaceColorScheme.DARK] mode. Other values will
642 /// be interpreted the same as [enum@Gtk.InterfaceColorScheme.LIGHT].
643 ///
644 /// This setting is be available for media queries in CSS:
645 ///
646 /// ```css
647 /// @media (prefers-color-scheme: dark) {
648 /// // some dark mode styling
649 /// }
650 /// ```
651 ///
652 /// Changing this setting will reload the style sheet.
653 #[cfg(feature = "v4_20")]
654 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
655 pub fn prefers_color_scheme(self, prefers_color_scheme: InterfaceColorScheme) -> Self {
656 Self {
657 builder: self
658 .builder
659 .property("prefers-color-scheme", prefers_color_scheme),
660 }
661 }
662
663 /// Define the contrast mode to use for the user interface.
664 ///
665 /// When set to [enum@Gtk.InterfaceContrast.MORE] or
666 /// [enum@Gtk.InterfaceContrast.LESS], the UI is rendered in
667 /// high or low contrast.
668 ///
669 /// When set to [enum@Gtk.InterfaceContrast.NO_PREFERENCE] (the default),
670 /// the user interface will be rendered in default mode.
671 ///
672 /// This setting is be available for media queries in CSS:
673 ///
674 /// ```css
675 /// @media (prefers-contrast: more) {
676 /// // some style with high contrast
677 /// }
678 /// ```
679 ///
680 /// Changing this setting will reload the style sheet.
681 #[cfg(feature = "v4_20")]
682 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
683 pub fn prefers_contrast(self, prefers_contrast: InterfaceContrast) -> Self {
684 Self {
685 builder: self.builder.property("prefers-contrast", prefers_contrast),
686 }
687 }
688
689 /// Define the type of reduced motion to use for the user interface.
690 ///
691 /// When set to [enum@Gtk.ReducedMotion.REDUCE] the UI is rendered in
692 /// with reduced motion animations.
693 ///
694 /// When set to [enum@Gtk.ReducedMotion.NO_PREFERENCE] (the default),
695 /// the user interface will be rendered in default mode.
696 ///
697 /// This setting is be available for media queries in CSS:
698 ///
699 /// ```css
700 /// @media (prefers-reduced-motion: reduce) {
701 /// // some style with reduced motion
702 /// }
703 /// ```
704 ///
705 /// Changing this setting will reload the style sheet.
706 #[cfg(feature = "v4_22")]
707 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
708 pub fn prefers_reduced_motion(self, prefers_reduced_motion: ReducedMotion) -> Self {
709 Self {
710 builder: self
711 .builder
712 .property("prefers-reduced-motion", prefers_reduced_motion),
713 }
714 }
715
716 // rustdoc-stripper-ignore-next
717 /// Build the [`CssProvider`].
718 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
719 pub fn build(self) -> CssProvider {
720 assert_initialized_main_thread!();
721 self.builder.build()
722 }
723}