Browse Source

Add max_width setting

debug-epoch
mira 10 months ago
parent
commit
d2afc4bf3a
4 changed files with 12 additions and 1 deletions
  1. 1
    0
      README.md
  2. 1
    0
      data/castor_settings.toml.example
  3. 2
    1
      src/draw.rs
  4. 8
    0
      src/settings.rs

+ 1
- 0
README.md View File

@@ -69,6 +69,7 @@ These are the keys currently supported, you can use hex codes, plain colors name
69 69
 ```
70 70
 [general]
71 71
 start_url = "gemini://gemini.circumlunar.space/capcom"
72
+max_width = 200
72 73
 
73 74
 [colors]
74 75
 h1 = "red"

+ 1
- 0
data/castor_settings.toml.example View File

@@ -1,5 +1,6 @@
1 1
 [general]
2 2
 start_url = "gemini://gemini.circumlunar.space/capcom"
3
+max_width = 200
3 4
 
4 5
 [colors]
5 6
 h1 = "red"

+ 2
- 1
src/draw.rs View File

@@ -454,5 +454,6 @@ fn mono_span(text: String) -> String {
454 454
 
455 455
 fn width(gui: &Arc<Gui>) -> usize {
456 456
     let (win_width, _) = gtk::ApplicationWindow::get_size(gui.window());
457
-    (win_width / 10).try_into().unwrap()
457
+    let calculated_width = (win_width / 10).try_into().unwrap();
458
+    std::cmp::min(calculated_width, crate::settings::max_width().unwrap_or(std::usize::MAX))
458 459
 }

+ 8
- 0
src/settings.rs View File

@@ -18,6 +18,7 @@ struct Settings {
18 18
 #[derive(Deserialize)]
19 19
 struct General {
20 20
     start_url: Option<String>,
21
+    max_width: Option<usize>,
21 22
 }
22 23
 
23 24
 #[derive(Deserialize)]
@@ -76,6 +77,13 @@ pub fn start_url() -> Option<String> {
76 77
     }
77 78
 }
78 79
 
80
+pub fn max_width() -> Option<usize> {
81
+    match read().general {
82
+        Some(general) => general.max_width,
83
+        None => None,
84
+    }
85
+}
86
+
79 87
 const DEFAULT_FONT: &str = "serif";
80 88
 const DEFAULT_FONT_STYLE: &str = "normal";
81 89
 const DEFAULT_FONT_SIZE: i32 = 11 * pango_sys::PANGO_SCALE;

Loading…
Cancel
Save