Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ if host_machine.system() == 'android'
'src/ui/pages/status_page.vala',
'src/ui/pages/welcome_page.vala',
'src/ui/preferences/app_settings_list_group.vala',
'src/ui/preferences/monospace_font_row.vala',
'src/ui/preferences/preferences.vala',
'src/ui/preferences/preferences_page.vala',
'src/ui/preferences/preferences_window.vala',
Expand Down Expand Up @@ -347,6 +348,7 @@ libsingularity_sources = files(
'src/ui/preferences/preferences_window.vala',
'src/ui/preferences/preferences_page.vala',
'src/ui/preferences/app_settings_list_group.vala',
'src/ui/preferences/monospace_font_row.vala',
'src/ui/pages/page_hero.vala',
'src/ui/pages/status_page.vala',
'src/ui/controls/search_entry.vala',
Expand Down
14 changes: 11 additions & 3 deletions src/core/app_settings_loader.vala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ namespace Singularity.Core {
* A single preference item inside an AppSettingsDescriptor.
*
* The `widget` field selects the UI control (`toggle`, `slider`,
* `combo`, `entry`, ..). Numeric `min`/`max` apply to sliders.
* `combo`, `entry`, `monospace-font-selector`, ..). Numeric `min`/`max`
* apply to sliders.
*/
public class AppSettingItem : GLib.Object {
/** GSettings key this item controls. */
Expand All @@ -62,7 +63,13 @@ namespace Singularity.Core {
/** GSettings value type (`"boolean"`, `"int"`, `"string"`, ..). */
public string setting_type { get; set; }

/** Widget type hint (`"toggle"`, `"slider"`, `"combo"`, `"entry"`, `"color-scheme-selector"`, ..). */
/**
* Widget type hint (`"toggle"`, `"slider"`, `"combo"`, `"entry"`,
* `"color-scheme-selector"`, `"monospace-font-selector"`, ..).
*
* `"monospace-font-selector"` applies to a string key and stores the
* chosen font family name.
*/
public string widget { get; set; }

/**
Expand Down Expand Up @@ -140,7 +147,8 @@ namespace Singularity.Core {
* { "key": "enable-feature", "label": "Enable feature", "subtitle": "Optional hint", "type": "boolean", "widget": "toggle", "profile": true },
* { "key": "font-size", "label": "Font size", "type": "int", "widget": "slider", "min": 8, "max": 32 },
* { "key": "mode", "label": "Mode", "type": "string", "widget": "combo",
* "options": [ { "id": "a", "label": "A", "subtitle": "Optional hint" } ] }
* "options": [ { "id": "a", "label": "A", "subtitle": "Optional hint" } ] },
* { "key": "font-family", "label": "Font family", "type": "string", "widget": "monospace-font-selector" }
* ]
* }
* }}}
Expand Down
35 changes: 35 additions & 0 deletions src/ui/preferences/monospace_font_row.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Gtk;

namespace Singularity.Widgets {

/**
* A SelectionRow that lists the installed monospace font families.
*
* The selected value is a font family name, for terminals, editors and
* other apps that let the user pick a fixed-width font.
*/
public class MonospaceFontRow : SelectionRow {

/**
* Creates a row listing the installed monospace font families.
*
* @param title Row label.
* @param current Currently selected family. It is always listed,
* also when that font is no longer installed.
*/
public MonospaceFontRow(string title, string current = "") {
base(title, families(current), current);
}

private static string[] families(string current) {
var names = new Gee.TreeSet<string>((a, b) => a.collate(b));
(unowned Pango.FontFamily)[] installed;
Pango.CairoFontMap.get_default().list_families(out installed);
foreach (unowned var family in installed) {
if (family.is_monospace()) names.add(family.get_name());
}
if (current != "") names.add(current);
return names.to_array();
}
}
}