1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright 2013-2020, The Gtk-rs Project Developers.
// See the COPYRIGHT file at the top-level directory of this distribution.
// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>

use glib::object::IsA;
use pango::FontDescription;
use StateFlags;
use StyleContext;
use StyleContextExt;

pub trait StyleContextExtManual: 'static {
    /// Returns the font description for a given state. The returned
    /// object is const and will remain valid until the
    /// `StyleContext::changed` signal happens.
    ///
    /// ## `state`
    /// state to retrieve the font for
    ///
    /// # Returns
    ///
    /// the `pango::FontDescription` for the given state.
    fn get_font(&self, state: StateFlags) -> FontDescription;
}

impl<O: IsA<StyleContext>> StyleContextExtManual for O {
    fn get_font(&self, state: StateFlags) -> FontDescription {
        self.get_property("font", state)
            .get()
            .expect("font property is not pango::FontDescription")
            .expect("font property is empty")
    }
}