mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 09:35:28 +00:00
reorganize children widgets
This commit is contained in:
parent
ba965814eb
commit
972fa6c3db
21 changed files with 271 additions and 488 deletions
|
|
@ -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<Counter>,
|
||||
pub send: Rc<Send>,
|
||||
pub widget: Rc<Widget>,
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Widget>,
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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 }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue