Add font size option, fixes #6

This commit is contained in:
JerryXiao 2022-06-07 18:51:08 +08:00
parent 3443a18445
commit f5c14d2541
Signed by: Jerry
GPG key ID: 22618F758B5BE2E5
4 changed files with 82 additions and 36 deletions

View file

@ -35,12 +35,16 @@ class Extension {
let text2 = this.settings_get('get_string', 'text-l2')
let vl2 = this.settings_get('get_double', 'l2-vertical')
let hl2 = this.settings_get('get_double', 'l2-horizontal')
let size1 = parseInt(this.settings_get('get_double', 'size-l1'))
let size2 = parseInt(this.settings_get('get_double', 'size-l2'))
let opacity = this.settings_get('get_double', 'opacity')
this.cleanup()
for (let monitor of Main.layoutManager.monitors) {
let label_1 = new St.Label({style_class: 'label-1', text: text1, opacity})
let label_2 = new St.Label({style_class: 'label-2', text: text2, opacity})
label_1.set_style(`font-size: ${size1}px`)
label_2.set_style(`font-size: ${size2}px`)
Main.layoutManager.uiGroup.add_actor(label_2, {"trackFullscreen": false})
Main.layoutManager.uiGroup.add_actor(label_1, {"trackFullscreen": false})
this.labels.push(label_1)

View file

@ -21,102 +21,138 @@ function buildPrefsWidget() {
})
// line 1
let l1label = new Gtk.Label({
let label_line_1 = new Gtk.Label({
label: '<b>Line 1</b>',
margin_top: 6,
use_markup: true,
})
prefsWidget.append(l1label)
prefsWidget.append(label_line_1)
let l1entry = new Gtk.Entry({
let entry_line_1 = new Gtk.Entry({
margin_top: 6,
hexpand: true,
})
l1entry.set_width_chars(30)
prefsWidget.append(l1entry)
entry_line_1.set_width_chars(30)
prefsWidget.append(entry_line_1)
// line 2
let l2label = new Gtk.Label({
let label_line_2 = new Gtk.Label({
label: '<b>Line 2</b>',
margin_top: 6,
use_markup: true,
})
prefsWidget.append(l2label)
prefsWidget.append(label_line_2)
let l2entry = new Gtk.Entry({
let entry_line_2 = new Gtk.Entry({
margin_top: 6,
hexpand: true,
})
l2entry.set_width_chars(30)
prefsWidget.append(l2entry)
entry_line_2.set_width_chars(30)
prefsWidget.append(entry_line_2)
// l2-vertical
let vlabel = new Gtk.Label({
// line 2 vertical position
let label_line_2_vertical_position = new Gtk.Label({
label: '<b>Vertical Position</b>',
margin_top: 12,
use_markup: true,
})
prefsWidget.append(vlabel)
prefsWidget.append(label_line_2_vertical_position)
let ventry = new Gtk.SpinButton({
let scale_line_2_vertical_position = new Gtk.Scale({
adjustment: new Gtk.Adjustment({lower: 0.01, upper: 1.0, step_increment: 0.01, page_increment: 0.1}),
margin_top: 6,
numeric: true,
draw_value: false,
digits: 4,
})
prefsWidget.append(ventry)
prefsWidget.append(scale_line_2_vertical_position)
// l2-horizontal
let hlabel = new Gtk.Label({
// line 2 horizontal position
let label_line_2_horizontal_position = new Gtk.Label({
label: '<b>Horizontal Position</b>',
margin_top: 6,
use_markup: true,
})
prefsWidget.append(hlabel)
prefsWidget.append(label_line_2_horizontal_position)
let hentry = new Gtk.SpinButton({
let scale_line_2_horizontal_position = new Gtk.Scale({
adjustment: new Gtk.Adjustment({lower: 0.01, upper: 1.0, step_increment: 0.01, page_increment: 0.1}),
margin_top: 6,
numeric: true,
draw_value: false,
digits: 4,
})
prefsWidget.append(hentry)
prefsWidget.append(scale_line_2_horizontal_position)
// line 1 text size
let label_line_1_text_size = new Gtk.Label({
label: '<b>Line 1 Text Size</b>',
margin_top: 12,
use_markup: true,
})
prefsWidget.append(label_line_1_text_size)
let spinbutton_line_1_text_size = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({lower: 1.0, upper: 65535.0, step_increment: 1.0, page_increment: 10.0}),
margin_top: 6,
numeric: true,
digits: 1,
})
prefsWidget.append(spinbutton_line_1_text_size)
// line 2 text size
let label_line_2_text_size = new Gtk.Label({
label: '<b>Line 2 Text Size</b>',
margin_top: 6,
use_markup: true,
})
prefsWidget.append(label_line_2_text_size)
let spinbutton_line_2_text_size = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({lower: 1.0, upper: 65535.0, step_increment: 1.0, page_increment: 10.0}),
margin_top: 6,
numeric: true,
digits: 1,
})
prefsWidget.append(spinbutton_line_2_text_size)
// opacity
let olabel = new Gtk.Label({
let label_opacity = new Gtk.Label({
label: '<b>Opacity</b>',
margin_top: 6,
use_markup: true,
})
prefsWidget.append(olabel)
prefsWidget.append(label_opacity)
let oentry = new Gtk.Scale({
let scale_opacity = new Gtk.Scale({
adjustment: new Gtk.Adjustment({lower: 0.1, upper: 255, step_increment: 0.1, page_increment: 1}),
margin_top: 6,
draw_value: false,
digits: 1,
})
prefsWidget.append(oentry)
prefsWidget.append(scale_opacity)
let resetbtn = new Gtk.Button({
let button_reset = new Gtk.Button({
label: 'reset',
margin_top: 12,
margin_bottom: 6,
})
resetbtn.connect('clicked', () => {
button_reset.connect('clicked', () => {
this.settings.reset('text-l1')
this.settings.reset('text-l2')
this.settings.reset('l2-vertical')
this.settings.reset('l2-horizontal')
this.settings.reset('size-l1')
this.settings.reset('size-l2')
this.settings.reset('opacity')
})
prefsWidget.append(resetbtn)
prefsWidget.append(button_reset)
this.settings.bind('text-l1', l1entry, 'text', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('text-l2', l2entry, 'text', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('l2-vertical', ventry.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('l2-horizontal', hentry.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('opacity', oentry.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('text-l1', entry_line_1, 'text', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('text-l2', entry_line_2, 'text', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('l2-vertical', scale_line_2_vertical_position.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('l2-horizontal', scale_line_2_horizontal_position.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('size-l1', spinbutton_line_1_text_size.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('size-l2', spinbutton_line_2_text_size.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT)
this.settings.bind('opacity', scale_opacity.adjustment, 'value', Gio.SettingsBindFlags.DEFAULT)
return prefsWidget
}

View file

@ -22,5 +22,13 @@
<default>102</default>
<summary>Opacity</summary>
</key>
<key name="size-l1" type="d">
<default>36</default>
<summary>Text size of line 1 (px)</summary>
</key>
<key name="size-l2" type="d">
<default>26</default>
<summary>Text size of line 2 (px)</summary>
</key>
</schema>
</schemalist>

View file

@ -1,13 +1,11 @@
/* Add your custom extension styling here */
.label-1 {
font-size: 36px;
font-weight: normal;
color: rgba(255, 255, 255, 1);
background-color: rgba(0, 0, 0, 0);
border-radius: 5px;
}
.label-2 {
font-size: 26px;
font-weight: normal;
color: rgba(255, 255, 255, 1);
background-color: rgba(0, 0, 0, 0);