diff options
Diffstat (limited to 'src/preferences/pages/editor.rs')
| -rw-r--r-- | src/preferences/pages/editor.rs | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/src/preferences/pages/editor.rs b/src/preferences/pages/editor.rs index 27b94da..c0e9b41 100644 --- a/src/preferences/pages/editor.rs +++ b/src/preferences/pages/editor.rs @@ -31,7 +31,7 @@ pub struct EditorPage { font_size_scale: gtk::Scale, soft_wrap_switch: gtk::Switch, custom_font_switch: gtk::Switch, - font_button: gtk::FontButton, + font_button: gtk::FontDialogButton, } impl EditorPage { @@ -124,21 +124,23 @@ impl EditorPage { (soft_wrap_row.1, custom_font_row.1) } - fn create_font_button(preferences: &UserPreferences) -> gtk::FontButton { - let button = gtk::FontButton::new(); + fn create_font_button(preferences: &UserPreferences) -> gtk::FontDialogButton { + let font_dialog = gtk::FontDialog::new(); + let font_button = gtk::FontDialogButton::new(Some(font_dialog)); #[allow(clippy::cast_possible_truncation)] - button.set_font(&format!( + let font_desc = gtk::pango::FontDescription::from_string(&format!( "{} {}", preferences.custom_editor_font_name, preferences.editor_font_size as i32 )); - button.set_sensitive(preferences.use_custom_editor_font); - button.set_hexpand(true); - button.set_use_font(true); - button.set_use_size(false); - button + font_button.set_font_desc(&font_desc); + font_button.set_sensitive(preferences.use_custom_editor_font); + font_button.set_hexpand(true); + font_button.set_use_font(true); + font_button.set_use_size(false); + font_button } - fn create_font_row(font_button: >k::FontButton) -> gtk::Box { + fn create_font_row(font_button: >k::FontDialogButton) -> gtk::Box { let row = gtk::Box::new(gtk::Orientation::Horizontal, 10); row.append(>k::Label::new(Some(&tr!("preferences.editor.font")))); row.append(font_button); @@ -150,7 +152,7 @@ impl EditorPage { font_size_scale: >k::Scale, soft_wrap_switch: >k::Switch, custom_font_switch: >k::Switch, - font_button: >k::FontButton, + font_button: >k::FontDialogButton, ) { let s = sender.clone(); let fb = font_button.clone(); @@ -167,15 +169,14 @@ impl EditorPage { let s = sender.clone(); let scale = font_size_scale.clone(); - font_button.connect_font_set(move |button| { - if let Some(font) = button.font() { - let font_desc = gtk::pango::FontDescription::from_string(&font); - if let Some(family) = font_desc.family() { + font_button.connect_font_desc_notify(move |button| { + if let Some(font) = button.font_desc() { + if let Some(family) = font.family() { s.emit(PreferencesInput::SetCustomEditorFontName( family.to_string(), )); } - let size = font_desc.size() / gtk::pango::SCALE; + let size = font.size() / gtk::pango::SCALE; if size > 0 { scale.set_value(f64::from(size)); } @@ -191,12 +192,11 @@ impl EditorPage { }); } - fn update_font_button_size(font_button: >k::FontButton, size: f64) { - if let Some(font) = font_button.font() { - let mut font_desc = gtk::pango::FontDescription::from_string(&font); + fn update_font_button_size(font_button: >k::FontDialogButton, size: f64) { + if let Some(mut font_desc) = font_button.font_desc() { #[allow(clippy::cast_possible_truncation)] font_desc.set_size(size as i32 * gtk::pango::SCALE); - font_button.set_font(&font_desc.to_string()); + font_button.set_font_desc(&font_desc); } } @@ -213,9 +213,10 @@ impl EditorPage { self.font_button .set_sensitive(preferences.use_custom_editor_font); #[allow(clippy::cast_possible_truncation)] - self.font_button.set_font(&format!( + let font_desc = gtk::pango::FontDescription::from_string(&format!( "{} {}", preferences.custom_editor_font_name, preferences.editor_font_size as i32 )); + self.font_button.set_font_desc(&font_desc); } } |