connect css provider

This commit is contained in:
yggverse 2024-09-26 16:20:07 +03:00
parent 40a212199b
commit 2485595b58

View File

@ -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