reorganize children widgets

This commit is contained in:
yggverse 2025-01-22 08:28:27 +02:00
parent ba965814eb
commit 972fa6c3db
21 changed files with 271 additions and 488 deletions

View File

@ -64,7 +64,7 @@ impl Page {
&navigation.widget.g_box, &navigation.widget.g_box,
&content.g_box, &content.g_box,
&search.g_box, &search.g_box,
&input.widget.clamp, &input.clamp,
)); ));
// Done // Done

View File

@ -1,18 +1,19 @@
mod response; mod response;
mod sensitive; mod sensitive;
mod titan; mod titan;
mod widget;
use super::TabAction; use super::TabAction;
use gtk::{glib::Uri, Label}; use adw::Clamp;
use gtk::{glib::Uri, prelude::WidgetExt, Box, Label};
use response::Response; use response::Response;
use sensitive::Sensitive; use sensitive::Sensitive;
use std::rc::Rc; use std::rc::Rc;
use titan::Titan; use titan::Titan;
use widget::Widget;
const MARGIN: i32 = 6;
pub struct Input { pub struct Input {
pub widget: Rc<Widget>, pub clamp: Clamp,
} }
impl Default for Input { impl Default for Input {
@ -24,16 +25,28 @@ impl Default for Input {
impl Input { impl Input {
// Construct // Construct
pub fn new() -> Self { pub fn new() -> Self {
// Init widget let clamp = Clamp::builder()
let widget = Rc::new(Widget::new()); .margin_bottom(MARGIN)
.margin_top(MARGIN)
.maximum_size(800)
.visible(false)
.build();
// Result Self { clamp }
Self { widget }
} }
// Actions // Actions
pub fn unset(&self) { 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 // Setters
@ -44,10 +57,8 @@ impl Input {
title: Option<&str>, title: Option<&str>,
size_limit: Option<usize>, size_limit: Option<usize>,
) { ) {
self.widget.update(Some( self.update(Some(
&Response::build(action, base, title, size_limit) &Response::build(action, base, title, size_limit).g_box,
.widget
.g_box,
)); ));
} }
@ -58,15 +69,12 @@ impl Input {
title: Option<&str>, title: Option<&str>,
max_length: Option<i32>, max_length: Option<i32>,
) { ) {
self.widget.update(Some( self.update(Some(
&Sensitive::build(action, base, title, max_length) &Sensitive::build(action, base, title, max_length).g_box,
.widget
.g_box,
)); ));
} }
pub fn set_new_titan(&self, on_send: impl Fn(&[u8], &Label) + 'static) { pub fn set_new_titan(&self, on_send: impl Fn(&[u8], &Label) + 'static) {
self.widget self.update(Some(&Titan::build(on_send).g_box));
.update(Some(&Titan::build(on_send).widget.g_box));
} }
} }

View File

@ -1,23 +1,26 @@
mod control; mod control;
mod form; mod form;
mod title; mod title;
mod widget;
use control::Control; use control::Control;
use form::Form; use form::Form;
use title::Title; use title::Title;
use widget::Widget;
use super::TabAction; use super::TabAction;
use gtk::{ use gtk::{
gio::SimpleAction, gio::SimpleAction,
glib::{uuid_string_random, Uri, UriHideFlags}, glib::{uuid_string_random, Uri, UriHideFlags},
prelude::BoxExt,
Box, Orientation,
}; };
use std::rc::Rc; use std::rc::Rc;
const MARGIN: i32 = 6;
const SPACING: i32 = 8;
pub struct Response { pub struct Response {
// Components // Components
pub widget: Rc<Widget>, pub g_box: Box,
} }
impl Response { impl Response {
@ -39,12 +42,19 @@ impl Response {
let form = Rc::new(Form::build(action_update.clone())); let form = Rc::new(Form::build(action_update.clone()));
let title = Rc::new(Title::build(title)); let title = Rc::new(Title::build(title));
// Init widget // Init main widget
let widget = Rc::new(Widget::build( let g_box = Box::builder()
&title.widget.label, .margin_bottom(MARGIN)
&form.widget.text_view, .margin_end(MARGIN)
&control.widget.g_box, .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 // Init events
action_update.connect_activate({ action_update.connect_activate({
@ -53,11 +63,11 @@ impl Response {
let form = form.clone(); let form = form.clone();
move |_, _| { move |_, _| {
control.update( control.update(
form.widget.text().is_empty(), form.text().is_empty(),
size_limit.map(|limit| { size_limit.map(|limit| {
limit as isize limit as isize
- ((base.to_string_partial(UriHideFlags::QUERY).len() - ((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) as isize)
}), }),
) )
@ -71,7 +81,7 @@ impl Response {
Some(&format!( Some(&format!(
"{}?{}", "{}?{}",
base.to_string_partial(UriHideFlags::QUERY), base.to_string_partial(UriHideFlags::QUERY),
Uri::escape_string(&form.widget.text(), None, false), Uri::escape_string(&form.text(), None, false),
)), )),
true, true,
); );
@ -79,6 +89,6 @@ impl Response {
}); });
// Return activated struct // Return activated struct
Self { widget } Self { g_box }
} }
} }

View File

@ -1,18 +1,18 @@
mod counter; mod counter;
mod send; mod send;
mod widget;
use counter::Counter; use counter::Counter;
use send::Send; use send::Send;
use widget::Widget;
use gtk::gio::SimpleAction; use gtk::{gio::SimpleAction, prelude::BoxExt, Align, Box, Orientation};
use std::rc::Rc; use std::rc::Rc;
const SPACING: i32 = 8;
pub struct Control { pub struct Control {
pub counter: Rc<Counter>, pub counter: Rc<Counter>,
pub send: Rc<Send>, pub send: Rc<Send>,
pub widget: Rc<Widget>, pub g_box: Box,
} }
impl Control { impl Control {
@ -24,14 +24,21 @@ impl Control {
let counter = Rc::new(Counter::new()); let counter = Rc::new(Counter::new());
let send = Rc::new(Send::build(action_send)); let send = Rc::new(Send::build(action_send));
// Init widget // Init main widget
let widget = Rc::new(Widget::build(&counter.label, &send.button)); 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 // Return activated struct
Self { Self {
counter, counter,
send, send,
widget, g_box,
} }
} }

View File

@ -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 }
}
}

View File

@ -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; const MARGIN: i32 = 8;
use gtk::gio::SimpleAction;
use std::rc::Rc;
pub struct Form { pub struct Form {
pub widget: Rc<Widget>, pub text_view: TextView,
} }
impl Form { impl Form {
@ -14,8 +18,46 @@ impl Form {
/// Build new `Self` /// Build new `Self`
pub fn build(action_update: SimpleAction) -> Self { pub fn build(action_update: SimpleAction) -> Self {
Self { // Init [SourceView](https://gitlab.gnome.org/GNOME/gtksourceview) type buffer
widget: Rc::new(Widget::build(action_update)), 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)
} }
} }

View File

@ -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)
}
}

View File

@ -1,11 +1,7 @@
mod widget; use gtk::{prelude::WidgetExt, Align, Label};
use widget::Widget;
use std::rc::Rc;
pub struct Title { pub struct Title {
pub widget: Rc<Widget>, pub label: Label,
} }
impl Title { impl Title {
@ -13,8 +9,19 @@ impl Title {
/// Build new `Self` /// Build new `Self`
pub fn build(title: Option<&str>) -> Self { pub fn build(title: Option<&str>) -> Self {
Self { let label = Label::builder()
widget: Rc::new(Widget::build(title)), .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 }
} }
} }

View File

@ -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 }
}
}

View File

@ -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 }
}
}

View File

@ -1,19 +1,20 @@
mod form; mod form;
mod widget;
use form::Form;
use widget::Widget;
use super::TabAction; use super::TabAction;
use form::Form;
use gtk::{ use gtk::{
gio::SimpleAction, gio::SimpleAction,
glib::{uuid_string_random, Uri, UriHideFlags}, glib::{uuid_string_random, Uri, UriHideFlags},
prelude::{EditableExt, WidgetExt}, prelude::{BoxExt, EditableExt, WidgetExt},
Box, Orientation,
}; };
use std::rc::Rc; use std::rc::Rc;
const MARGIN: i32 = 6;
const SPACING: i32 = 8;
pub struct Sensitive { pub struct Sensitive {
pub widget: Rc<Widget>, pub g_box: Box,
} }
impl Sensitive { impl Sensitive {
@ -38,7 +39,16 @@ impl Sensitive {
)); ));
// Init widget // 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 // Init events
action_send.connect_activate({ action_send.connect_activate({
@ -48,18 +58,18 @@ impl Sensitive {
Some(&format!( Some(&format!(
"{}?{}", "{}?{}",
base.to_string_partial(UriHideFlags::QUERY), 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, true,
); );
} }
}); });
widget.g_box.connect_realize(move |_| { g_box.connect_realize(move |_| {
form.widget.password_entry_row.grab_focus(); form.password_entry_row.grab_focus();
}); });
// Return activated struct // Return activated struct
Self { widget } Self { g_box }
} }
} }

View File

@ -1,23 +1,43 @@
mod widget; use adw::{
prelude::{EntryRowExt, PreferencesRowExt},
use widget::Widget; PasswordEntryRow,
};
use gtk::gio::SimpleAction; use gtk::{
use std::rc::Rc; gio::SimpleAction,
prelude::{ActionExt, WidgetExt},
};
pub struct Form { pub struct Form {
pub widget: Rc<Widget>, pub password_entry_row: PasswordEntryRow,
} }
impl Form { impl Form {
// Constructors // Constructors
/// Build new `Self` /// Build new `Self`
pub fn build(action_send: SimpleAction, title: Option<&str>, max_length: Option<i32>) -> Self { pub fn build(action_send: SimpleAction, title: Option<&str>, _max_length: Option<i32>) -> Self {
// Init widget // Init main widget
let widget = Rc::new(Widget::build(action_send, title, max_length)); let password_entry_row = PasswordEntryRow::builder().show_apply_button(true).build();
// Result if let Some(value) = title {
Self { widget } 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 }
} }
} }

View File

@ -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<i32>) -> 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 }
}
}

View File

@ -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 }
}
}

View File

@ -1,19 +1,20 @@
mod control; mod control;
mod form; mod form;
mod title; mod title;
mod widget;
use control::Control; use control::Control;
use form::Form; use form::Form;
use title::Title; 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; use std::rc::Rc;
const MARGIN: i32 = 6;
const SPACING: i32 = 8;
pub struct Titan { pub struct Titan {
// Components // Components
pub widget: Rc<Widget>, pub g_box: Box,
} }
impl Titan { impl Titan {
@ -31,24 +32,30 @@ impl Titan {
let title = Title::build(None); let title = Title::build(None);
// Init widget // Init widget
let widget = Rc::new(Widget::build( let g_box = Box::builder()
&title.label, .margin_bottom(MARGIN)
&form.widget.text_view, .margin_end(MARGIN)
&control.widget.g_box, .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 // Init events
action_update.connect_activate({ action_update.connect_activate({
let control = control.clone(); let control = control.clone();
let form = form.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 |_, _| { action_send
on_send(form.widget.text().as_bytes(), &control.counter.label) .connect_activate(move |_, _| on_send(form.text().as_bytes(), &control.counter.label));
});
// Return activated struct // Return activated struct
Self { widget } Self { g_box }
} }
} }

View File

@ -1,18 +1,18 @@
mod counter; mod counter;
mod send; mod send;
mod widget;
use counter::Counter; use counter::Counter;
use send::Send;
use widget::Widget;
use gtk::gio::SimpleAction; use gtk::gio::SimpleAction;
use gtk::{prelude::BoxExt, Align, Box, Orientation};
use send::Send;
use std::rc::Rc; use std::rc::Rc;
const SPACING: i32 = 8;
pub struct Control { pub struct Control {
pub counter: Rc<Counter>, pub counter: Rc<Counter>,
pub send: Rc<Send>, pub send: Rc<Send>,
pub widget: Rc<Widget>, pub g_box: Box,
} }
impl Control { impl Control {
@ -24,14 +24,21 @@ impl Control {
let counter = Rc::new(Counter::new()); let counter = Rc::new(Counter::new());
let send = Rc::new(Send::build(action_send)); let send = Rc::new(Send::build(action_send));
// Init widget // Init main widget
let widget = Rc::new(Widget::build(&counter.label, &send.button)); 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 // Return activated struct
Self { Self {
counter, counter,
send, send,
widget, g_box,
} }
} }

View File

@ -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 }
}
}

View File

@ -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; const MARGIN: i32 = 8;
use gtk::gio::SimpleAction;
use std::rc::Rc;
pub struct Form { pub struct Form {
pub widget: Rc<Widget>, pub text_view: TextView,
} }
impl Form { impl Form {
@ -14,8 +18,46 @@ impl Form {
/// Build new `Self` /// Build new `Self`
pub fn build(action_update: SimpleAction) -> Self { pub fn build(action_update: SimpleAction) -> Self {
Self { // Init [SourceView](https://gitlab.gnome.org/GNOME/gtksourceview) type buffer
widget: Rc::new(Widget::build(action_update)), 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)
} }
} }

View File

@ -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)
}
}

View File

@ -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 }
}
}

View File

@ -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)
}
}
}