~exprez135/castor

d2afc4bf3a387a89bdaa875b62dd36614c8c85ae — mira 1 year, 4 months ago 75c3cdb
Add max_width setting
4 files changed, 12 insertions(+), 1 deletions(-)

M README.md
M data/castor_settings.toml.example
M src/draw.rs
M src/settings.rs
M README.md => README.md +1 -0
@@ 69,6 69,7 @@ These are the keys currently supported, you can use hex codes, plain colors name
```
[general]
start_url = "gemini://gemini.circumlunar.space/capcom"
max_width = 200

[colors]
h1 = "red"

M data/castor_settings.toml.example => data/castor_settings.toml.example +1 -0
@@ 1,5 1,6 @@
[general]
start_url = "gemini://gemini.circumlunar.space/capcom"
max_width = 200

[colors]
h1 = "red"

M src/draw.rs => src/draw.rs +2 -1
@@ 454,5 454,6 @@ fn mono_span(text: String) -> String {

fn width(gui: &Arc<Gui>) -> usize {
    let (win_width, _) = gtk::ApplicationWindow::get_size(gui.window());
    (win_width / 10).try_into().unwrap()
    let calculated_width = (win_width / 10).try_into().unwrap();
    std::cmp::min(calculated_width, crate::settings::max_width().unwrap_or(std::usize::MAX))
}

M src/settings.rs => src/settings.rs +8 -0
@@ 18,6 18,7 @@ struct Settings {
#[derive(Deserialize)]
struct General {
    start_url: Option<String>,
    max_width: Option<usize>,
}

#[derive(Deserialize)]


@@ 76,6 77,13 @@ pub fn start_url() -> Option<String> {
    }
}

pub fn max_width() -> Option<usize> {
    match read().general {
        Some(general) => general.max_width,
        None => None,
    }
}

const DEFAULT_FONT: &str = "serif";
const DEFAULT_FONT_STYLE: &str = "normal";
const DEFAULT_FONT_SIZE: i32 = 11 * pango_sys::PANGO_SCALE;