reorganize widget modules

This commit is contained in:
yggverse 2024-09-23 18:51:48 +03:00
parent b9b226cc54
commit 4903968309
47 changed files with 352 additions and 786 deletions

View file

@ -1,19 +1,19 @@
mod widget;
use gtk::{Box, Orientation};
pub struct Content {
widget: widget::Content,
widget: Box,
}
impl Content {
// Construct
pub fn new() -> Content {
Self {
widget: widget::Content::new(),
widget: Box::builder().orientation(Orientation::Vertical).build(),
}
}
// Getters
pub fn widget(&self) -> &widget::Content {
pub fn widget(&self) -> &Box {
&self.widget
}
}

View file

@ -1,19 +0,0 @@
pub struct Content {
gtk: gtk::Box,
}
impl Content {
// Construct new object
pub fn new() -> Content {
Self {
gtk: gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
.build(),
}
}
// Getters
pub fn gtk(&self) -> &gtk::Box {
&self.gtk
}
}

View file

@ -1,23 +1,31 @@
mod content;
mod navigation;
mod widget;
use gtk::prelude::BoxExt;
use gtk::{Box, Orientation};
pub struct Page {
widget: widget::Page,
widget: Box,
}
impl Page {
pub fn new() -> Page {
Self {
widget: widget::Page::new(
navigation::Navigation::new().widget().gtk(),
content::Content::new().widget().gtk(),
),
}
// Init components
let navigation = navigation::Navigation::new();
let content = content::Content::new();
// Init widget
let widget = Box::builder().orientation(Orientation::Vertical).build();
widget.append(navigation.widget());
widget.append(content.widget());
// Result
Self { widget }
}
// Getters
pub fn widget(&self) -> &widget::Page {
pub fn widget(&self) -> &Box {
&self.widget
}
}

View file

@ -1,19 +1,23 @@
mod widget;
use gtk::Button;
pub struct Base {
widget: widget::Base,
widget: Button,
}
impl Base {
// Construct
pub fn new() -> Base {
Self {
widget: widget::Base::new(),
widget: Button::builder()
.icon_name("go-home-symbolic")
.tooltip_text("Base")
.sensitive(false)
.build(),
}
}
// Getters
pub fn widget(&self) -> &widget::Base {
pub fn widget(&self) -> &Button {
&self.widget
}
}

View file

@ -1,21 +0,0 @@
pub struct Base {
gtk: gtk::Button,
}
impl Base {
// Construct
pub fn new() -> Base {
Self {
gtk: gtk::Button::builder()
.icon_name("go-home-symbolic")
.tooltip_text("Base")
.sensitive(false)
.build(),
}
}
// Getters
pub fn gtk(&self) -> &gtk::Button {
&self.gtk
}
}

View file

@ -1,19 +1,23 @@
mod widget;
use gtk::Button;
pub struct Bookmark {
widget: widget::Bookmark,
widget: Button,
}
impl Bookmark {
// Construct
pub fn new() -> Bookmark {
Self {
widget: widget::Bookmark::new(),
widget: Button::builder()
.icon_name("starred-symbolic")
.tooltip_text("Toggle bookmark")
.sensitive(false)
.build(),
}
}
// Getters
pub fn widget(&self) -> &widget::Bookmark {
pub fn widget(&self) -> &Button {
&self.widget
}
}

View file

@ -1,21 +0,0 @@
pub struct Bookmark {
gtk: gtk::Button,
}
impl Bookmark {
// Construct
pub fn new() -> Bookmark {
Self {
gtk: gtk::Button::builder()
.icon_name("starred-symbolic")
.tooltip_text("Toggle bookmark")
.sensitive(false)
.build(),
}
}
// Getters
pub fn gtk(&self) -> &gtk::Button {
&self.gtk
}
}

View file

@ -1,19 +1,23 @@
mod widget;
use gtk::Button;
pub struct Back {
widget: widget::Back,
widget: Button,
}
impl Back {
// Construct
pub fn new() -> Back {
Self {
widget: widget::Back::new(),
widget: Button::builder()
.icon_name("go-previous-symbolic")
.tooltip_text("Back")
.sensitive(false)
.build(),
}
}
// Getters
pub fn widget(&self) -> &widget::Back {
pub fn widget(&self) -> &Button {
&self.widget
}
}

View file

@ -1,21 +0,0 @@
pub struct Back {
gtk: gtk::Button,
}
impl Back {
// Construct
pub fn new() -> Back {
Self {
gtk: gtk::Button::builder()
.icon_name("go-previous-symbolic")
.tooltip_text("Back")
.sensitive(false)
.build(),
}
}
// Getters
pub fn gtk(&self) -> &gtk::Button {
&self.gtk
}
}

View file

@ -1,19 +1,23 @@
mod widget;
use gtk::Button;
pub struct Forward {
widget: widget::Forward,
widget: Button,
}
impl Forward {
// Construct
pub fn new() -> Forward {
Self {
widget: widget::Forward::new(),
widget: Button::builder()
.icon_name("go-next-symbolic")
.tooltip_text("Forward")
.sensitive(false)
.build(),
}
}
// Getters
pub fn widget(&self) -> &widget::Forward {
pub fn widget(&self) -> &Button {
&self.widget
}
}

View file

@ -1,21 +0,0 @@
pub struct Forward {
gtk: gtk::Button,
}
impl Forward {
// Construct
pub fn new() -> Forward {
Self {
gtk: gtk::Button::builder()
.icon_name("go-next-symbolic")
.tooltip_text("Forward")
.sensitive(false)
.build(),
}
}
// Getters
pub fn gtk(&self) -> &gtk::Button {
&self.gtk
}
}

View file

@ -1,24 +1,38 @@
mod back;
mod forward;
mod widget;
use back::Back;
use forward::Forward;
use gtk::prelude::BoxExt;
use gtk::{Box, Orientation};
pub struct History {
widget: widget::History,
widget: Box,
}
impl History {
// Construct
pub fn new() -> History {
Self {
widget: widget::History::new(
back::Back::new().widget().gtk(),
forward::Forward::new().widget().gtk(),
),
}
// init components
let back = Back::new();
let forward = Forward::new();
// Init widget
let widget = Box::builder()
.orientation(Orientation::Horizontal)
.css_classes([
"linked", // merge childs
])
.build();
widget.append(back.widget());
widget.append(forward.widget());
Self { widget }
}
// Getters
pub fn widget(&self) -> &widget::History {
pub fn widget(&self) -> &Box {
&self.widget
}
}

View file

@ -4,27 +4,47 @@ mod history;
mod reload;
mod request;
mod widget;
use gtk::prelude::BoxExt;
use gtk::{Box, Orientation};
use base::Base;
use bookmark::Bookmark;
use history::History;
use reload::Reload;
use request::Request;
pub struct Navigation {
widget: widget::Navigation,
widget: Box,
}
impl Navigation {
pub fn new() -> Navigation {
Self {
widget: widget::Navigation::new(
base::Base::new().widget().gtk(),
history::History::new().widget().gtk(),
reload::Reload::new().widget().gtk(),
request::Request::new().widget().gtk(),
bookmark::Bookmark::new().widget().gtk(),
),
}
let base = Base::new();
let history = History::new();
let reload = Reload::new();
let request = Request::new();
let bookmark = Bookmark::new();
let widget = Box::builder()
.orientation(Orientation::Horizontal)
.spacing(8)
.margin_top(8)
.margin_start(8)
.margin_end(8)
.margin_bottom(8)
.build();
widget.append(base.widget());
widget.append(history.widget());
widget.append(reload.widget());
widget.append(request.widget());
widget.append(bookmark.widget());
Self { widget }
}
// Getters
pub fn widget(&self) -> &widget::Navigation {
pub fn widget(&self) -> &Box {
&self.widget
}
}

View file

@ -1,19 +1,23 @@
mod widget;
use gtk::Button;
pub struct Reload {
widget: widget::Reload,
widget: Button,
}
impl Reload {
// Construct
pub fn new() -> Reload {
Self {
widget: widget::Reload::new(),
widget: Button::builder()
.icon_name("view-refresh-symbolic")
.tooltip_text("Reload")
.sensitive(false)
.build(),
}
}
// Getters
pub fn widget(&self) -> &widget::Reload {
pub fn widget(&self) -> &Button {
&self.widget
}
}

View file

@ -1,21 +0,0 @@
pub struct Reload {
gtk: gtk::Button,
}
impl Reload {
// Construct
pub fn new() -> Reload {
Self {
gtk: gtk::Button::builder()
.icon_name("view-refresh-symbolic")
.tooltip_text("Reload")
.sensitive(false)
.build(),
}
}
// Getters
pub fn gtk(&self) -> &gtk::Button {
&self.gtk
}
}

View file

@ -1,19 +1,23 @@
mod widget;
use gtk::Entry;
pub struct Request {
widget: widget::Request,
widget: Entry,
}
impl Request {
// Construct
pub fn new() -> Request {
Self {
widget: widget::Request::new(),
widget: Entry::builder()
.placeholder_text("URL or search term...")
.hexpand(true)
.progress_pulse_step(0.1)
.build(),
}
}
// Getters
pub fn widget(&self) -> &widget::Request {
pub fn widget(&self) -> &Entry {
&self.widget
}
}

View file

@ -1,21 +0,0 @@
pub struct Request {
gtk: gtk::Entry,
}
impl Request {
// Construct
pub fn new() -> Request {
Self {
gtk: gtk::Entry::builder()
.placeholder_text("URL or search term...")
.hexpand(true)
.progress_pulse_step(0.1)
.build(),
}
}
// Getters
pub fn gtk(&self) -> &gtk::Entry {
&self.gtk
}
}

View file

@ -1,38 +0,0 @@
use gtk::prelude::BoxExt;
pub struct Navigation {
gtk: gtk::Box,
}
impl Navigation {
// Construct
pub fn new(
base: &gtk::Button,
history: &gtk::Box,
reload: &gtk::Button,
request: &gtk::Entry,
bookmark: &gtk::Button,
) -> Navigation {
let gtk = gtk::Box::builder()
.orientation(gtk::Orientation::Horizontal)
.spacing(8)
.margin_top(8)
.margin_start(8)
.margin_end(8)
.margin_bottom(8)
.build();
gtk.append(base);
gtk.append(history);
gtk.append(reload);
gtk.append(request);
gtk.append(bookmark);
Self { gtk }
}
// Getters
pub fn gtk(&self) -> &gtk::Box {
&self.gtk
}
}

View file

@ -1,24 +0,0 @@
use gtk::prelude::BoxExt;
pub struct Page {
container: gtk::Box,
}
impl Page {
// Construct
pub fn new(navigation: &gtk::Box, content: &gtk::Box) -> Page {
let container = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
.build();
container.append(navigation);
container.append(content);
Self { container }
}
// Getters
pub fn container(&self) -> &gtk::Box {
&self.container
}
}