mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
begin Label with TextView replacement
This commit is contained in:
parent
5798b990ad
commit
46fa31ab16
@ -33,7 +33,7 @@ impl Text {
|
||||
// Init widget
|
||||
let widget = ScrolledWindow::builder().build();
|
||||
|
||||
widget.set_child(Some(gemini.widget()));
|
||||
widget.set_child(Some(gemini.gobject()));
|
||||
|
||||
// Result
|
||||
Self { meta, widget }
|
||||
|
@ -1,30 +1,30 @@
|
||||
mod reader;
|
||||
mod widget;
|
||||
|
||||
use reader::Reader;
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::{GString, Uri},
|
||||
Viewport,
|
||||
};
|
||||
|
||||
use adw::ClampScrollable;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Gemini {
|
||||
reader: Reader,
|
||||
widget: Viewport,
|
||||
reader: Arc<Reader>,
|
||||
widget: Arc<Widget>,
|
||||
}
|
||||
|
||||
impl Gemini {
|
||||
// Construct
|
||||
pub fn new(gemtext: &str, base: &Uri, action_page_open: Arc<SimpleAction>) -> Self {
|
||||
// Init components
|
||||
let reader = Reader::new(gemtext, base, action_page_open);
|
||||
let reader = Reader::new_arc(gemtext, base, action_page_open);
|
||||
|
||||
// Init widget
|
||||
let widget = Viewport::builder().scroll_to_focus(false).build();
|
||||
|
||||
widget.set_child(Some(reader.widget()));
|
||||
let widget = Widget::new_arc(&reader.gobject());
|
||||
|
||||
// Result
|
||||
Self { reader, widget }
|
||||
@ -35,7 +35,7 @@ impl Gemini {
|
||||
&self.reader.title()
|
||||
}
|
||||
|
||||
pub fn widget(&self) -> &Viewport {
|
||||
&self.widget
|
||||
pub fn gobject(&self) -> &ClampScrollable {
|
||||
&self.widget.gobject()
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,16 @@
|
||||
mod parser;
|
||||
mod widget;
|
||||
|
||||
use parser::header::Header;
|
||||
use parser::link::Link;
|
||||
use parser::plain::Plain;
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
glib::{GString, Propagation, Uri, UriFlags},
|
||||
prelude::{ActionExt, StyleContextExt, ToVariant, WidgetExt},
|
||||
Align, CssProvider, Label, STYLE_PROVIDER_PRIORITY_APPLICATION,
|
||||
glib::{GString, Uri},
|
||||
prelude::TextBufferExt,
|
||||
TextBuffer, TextView,
|
||||
};
|
||||
|
||||
use std::sync::Arc;
|
||||
@ -16,12 +18,12 @@ use std::sync::Arc;
|
||||
pub struct Reader {
|
||||
title: Option<GString>,
|
||||
// css: CssProvider,
|
||||
widget: Label,
|
||||
widget: Arc<Widget>,
|
||||
}
|
||||
|
||||
impl Reader {
|
||||
// Construct
|
||||
pub fn new(gemtext: &str, base: &Uri, action_page_open: Arc<SimpleAction>) -> Self {
|
||||
pub fn new_arc(gemtext: &str, base: &Uri, action_page_open: Arc<SimpleAction>) -> Arc<Self> {
|
||||
// Init title
|
||||
let mut title = None;
|
||||
|
||||
@ -54,37 +56,15 @@ impl Reader {
|
||||
markup.push_str(Plain::from(line).markup())
|
||||
}
|
||||
|
||||
// Init CSS
|
||||
let css = CssProvider::new();
|
||||
|
||||
/* @TODO Theme parser error: <broken file>
|
||||
css.load_from_path(
|
||||
"src/browser/main/tab/page/content/text/gemini/reader/default.css"
|
||||
); */
|
||||
|
||||
css.load_from_data("label{caret-color: transparent;}");
|
||||
// Init buffer @TODO
|
||||
let buffer = TextBuffer::new(None);
|
||||
buffer.set_text(&markup);
|
||||
|
||||
// Init widget
|
||||
let widget = Label::builder()
|
||||
.halign(Align::Fill)
|
||||
.valign(Align::Fill)
|
||||
.hexpand(true)
|
||||
.vexpand(true)
|
||||
.xalign(0.0)
|
||||
.yalign(0.0)
|
||||
.margin_start(8)
|
||||
.margin_end(8)
|
||||
.wrap(true)
|
||||
.selectable(true)
|
||||
.use_markup(true)
|
||||
.label(markup)
|
||||
.build();
|
||||
|
||||
widget
|
||||
.style_context()
|
||||
.add_provider(&css, STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
let widget = Widget::new_arc(&buffer);
|
||||
|
||||
// Connect actions
|
||||
/* @TODO
|
||||
widget.connect_activate_link(move |_, href| {
|
||||
// Detect requested protocol
|
||||
if let Ok(uri) = Uri::parse(&href, UriFlags::NONE) {
|
||||
@ -103,14 +83,10 @@ impl Reader {
|
||||
|
||||
// Delegate unparsable
|
||||
Propagation::Proceed
|
||||
});
|
||||
}); */
|
||||
|
||||
// Result
|
||||
Self {
|
||||
title,
|
||||
// css,
|
||||
widget,
|
||||
}
|
||||
Arc::new(Self { title, widget })
|
||||
}
|
||||
|
||||
// Getters
|
||||
@ -118,7 +94,7 @@ impl Reader {
|
||||
&self.title
|
||||
}
|
||||
|
||||
pub fn widget(&self) -> &Label {
|
||||
&self.widget
|
||||
pub fn gobject(&self) -> &TextView {
|
||||
&self.widget.gobject()
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
use gtk::{TextBuffer, TextView, WrapMode};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Widget {
|
||||
gobject: TextView,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new_arc(buffer: &TextBuffer) -> Arc<Self> {
|
||||
Arc::new(Self {
|
||||
gobject: TextView::builder()
|
||||
.editable(false)
|
||||
.cursor_visible(false)
|
||||
.wrap_mode(WrapMode::Word)
|
||||
.vexpand(true)
|
||||
.buffer(buffer)
|
||||
.build(),
|
||||
})
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &TextView {
|
||||
&self.gobject
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
use adw::ClampScrollable;
|
||||
use gtk::TextView;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Widget {
|
||||
gobject: ClampScrollable,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new_arc(child: &TextView) -> Arc<Self> {
|
||||
Arc::new(Self {
|
||||
gobject: ClampScrollable::builder().child(child).build(),
|
||||
})
|
||||
}
|
||||
|
||||
// Getters
|
||||
pub fn gobject(&self) -> &ClampScrollable {
|
||||
&self.gobject
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user