Skip to content

Commit 9037c55

Browse files
committed
use Properties from glib::, improve draw_ctx::clear
1 parent fa9512b commit 9037c55

File tree

5 files changed

+18
-24
lines changed

5 files changed

+18
-24
lines changed

Cargo.lock

Lines changed: 8 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ serde = { version = "1.0.116", features = ["derive"] }
2828
env_logger = "0.8.1"
2929
log = "0.4.0"
3030
adw = { package = "libadwaita", git = "https://gitlab.gnome.org/World/Rust/libadwaita-rs.git"}
31-
glib-macros = {git = "https://github.com/ranfdev/gtk-rs-core.git", branch = "props_macro"}
3231

3332
[patch."https://github.com/gtk-rs/gtk-rs-core.git"]
3433
glib = {git = "https://github.com/ranfdev/gtk-rs-core.git", branch = "props_macro"}

src/draw_ctx.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl DrawCtx {
1515
let text_buffer = gtk::TextBuffer::new(None);
1616
text_view.set_buffer(Some(&text_buffer));
1717

18-
let this = Self {
18+
let mut this = Self {
1919
text_view,
2020
text_buffer,
2121
config,
@@ -24,9 +24,9 @@ impl DrawCtx {
2424
this
2525
}
2626

27-
pub fn init_tags(&self) -> gtk::TextTagTable {
27+
pub fn init_tags(&mut self) -> gtk::TextTagTable {
2828
let default_config = &config::DEFAULT_CONFIG;
29-
let tag_table = gtk::TextTagTable::new();
29+
let tag_table = self.text_buffer.tag_table();
3030
let tag_h1 = DrawCtx::create_tag("h1", {
3131
self.config
3232
.fonts
@@ -219,8 +219,5 @@ impl DrawCtx {
219219
pub fn clear(&mut self) {
220220
let b = &self.text_buffer;
221221
b.delete(&mut b.start_iter(), &mut b.end_iter());
222-
223-
self.text_buffer = gtk::TextBuffer::new(Some(&self.init_tags()));
224-
self.text_view.set_buffer(Some(&self.text_buffer));
225222
}
226223
}

src/tab.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use futures::future::RemoteHandle;
44
use futures::io::BufReader;
55
use futures::prelude::*;
66
use futures::task::LocalSpawnExt;
7-
use glib_macros::Properties;
87
use gtk::gdk::prelude::*;
98
use gtk::gio;
109
use gtk::glib;
@@ -17,6 +16,7 @@ use std::marker::PhantomData;
1716
use std::pin::Pin;
1817
use std::rc::Rc;
1918
use url::Url;
19+
use glib::Properties;
2020

2121
use crate::common;
2222
use crate::common::{glibctx, HistoryItem, LossyTextRead, PageElement, RequestCtx};
@@ -310,7 +310,7 @@ impl Tab {
310310
async move {
311311
let buf = BufReader::new(&*cache);
312312
draw_ctx.clear();
313-
let res = this.display_gemini(&mut draw_ctx, buf).await;
313+
let res = this.display_gemini(buf).await;
314314
match res {
315315
Ok(_) => {
316316
info!("Loaded {} from cache", &url);
@@ -412,7 +412,7 @@ impl Tab {
412412
let lines = BufReader::new(file);
413413
match path.extension().map(|x| x.to_str()) {
414414
Some(Some("gmi")) | Some(Some("gemini")) => {
415-
this.display_gemini(&mut req.draw_ctx, lines).await?;
415+
this.display_gemini(lines).await?;
416416
}
417417
_ => {
418418
Self::display_text(&mut req.draw_ctx, lines).await?;
@@ -426,7 +426,7 @@ impl Tab {
426426
match req.url.scheme() {
427427
"about" => {
428428
let reader = futures::io::BufReader::new(common::ABOUT_PAGE.as_bytes());
429-
this.display_gemini(&mut req.draw_ctx, reader).await?;
429+
this.display_gemini(reader).await?;
430430
Ok(None)
431431
}
432432
"file" => {
@@ -458,7 +458,7 @@ impl Tab {
458458
let body = res.body().context("Body not found")?;
459459
let buffered = futures::io::BufReader::new(body);
460460
if meta.contains("text/gemini") {
461-
let res = this.display_gemini(&mut req.draw_ctx, buffered).await?;
461+
let res = this.display_gemini(buffered).await?;
462462
Some(res)
463463
} else if meta.contains("text") {
464464
Self::display_text(&mut req.draw_ctx, buffered).await?;
@@ -634,10 +634,10 @@ click on the button below\n",
634634
}
635635
async fn display_gemini<T: AsyncBufRead + Unpin>(
636636
&self,
637-
draw_ctx: &mut DrawCtx,
638637
mut reader: T,
639638
) -> anyhow::Result<Vec<u8>> {
640639
let imp = self.imp();
640+
let mut draw_ctx = imp.draw_ctx.borrow().clone().unwrap();
641641

642642
let mut parser = gemini::Parser::new();
643643
let mut text_iter = draw_ctx.text_buffer.end_iter();

src/window.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use adw::prelude::*;
22
use adw::subclass::application_window::AdwApplicationWindowImpl;
33
use anyhow::Context;
44
use futures::prelude::*;
5-
use glib::clone;
6-
use glib_macros::Properties;
5+
use glib::{clone, Properties};
76
use gtk::gdk;
87
use gtk::gio;
98
use gtk::glib;

0 commit comments

Comments
 (0)