From 972fa6c3db32d50ff6627cf2d86df7d587c9ae28 Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 22 Jan 2025 08:28:27 +0200 Subject: [PATCH] reorganize children widgets --- src/app/browser/window/tab/item/page.rs | 2 +- src/app/browser/window/tab/item/page/input.rs | 46 ++++++++------ .../window/tab/item/page/input/response.rs | 36 +++++++---- .../tab/item/page/input/response/control.rs | 21 ++++--- .../page/input/response/control/widget.rs | 27 -------- .../tab/item/page/input/response/form.rs | 60 +++++++++++++++--- .../item/page/input/response/form/widget.rs | 63 ------------------- .../tab/item/page/input/response/title.rs | 23 ++++--- .../item/page/input/response/title/widget.rs | 27 -------- .../tab/item/page/input/response/widget.rs | 30 --------- .../window/tab/item/page/input/sensitive.rs | 32 ++++++---- .../tab/item/page/input/sensitive/form.rs | 44 +++++++++---- .../item/page/input/sensitive/form/widget.rs | 43 ------------- .../tab/item/page/input/sensitive/widget.rs | 29 --------- .../window/tab/item/page/input/titan.rs | 35 ++++++----- .../tab/item/page/input/titan/control.rs | 23 ++++--- .../item/page/input/titan/control/widget.rs | 27 -------- .../window/tab/item/page/input/titan/form.rs | 60 +++++++++++++++--- .../tab/item/page/input/titan/form/widget.rs | 63 ------------------- .../tab/item/page/input/titan/widget.rs | 30 --------- .../window/tab/item/page/input/widget.rs | 38 ----------- 21 files changed, 271 insertions(+), 488 deletions(-) delete mode 100644 src/app/browser/window/tab/item/page/input/response/control/widget.rs delete mode 100644 src/app/browser/window/tab/item/page/input/response/form/widget.rs delete mode 100644 src/app/browser/window/tab/item/page/input/response/title/widget.rs delete mode 100644 src/app/browser/window/tab/item/page/input/response/widget.rs delete mode 100644 src/app/browser/window/tab/item/page/input/sensitive/form/widget.rs delete mode 100644 src/app/browser/window/tab/item/page/input/sensitive/widget.rs delete mode 100644 src/app/browser/window/tab/item/page/input/titan/control/widget.rs delete mode 100644 src/app/browser/window/tab/item/page/input/titan/form/widget.rs delete mode 100644 src/app/browser/window/tab/item/page/input/titan/widget.rs delete mode 100644 src/app/browser/window/tab/item/page/input/widget.rs diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index cc3d3704..3088aced 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -64,7 +64,7 @@ impl Page { &navigation.widget.g_box, &content.g_box, &search.g_box, - &input.widget.clamp, + &input.clamp, )); // Done diff --git a/src/app/browser/window/tab/item/page/input.rs b/src/app/browser/window/tab/item/page/input.rs index 40138682..7c936d4b 100644 --- a/src/app/browser/window/tab/item/page/input.rs +++ b/src/app/browser/window/tab/item/page/input.rs @@ -1,18 +1,19 @@ mod response; mod sensitive; mod titan; -mod widget; use super::TabAction; -use gtk::{glib::Uri, Label}; +use adw::Clamp; +use gtk::{glib::Uri, prelude::WidgetExt, Box, Label}; use response::Response; use sensitive::Sensitive; use std::rc::Rc; use titan::Titan; -use widget::Widget; + +const MARGIN: i32 = 6; pub struct Input { - pub widget: Rc, + pub clamp: Clamp, } impl Default for Input { @@ -24,16 +25,28 @@ impl Default for Input { impl Input { // Construct pub fn new() -> Self { - // Init widget - let widget = Rc::new(Widget::new()); + let clamp = Clamp::builder() + .margin_bottom(MARGIN) + .margin_top(MARGIN) + .maximum_size(800) + .visible(false) + .build(); - // Result - Self { widget } + Self { clamp } } // Actions pub fn unset(&self) { - self.widget.update(None); + self.update(None); + } + + pub fn update(&self, child: Option<&Box>) { + if child.is_some() { + self.clamp.set_visible(true); // widget may be hidden, make it visible to child redraw + self.clamp.set_child(child); + } else { + self.clamp.set_visible(false) + } } // Setters @@ -44,10 +57,8 @@ impl Input { title: Option<&str>, size_limit: Option, ) { - self.widget.update(Some( - &Response::build(action, base, title, size_limit) - .widget - .g_box, + self.update(Some( + &Response::build(action, base, title, size_limit).g_box, )); } @@ -58,15 +69,12 @@ impl Input { title: Option<&str>, max_length: Option, ) { - self.widget.update(Some( - &Sensitive::build(action, base, title, max_length) - .widget - .g_box, + self.update(Some( + &Sensitive::build(action, base, title, max_length).g_box, )); } pub fn set_new_titan(&self, on_send: impl Fn(&[u8], &Label) + 'static) { - self.widget - .update(Some(&Titan::build(on_send).widget.g_box)); + self.update(Some(&Titan::build(on_send).g_box)); } } diff --git a/src/app/browser/window/tab/item/page/input/response.rs b/src/app/browser/window/tab/item/page/input/response.rs index d5af1346..40f81656 100644 --- a/src/app/browser/window/tab/item/page/input/response.rs +++ b/src/app/browser/window/tab/item/page/input/response.rs @@ -1,23 +1,26 @@ mod control; mod form; mod title; -mod widget; use control::Control; use form::Form; use title::Title; -use widget::Widget; use super::TabAction; use gtk::{ gio::SimpleAction, glib::{uuid_string_random, Uri, UriHideFlags}, + prelude::BoxExt, + Box, Orientation, }; use std::rc::Rc; +const MARGIN: i32 = 6; +const SPACING: i32 = 8; + pub struct Response { // Components - pub widget: Rc, + pub g_box: Box, } impl Response { @@ -39,12 +42,19 @@ impl Response { let form = Rc::new(Form::build(action_update.clone())); let title = Rc::new(Title::build(title)); - // Init widget - let widget = Rc::new(Widget::build( - &title.widget.label, - &form.widget.text_view, - &control.widget.g_box, - )); + // Init main widget + 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.label); + g_box.append(&form.text_view); + g_box.append(&control.g_box); // Init events action_update.connect_activate({ @@ -53,11 +63,11 @@ impl Response { let form = form.clone(); move |_, _| { control.update( - form.widget.text().is_empty(), + form.text().is_empty(), size_limit.map(|limit| { limit as isize - ((base.to_string_partial(UriHideFlags::QUERY).len() - + Uri::escape_string(&form.widget.text(), None, false).len()) + + Uri::escape_string(&form.text(), None, false).len()) as isize) }), ) @@ -71,7 +81,7 @@ impl Response { Some(&format!( "{}?{}", base.to_string_partial(UriHideFlags::QUERY), - Uri::escape_string(&form.widget.text(), None, false), + Uri::escape_string(&form.text(), None, false), )), true, ); @@ -79,6 +89,6 @@ impl Response { }); // Return activated struct - Self { widget } + Self { g_box } } } diff --git a/src/app/browser/window/tab/item/page/input/response/control.rs b/src/app/browser/window/tab/item/page/input/response/control.rs index 06377ef1..a49587a7 100644 --- a/src/app/browser/window/tab/item/page/input/response/control.rs +++ b/src/app/browser/window/tab/item/page/input/response/control.rs @@ -1,18 +1,18 @@ mod counter; mod send; -mod widget; use counter::Counter; use send::Send; -use widget::Widget; -use gtk::gio::SimpleAction; +use gtk::{gio::SimpleAction, prelude::BoxExt, Align, Box, Orientation}; use std::rc::Rc; +const SPACING: i32 = 8; + pub struct Control { pub counter: Rc, pub send: Rc, - pub widget: Rc, + pub g_box: Box, } impl Control { @@ -24,14 +24,21 @@ impl Control { let counter = Rc::new(Counter::new()); let send = Rc::new(Send::build(action_send)); - // Init widget - let widget = Rc::new(Widget::build(&counter.label, &send.button)); + // Init main widget + let g_box = Box::builder() + .halign(Align::End) + .orientation(Orientation::Horizontal) + .spacing(SPACING) + .build(); + + g_box.append(&counter.label); + g_box.append(&send.button); // Return activated struct Self { counter, send, - widget, + g_box, } } diff --git a/src/app/browser/window/tab/item/page/input/response/control/widget.rs b/src/app/browser/window/tab/item/page/input/response/control/widget.rs deleted file mode 100644 index 7242866e..00000000 --- a/src/app/browser/window/tab/item/page/input/response/control/widget.rs +++ /dev/null @@ -1,27 +0,0 @@ -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 } - } -} diff --git a/src/app/browser/window/tab/item/page/input/response/form.rs b/src/app/browser/window/tab/item/page/input/response/form.rs index 1fbc0bbd..4dbe71e2 100644 --- a/src/app/browser/window/tab/item/page/input/response/form.rs +++ b/src/app/browser/window/tab/item/page/input/response/form.rs @@ -1,12 +1,16 @@ -mod widget; +use gtk::{ + gio::SimpleAction, + glib::GString, + prelude::{ActionExt, TextBufferExt, TextViewExt, WidgetExt}, + TextView, WrapMode, +}; +use libspelling::{Checker, TextBufferAdapter}; +use sourceview::Buffer; -use widget::Widget; - -use gtk::gio::SimpleAction; -use std::rc::Rc; +const MARGIN: i32 = 8; pub struct Form { - pub widget: Rc, + pub text_view: TextView, } impl Form { @@ -14,8 +18,46 @@ impl Form { /// Build new `Self` pub fn build(action_update: SimpleAction) -> Self { - Self { - widget: Rc::new(Widget::build(action_update)), - } + // 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 text(&self) -> GString { + let buffer = self.text_view.buffer(); + buffer.text(&buffer.start_iter(), &buffer.end_iter(), true) } } diff --git a/src/app/browser/window/tab/item/page/input/response/form/widget.rs b/src/app/browser/window/tab/item/page/input/response/form/widget.rs deleted file mode 100644 index be21415e..00000000 --- a/src/app/browser/window/tab/item/page/input/response/form/widget.rs +++ /dev/null @@ -1,63 +0,0 @@ -use gtk::{ - gio::SimpleAction, - glib::GString, - 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 { - // Constructors - - /// Build new `Self` - pub fn build(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 text(&self) -> GString { - let buffer = self.text_view.buffer(); - buffer.text(&buffer.start_iter(), &buffer.end_iter(), true) - } -} diff --git a/src/app/browser/window/tab/item/page/input/response/title.rs b/src/app/browser/window/tab/item/page/input/response/title.rs index 383e6875..aa8dadcc 100644 --- a/src/app/browser/window/tab/item/page/input/response/title.rs +++ b/src/app/browser/window/tab/item/page/input/response/title.rs @@ -1,11 +1,7 @@ -mod widget; - -use widget::Widget; - -use std::rc::Rc; +use gtk::{prelude::WidgetExt, Align, Label}; pub struct Title { - pub widget: Rc, + pub label: Label, } impl Title { @@ -13,8 +9,19 @@ impl Title { /// Build new `Self` pub fn build(title: Option<&str>) -> Self { - Self { - widget: Rc::new(Widget::build(title)), + 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 } } } diff --git a/src/app/browser/window/tab/item/page/input/response/title/widget.rs b/src/app/browser/window/tab/item/page/input/response/title/widget.rs deleted file mode 100644 index 107ecce9..00000000 --- a/src/app/browser/window/tab/item/page/input/response/title/widget.rs +++ /dev/null @@ -1,27 +0,0 @@ -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 } - } -} diff --git a/src/app/browser/window/tab/item/page/input/response/widget.rs b/src/app/browser/window/tab/item/page/input/response/widget.rs deleted file mode 100644 index 857b6cb4..00000000 --- a/src/app/browser/window/tab/item/page/input/response/widget.rs +++ /dev/null @@ -1,30 +0,0 @@ -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 } - } -} diff --git a/src/app/browser/window/tab/item/page/input/sensitive.rs b/src/app/browser/window/tab/item/page/input/sensitive.rs index 124541bd..ebe20ad3 100644 --- a/src/app/browser/window/tab/item/page/input/sensitive.rs +++ b/src/app/browser/window/tab/item/page/input/sensitive.rs @@ -1,19 +1,20 @@ mod form; -mod widget; - -use form::Form; -use widget::Widget; use super::TabAction; +use form::Form; use gtk::{ gio::SimpleAction, glib::{uuid_string_random, Uri, UriHideFlags}, - prelude::{EditableExt, WidgetExt}, + prelude::{BoxExt, EditableExt, WidgetExt}, + Box, Orientation, }; use std::rc::Rc; +const MARGIN: i32 = 6; +const SPACING: i32 = 8; + pub struct Sensitive { - pub widget: Rc, + pub g_box: Box, } impl Sensitive { @@ -38,7 +39,16 @@ impl Sensitive { )); // Init widget - let widget = Rc::new(Widget::build(&form.widget.password_entry_row)); + 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(&form.password_entry_row); // Init events action_send.connect_activate({ @@ -48,18 +58,18 @@ impl Sensitive { Some(&format!( "{}?{}", base.to_string_partial(UriHideFlags::QUERY), - Uri::escape_string(&form.widget.password_entry_row.text(), None, false), + Uri::escape_string(&form.password_entry_row.text(), None, false), )), true, ); } }); - widget.g_box.connect_realize(move |_| { - form.widget.password_entry_row.grab_focus(); + g_box.connect_realize(move |_| { + form.password_entry_row.grab_focus(); }); // Return activated struct - Self { widget } + Self { g_box } } } diff --git a/src/app/browser/window/tab/item/page/input/sensitive/form.rs b/src/app/browser/window/tab/item/page/input/sensitive/form.rs index 217314cc..1d6f44d4 100644 --- a/src/app/browser/window/tab/item/page/input/sensitive/form.rs +++ b/src/app/browser/window/tab/item/page/input/sensitive/form.rs @@ -1,23 +1,43 @@ -mod widget; - -use widget::Widget; - -use gtk::gio::SimpleAction; -use std::rc::Rc; +use adw::{ + prelude::{EntryRowExt, PreferencesRowExt}, + PasswordEntryRow, +}; +use gtk::{ + gio::SimpleAction, + prelude::{ActionExt, WidgetExt}, +}; pub struct Form { - pub widget: Rc, + pub password_entry_row: PasswordEntryRow, } impl Form { // Constructors /// Build new `Self` - pub fn build(action_send: SimpleAction, title: Option<&str>, max_length: Option) -> Self { - // Init widget - let widget = Rc::new(Widget::build(action_send, title, max_length)); + pub fn build(action_send: SimpleAction, title: Option<&str>, _max_length: Option) -> Self { + // Init main widget + let password_entry_row = PasswordEntryRow::builder().show_apply_button(true).build(); - // Result - Self { widget } + if let Some(value) = title { + password_entry_row.set_title(value); + } + + /* @TODO adw 1.6 / ubuntu 24.10+ + if let Some(value) = max_length { + password_entry_row.set_max_length(value); + } */ + + // Init events + password_entry_row.connect_apply(move |_| { + action_send.activate(None); + }); + + password_entry_row.connect_realize(move |this| { + this.grab_focus(); + }); + + // Return activated struct + Self { password_entry_row } } } diff --git a/src/app/browser/window/tab/item/page/input/sensitive/form/widget.rs b/src/app/browser/window/tab/item/page/input/sensitive/form/widget.rs deleted file mode 100644 index be74d0b1..00000000 --- a/src/app/browser/window/tab/item/page/input/sensitive/form/widget.rs +++ /dev/null @@ -1,43 +0,0 @@ -use adw::{ - prelude::{EntryRowExt, PreferencesRowExt}, - PasswordEntryRow, -}; -use gtk::{ - gio::SimpleAction, - prelude::{ActionExt, WidgetExt}, -}; - -pub struct Widget { - pub password_entry_row: PasswordEntryRow, -} - -impl Widget { - // Constructors - - /// Build new `Self` - pub fn build(action_send: SimpleAction, title: Option<&str>, _max_length: Option) -> Self { - // Init main widget - let password_entry_row = PasswordEntryRow::builder().show_apply_button(true).build(); - - if let Some(value) = title { - password_entry_row.set_title(value); - } - - /* @TODO adw 1.6 / ubuntu 24.10+ - if let Some(value) = max_length { - password_entry_row.set_max_length(value); - } */ - - // Init events - password_entry_row.connect_apply(move |_| { - action_send.activate(None); - }); - - password_entry_row.connect_realize(move |this| { - this.grab_focus(); - }); - - // Return activated struct - Self { password_entry_row } - } -} diff --git a/src/app/browser/window/tab/item/page/input/sensitive/widget.rs b/src/app/browser/window/tab/item/page/input/sensitive/widget.rs deleted file mode 100644 index 1d2cbcec..00000000 --- a/src/app/browser/window/tab/item/page/input/sensitive/widget.rs +++ /dev/null @@ -1,29 +0,0 @@ -use adw::PasswordEntryRow; -use gtk::{prelude::BoxExt, Box, Orientation}; - -const MARGIN: i32 = 6; -const SPACING: i32 = 8; - -pub struct Widget { - pub g_box: Box, -} - -impl Widget { - // Constructors - - /// Build new `Self` - pub fn build(response: &PasswordEntryRow) -> 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(response); - - Self { g_box } - } -} diff --git a/src/app/browser/window/tab/item/page/input/titan.rs b/src/app/browser/window/tab/item/page/input/titan.rs index a9c758df..ffc3d22e 100644 --- a/src/app/browser/window/tab/item/page/input/titan.rs +++ b/src/app/browser/window/tab/item/page/input/titan.rs @@ -1,19 +1,20 @@ mod control; mod form; mod title; -mod widget; use control::Control; use form::Form; use title::Title; -use widget::Widget; -use gtk::{gio::SimpleAction, glib::uuid_string_random, Label}; +use gtk::{gio::SimpleAction, glib::uuid_string_random, prelude::BoxExt, Box, Label, Orientation}; use std::rc::Rc; +const MARGIN: i32 = 6; +const SPACING: i32 = 8; + pub struct Titan { // Components - pub widget: Rc, + pub g_box: Box, } impl Titan { @@ -31,24 +32,30 @@ impl Titan { let title = Title::build(None); // Init widget - let widget = Rc::new(Widget::build( - &title.label, - &form.widget.text_view, - &control.widget.g_box, - )); + 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.label); + g_box.append(&form.text_view); + g_box.append(&control.g_box); // Init events action_update.connect_activate({ let control = control.clone(); let form = form.clone(); - move |_, _| control.update(Some(form.widget.text().as_bytes().len())) + move |_, _| control.update(Some(form.text().as_bytes().len())) }); - action_send.connect_activate(move |_, _| { - on_send(form.widget.text().as_bytes(), &control.counter.label) - }); + action_send + .connect_activate(move |_, _| on_send(form.text().as_bytes(), &control.counter.label)); // Return activated struct - Self { widget } + Self { g_box } } } diff --git a/src/app/browser/window/tab/item/page/input/titan/control.rs b/src/app/browser/window/tab/item/page/input/titan/control.rs index 7668e6e1..6c61b6d1 100644 --- a/src/app/browser/window/tab/item/page/input/titan/control.rs +++ b/src/app/browser/window/tab/item/page/input/titan/control.rs @@ -1,18 +1,18 @@ mod counter; mod send; -mod widget; use counter::Counter; -use send::Send; -use widget::Widget; - use gtk::gio::SimpleAction; +use gtk::{prelude::BoxExt, Align, Box, Orientation}; +use send::Send; use std::rc::Rc; +const SPACING: i32 = 8; + pub struct Control { pub counter: Rc, pub send: Rc, - pub widget: Rc, + pub g_box: Box, } impl Control { @@ -24,14 +24,21 @@ impl Control { let counter = Rc::new(Counter::new()); let send = Rc::new(Send::build(action_send)); - // Init widget - let widget = Rc::new(Widget::build(&counter.label, &send.button)); + // Init main widget + let g_box = Box::builder() + .halign(Align::End) + .orientation(Orientation::Horizontal) + .spacing(SPACING) + .build(); + + g_box.append(&counter.label); + g_box.append(&send.button); // Return activated struct Self { counter, send, - widget, + g_box, } } diff --git a/src/app/browser/window/tab/item/page/input/titan/control/widget.rs b/src/app/browser/window/tab/item/page/input/titan/control/widget.rs deleted file mode 100644 index 7242866e..00000000 --- a/src/app/browser/window/tab/item/page/input/titan/control/widget.rs +++ /dev/null @@ -1,27 +0,0 @@ -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 } - } -} diff --git a/src/app/browser/window/tab/item/page/input/titan/form.rs b/src/app/browser/window/tab/item/page/input/titan/form.rs index 1fbc0bbd..4dbe71e2 100644 --- a/src/app/browser/window/tab/item/page/input/titan/form.rs +++ b/src/app/browser/window/tab/item/page/input/titan/form.rs @@ -1,12 +1,16 @@ -mod widget; +use gtk::{ + gio::SimpleAction, + glib::GString, + prelude::{ActionExt, TextBufferExt, TextViewExt, WidgetExt}, + TextView, WrapMode, +}; +use libspelling::{Checker, TextBufferAdapter}; +use sourceview::Buffer; -use widget::Widget; - -use gtk::gio::SimpleAction; -use std::rc::Rc; +const MARGIN: i32 = 8; pub struct Form { - pub widget: Rc, + pub text_view: TextView, } impl Form { @@ -14,8 +18,46 @@ impl Form { /// Build new `Self` pub fn build(action_update: SimpleAction) -> Self { - Self { - widget: Rc::new(Widget::build(action_update)), - } + // 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 text(&self) -> GString { + let buffer = self.text_view.buffer(); + buffer.text(&buffer.start_iter(), &buffer.end_iter(), true) } } diff --git a/src/app/browser/window/tab/item/page/input/titan/form/widget.rs b/src/app/browser/window/tab/item/page/input/titan/form/widget.rs deleted file mode 100644 index be21415e..00000000 --- a/src/app/browser/window/tab/item/page/input/titan/form/widget.rs +++ /dev/null @@ -1,63 +0,0 @@ -use gtk::{ - gio::SimpleAction, - glib::GString, - 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 { - // Constructors - - /// Build new `Self` - pub fn build(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 text(&self) -> GString { - let buffer = self.text_view.buffer(); - buffer.text(&buffer.start_iter(), &buffer.end_iter(), true) - } -} diff --git a/src/app/browser/window/tab/item/page/input/titan/widget.rs b/src/app/browser/window/tab/item/page/input/titan/widget.rs deleted file mode 100644 index 857b6cb4..00000000 --- a/src/app/browser/window/tab/item/page/input/titan/widget.rs +++ /dev/null @@ -1,30 +0,0 @@ -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 } - } -} diff --git a/src/app/browser/window/tab/item/page/input/widget.rs b/src/app/browser/window/tab/item/page/input/widget.rs deleted file mode 100644 index 6c80fa3f..00000000 --- a/src/app/browser/window/tab/item/page/input/widget.rs +++ /dev/null @@ -1,38 +0,0 @@ -use adw::Clamp; -use gtk::{prelude::WidgetExt, Box}; - -const MARGIN: i32 = 6; - -pub struct Widget { - pub clamp: Clamp, -} - -impl Default for Widget { - fn default() -> Self { - Self::new() - } -} - -impl Widget { - // Construct - pub fn new() -> Self { - let clamp = Clamp::builder() - .margin_bottom(MARGIN) - .margin_top(MARGIN) - .maximum_size(800) - .visible(false) - .build(); - - Self { clamp } - } - - // Actions - pub fn update(&self, child: Option<&Box>) { - if child.is_some() { - self.clamp.set_visible(true); // widget may be hidden, make it visible to child redraw - self.clamp.set_child(child); - } else { - self.clamp.set_visible(false) - } - } -}