mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 09:35:28 +00:00
begin Titan protocol implementation
This commit is contained in:
parent
236d941b37
commit
879fe7a6f6
37 changed files with 609 additions and 102 deletions
47
src/app/browser/window/tab/item/page/input/titan/control.rs
Normal file
47
src/app/browser/window/tab/item/page/input/titan/control.rs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
mod counter;
|
||||
mod send;
|
||||
mod widget;
|
||||
|
||||
use counter::Counter;
|
||||
use send::Send;
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::gio::SimpleAction;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Control {
|
||||
pub counter: Rc<Counter>,
|
||||
pub send: Rc<Send>,
|
||||
pub widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
impl Control {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(action_send: SimpleAction) -> Self {
|
||||
// Init components
|
||||
let counter = Rc::new(Counter::new());
|
||||
let send = Rc::new(Send::build(action_send));
|
||||
|
||||
// Init widget
|
||||
let widget = Rc::new(Widget::build(&counter.widget.label, &send.widget.button));
|
||||
|
||||
// Return activated struct
|
||||
Self {
|
||||
counter,
|
||||
send,
|
||||
widget,
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, bytes: Option<usize>) {
|
||||
// Update children components
|
||||
self.counter.update(bytes);
|
||||
self.send.update(match bytes {
|
||||
Some(left) => left > 0,
|
||||
None => false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
mod widget;
|
||||
|
||||
use widget::Widget;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Counter {
|
||||
pub widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
impl Default for Counter {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Counter {
|
||||
// Construct
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
widget: Rc::new(Widget::new()),
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, bytes: Option<usize>) {
|
||||
self.widget.update(bytes);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
use gtk::{prelude::WidgetExt, Label};
|
||||
|
||||
pub struct Widget {
|
||||
pub label: Label,
|
||||
}
|
||||
|
||||
impl Default for Widget {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
label: Label::builder().css_classes(["dim-label"]).build(), // @TODO `.dimmed` Since: Adw 1.7
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, bytes: Option<usize>) {
|
||||
match bytes {
|
||||
Some(value) => {
|
||||
self.label.set_label(&crate::tool::format_bytes(value));
|
||||
self.label.set_visible(value > 0);
|
||||
}
|
||||
None => self.label.set_visible(false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
mod widget;
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::gio::SimpleAction;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Send {
|
||||
pub widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
impl Send {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(action_send: SimpleAction) -> Self {
|
||||
// Init widget
|
||||
let widget = Rc::new(Widget::build(action_send));
|
||||
|
||||
// Result
|
||||
Self { widget }
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, is_sensitive: bool) {
|
||||
self.widget.update(is_sensitive);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
prelude::{ActionExt, ButtonExt, WidgetExt},
|
||||
Button,
|
||||
};
|
||||
|
||||
pub struct Widget {
|
||||
pub button: Button,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(action_send: SimpleAction) -> Self {
|
||||
// Init main widget
|
||||
let button = Button::builder()
|
||||
.css_classes(["accent"]) // | `suggested-action`
|
||||
.label("Send")
|
||||
.sensitive(false)
|
||||
.build();
|
||||
|
||||
// Init events
|
||||
button.connect_clicked({
|
||||
move |_| {
|
||||
action_send.activate(None);
|
||||
}
|
||||
});
|
||||
|
||||
// Return activated `Self`
|
||||
Self { button }
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, is_sensitive: bool) {
|
||||
self.button.set_sensitive(is_sensitive);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
use gtk::{prelude::BoxExt, Align, Box, Button, Label, Orientation};
|
||||
|
||||
const SPACING: i32 = 8;
|
||||
|
||||
pub struct Widget {
|
||||
pub g_box: Box,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(limit: &Label, send: &Button) -> Self {
|
||||
// Init main widget
|
||||
let g_box = Box::builder()
|
||||
.halign(Align::End)
|
||||
.orientation(Orientation::Horizontal)
|
||||
.spacing(SPACING)
|
||||
.build();
|
||||
|
||||
g_box.append(limit);
|
||||
g_box.append(send);
|
||||
|
||||
// Return new `Self`
|
||||
Self { g_box }
|
||||
}
|
||||
}
|
||||
21
src/app/browser/window/tab/item/page/input/titan/form.rs
Normal file
21
src/app/browser/window/tab/item/page/input/titan/form.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
mod widget;
|
||||
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::gio::SimpleAction;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Form {
|
||||
pub widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
impl Form {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(action_update: SimpleAction) -> Self {
|
||||
Self {
|
||||
widget: Rc::new(Widget::new(action_update)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
prelude::{ActionExt, TextBufferExt, TextViewExt, WidgetExt},
|
||||
TextView, WrapMode,
|
||||
};
|
||||
use libspelling::{Checker, TextBufferAdapter};
|
||||
use sourceview::Buffer;
|
||||
|
||||
const MARGIN: i32 = 8;
|
||||
|
||||
pub struct Widget {
|
||||
pub text_view: TextView,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new(action_update: SimpleAction) -> Self {
|
||||
// Init [SourceView](https://gitlab.gnome.org/GNOME/gtksourceview) type buffer
|
||||
let buffer = Buffer::builder().build();
|
||||
|
||||
// Init [libspelling](https://gitlab.gnome.org/GNOME/libspelling)
|
||||
let checker = Checker::default();
|
||||
let adapter = TextBufferAdapter::new(&buffer, &checker);
|
||||
adapter.set_enabled(true);
|
||||
|
||||
// Init main widget
|
||||
let text_view = TextView::builder()
|
||||
.bottom_margin(MARGIN)
|
||||
.buffer(&buffer)
|
||||
.css_classes(["frame", "view"])
|
||||
.extra_menu(&adapter.menu_model())
|
||||
.left_margin(MARGIN)
|
||||
.margin_bottom(MARGIN / 4)
|
||||
.right_margin(MARGIN)
|
||||
.top_margin(MARGIN)
|
||||
.wrap_mode(WrapMode::Word)
|
||||
.build();
|
||||
|
||||
text_view.insert_action_group("spelling", Some(&adapter));
|
||||
|
||||
// Init events
|
||||
text_view.buffer().connect_changed(move |_| {
|
||||
action_update.activate(None);
|
||||
});
|
||||
|
||||
text_view.connect_realize(move |this| {
|
||||
this.grab_focus();
|
||||
});
|
||||
|
||||
// Return activated `Self`
|
||||
Self { text_view }
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
pub fn size(&self) -> usize {
|
||||
let buffer = self.text_view.buffer();
|
||||
buffer
|
||||
.text(&buffer.start_iter(), &buffer.end_iter(), true)
|
||||
.len()
|
||||
}
|
||||
}
|
||||
20
src/app/browser/window/tab/item/page/input/titan/title.rs
Normal file
20
src/app/browser/window/tab/item/page/input/titan/title.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
mod widget;
|
||||
|
||||
use widget::Widget;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Title {
|
||||
pub widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
impl Title {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(title: Option<&str>) -> Self {
|
||||
Self {
|
||||
widget: Rc::new(Widget::build(title)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
use gtk::{prelude::WidgetExt, Align, Label};
|
||||
|
||||
pub struct Widget {
|
||||
pub label: Label,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(title: Option<&str>) -> Self {
|
||||
let label = Label::builder()
|
||||
.css_classes(["heading"])
|
||||
.halign(Align::Start)
|
||||
.visible(false)
|
||||
.build();
|
||||
|
||||
if let Some(value) = title {
|
||||
if !value.is_empty() {
|
||||
label.set_label(value);
|
||||
label.set_visible(true)
|
||||
}
|
||||
}
|
||||
|
||||
Self { label }
|
||||
}
|
||||
}
|
||||
30
src/app/browser/window/tab/item/page/input/titan/widget.rs
Normal file
30
src/app/browser/window/tab/item/page/input/titan/widget.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
use gtk::{prelude::BoxExt, Box, Label, Orientation, TextView};
|
||||
|
||||
const MARGIN: i32 = 6;
|
||||
const SPACING: i32 = 8;
|
||||
|
||||
pub struct Widget {
|
||||
pub g_box: Box,
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Constructors
|
||||
|
||||
/// Build new `Self`
|
||||
pub fn build(title: &Label, response: &TextView, control: &Box) -> Self {
|
||||
let g_box = Box::builder()
|
||||
.margin_bottom(MARGIN)
|
||||
.margin_end(MARGIN)
|
||||
.margin_start(MARGIN)
|
||||
.margin_top(MARGIN)
|
||||
.spacing(SPACING)
|
||||
.orientation(Orientation::Vertical)
|
||||
.build();
|
||||
|
||||
g_box.append(title);
|
||||
g_box.append(response);
|
||||
g_box.append(control);
|
||||
|
||||
Self { g_box }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue