mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 09:35:28 +00:00
implement source view component as trait
This commit is contained in:
parent
f2da250376
commit
b995482e45
2 changed files with 36 additions and 31 deletions
|
|
@ -5,7 +5,7 @@ mod source;
|
||||||
use super::{ItemAction, WindowAction};
|
use super::{ItemAction, WindowAction};
|
||||||
use adw::ClampScrollable;
|
use adw::ClampScrollable;
|
||||||
use gemini::Gemini;
|
use gemini::Gemini;
|
||||||
use gtk::{glib::Uri, prelude::Cast, ScrolledWindow, TextView};
|
use gtk::{glib::Uri, ScrolledWindow, TextView};
|
||||||
use plain::Plain;
|
use plain::Plain;
|
||||||
use source::Source;
|
use source::Source;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
@ -64,10 +64,10 @@ impl Text {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn source(data: &str) -> Self {
|
pub fn source(data: &str) -> Self {
|
||||||
let source = Source::new(data);
|
let source = sourceview::View::source(data);
|
||||||
Self {
|
Self {
|
||||||
scrolled_window: ScrolledWindow::builder().child(&source.text_view).build(),
|
scrolled_window: ScrolledWindow::builder().child(&source).build(),
|
||||||
text_view: source.text_view.upcast::<TextView>(),
|
text_view: source.into_text_view(),
|
||||||
meta: Meta { title: None },
|
meta: Meta { title: None },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
use sourceview::{Buffer, StyleScheme, View};
|
use gtk::TextView;
|
||||||
const MARGIN: i32 = 8;
|
use sourceview::View;
|
||||||
|
|
||||||
pub struct Source {
|
pub trait Source {
|
||||||
pub text_view: View,
|
fn source(data: &str) -> Self;
|
||||||
|
fn into_text_view(self) -> TextView;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Source {
|
impl Source for View {
|
||||||
pub fn new(data: &str) -> Self {
|
fn source(data: &str) -> Self {
|
||||||
Self {
|
use sourceview::{Buffer, StyleScheme};
|
||||||
text_view: View::builder()
|
const MARGIN: i32 = 8;
|
||||||
|
View::builder()
|
||||||
.bottom_margin(MARGIN)
|
.bottom_margin(MARGIN)
|
||||||
.buffer(
|
.buffer(
|
||||||
&Buffer::builder()
|
&Buffer::builder()
|
||||||
|
|
@ -26,7 +28,10 @@ impl Source {
|
||||||
.show_line_numbers(true)
|
.show_line_numbers(true)
|
||||||
.top_margin(MARGIN)
|
.top_margin(MARGIN)
|
||||||
.vexpand(true)
|
.vexpand(true)
|
||||||
.build(),
|
.build()
|
||||||
}
|
}
|
||||||
|
fn into_text_view(self) -> TextView {
|
||||||
|
use sourceview::prelude::Cast;
|
||||||
|
self.upcast::<TextView>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue