From 2485595b58c6d6e86265ec4a0396d6c40d497b21 Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 26 Sep 2024 16:20:07 +0300 Subject: [PATCH] connect css provider --- .../page/content/text/gemini/reader/mod.rs | 45 +++++++++++++------ 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/src/browser/main/tab/page/content/text/gemini/reader/mod.rs b/src/browser/main/tab/page/content/text/gemini/reader/mod.rs index d3198e9b..1a9a5731 100644 --- a/src/browser/main/tab/page/content/text/gemini/reader/mod.rs +++ b/src/browser/main/tab/page/content/text/gemini/reader/mod.rs @@ -1,25 +1,42 @@ -use gtk::{Align, Label}; +use gtk::{ + prelude::{StyleContextExt, WidgetExt}, + Align, CssProvider, Label, STYLE_PROVIDER_PRIORITY_APPLICATION, +}; pub struct Reader { + css: CssProvider, widget: Label, } impl Reader { // Construct pub fn new(gemtext: &str) -> Self { - Self { - widget: Label::builder() - .halign(Align::Start) - .valign(Align::Start) - .vexpand(true) - .margin_start(8) - .margin_end(8) - .wrap(true) - .selectable(true) - .use_markup(true) - .label(gemtext) // @TODO - .build(), - } + // Init CSS + let css = CssProvider::new(); + + css.load_from_path( + "src/browser/main/tab/page/content/text/gemini/reader/default.css", // @TODO + ); + + // Init widget + let widget = Label::builder() + .halign(Align::Start) + .valign(Align::Start) + .vexpand(true) + .margin_start(8) + .margin_end(8) + .wrap(true) + .selectable(true) + .use_markup(true) + .label(gemtext) // @TODO + .build(); + + widget + .style_context() + .add_provider(&css, STYLE_PROVIDER_PRIORITY_APPLICATION); + + // Result + Self { css, widget } } // Getters