Browse Source

complete widget submodule refactory

master
yggverse 2 months ago
parent
commit
1e42a75f2e
  1. 4
      src/browser/main/mod.rs
  2. 28
      src/browser/main/tab/label/mod.rs
  3. 23
      src/browser/main/tab/label/pin/mod.rs
  4. 20
      src/browser/main/tab/label/pin/widget.rs
  5. 25
      src/browser/main/tab/label/title/mod.rs
  6. 22
      src/browser/main/tab/label/title/widget.rs
  7. 24
      src/browser/main/tab/label/widget.rs
  8. 37
      src/browser/main/tab/mod.rs
  9. 23
      src/browser/main/tab/page/content/mod.rs
  10. 19
      src/browser/main/tab/page/content/widget.rs
  11. 27
      src/browser/main/tab/page/mod.rs
  12. 24
      src/browser/main/tab/page/navigation/base/mod.rs
  13. 21
      src/browser/main/tab/page/navigation/base/widget.rs
  14. 24
      src/browser/main/tab/page/navigation/bookmark/mod.rs
  15. 21
      src/browser/main/tab/page/navigation/bookmark/widget.rs
  16. 24
      src/browser/main/tab/page/navigation/history/back/mod.rs
  17. 21
      src/browser/main/tab/page/navigation/history/back/widget.rs
  18. 24
      src/browser/main/tab/page/navigation/history/forward/mod.rs
  19. 21
      src/browser/main/tab/page/navigation/history/forward/widget.rs
  20. 32
      src/browser/main/tab/page/navigation/history/mod.rs
  21. 27
      src/browser/main/tab/page/navigation/history/widget.rs
  22. 39
      src/browser/main/tab/page/navigation/mod.rs
  23. 24
      src/browser/main/tab/page/navigation/reload/mod.rs
  24. 21
      src/browser/main/tab/page/navigation/reload/widget.rs
  25. 24
      src/browser/main/tab/page/navigation/request/mod.rs
  26. 21
      src/browser/main/tab/page/navigation/request/widget.rs
  27. 38
      src/browser/main/tab/page/navigation/widget.rs
  28. 24
      src/browser/main/tab/page/widget.rs
  29. 30
      src/browser/main/tab/widget.rs

4
src/browser/main/mod.rs

@ -10,11 +10,11 @@ impl Main { @@ -10,11 +10,11 @@ impl Main {
// Construct
pub fn new() -> Main {
// Init components
let tab = tab::new();
let tab = tab::Tab::new();
// Init struct
Self {
widget: widget::Main::new(tab.widget.as_ref()), // @TODO
widget: widget::Main::new(tab.widget().gtk()), // @TODO
tab,
}
}

28
src/browser/main/tab/label/mod.rs

@ -1,16 +1,24 @@ @@ -1,16 +1,24 @@
mod pin;
mod title;
mod widget;
use gtk::prelude::BoxExt;
use gtk::Box;
pub fn new() -> Box {
let label = Box::builder()
.orientation(gtk::Orientation::Horizontal)
.build();
pub struct Label {
widget: widget::Label,
}
label.append(&pin::new(false));
label.append(&title::new());
impl Label {
// Construct
pub fn new() -> Label {
Self {
widget: widget::Label::new(
pin::Pin::new().widget().gtk(),
title::Title::new().widget().gtk(),
),
}
}
label
// Getters
pub fn widget(&self) -> &widget::Label {
&self.widget
}
}

23
src/browser/main/tab/label/pin/mod.rs

@ -1,8 +1,19 @@ @@ -1,8 +1,19 @@
use gtk::Image;
mod widget;
pub fn new(visible: bool) -> Image {
Image::builder()
.icon_name("view-pin-symbolic")
.visible(visible)
.build()
pub struct Pin {
widget: widget::Pin,
}
impl Pin {
// Construct
pub fn new() -> Pin {
Self {
widget: widget::Pin::new(),
}
}
// Getters
pub fn widget(&self) -> &widget::Pin {
&self.widget
}
}

20
src/browser/main/tab/label/pin/widget.rs

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
pub struct Pin {
gtk: gtk::Image,
}
impl Pin {
// Construct
pub fn new() -> Pin {
let gtk = gtk::Image::builder()
.icon_name("view-pin-symbolic")
.visible(false) //@TODO
.build();
Self { gtk }
}
// Getters
pub fn gtk(&self) -> &gtk::Image {
&self.gtk
}
}

25
src/browser/main/tab/label/title/mod.rs

@ -1,10 +1,19 @@ @@ -1,10 +1,19 @@
use gtk::Label;
mod widget;
pub fn new() -> Label {
Label::builder()
.label("New page")
.ellipsize(gtk::pango::EllipsizeMode::End)
.width_chars(16)
.single_line_mode(true)
.build()
pub struct Title {
widget: widget::Title,
}
impl Title {
// Construct
pub fn new() -> Title {
Self {
widget: widget::Title::new(),
}
}
// Getters
pub fn widget(&self) -> &widget::Title {
&self.widget
}
}

22
src/browser/main/tab/label/title/widget.rs

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
pub struct Title {
gtk: gtk::Label,
}
impl Title {
// Construct
pub fn new() -> Title {
let gtk = gtk::Label::builder()
.label("New page")
.ellipsize(gtk::pango::EllipsizeMode::End)
.width_chars(16)
.single_line_mode(true)
.build();
Self { gtk }
}
// Getters
pub fn gtk(&self) -> &gtk::Label {
&self.gtk
}
}

24
src/browser/main/tab/label/widget.rs

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
use gtk::prelude::BoxExt;
pub struct Label {
gtk: gtk::Box,
}
impl Label {
// Construct new object
pub fn new(pin: &gtk::Image, title: &gtk::Label) -> Label {
let gtk = gtk::Box::builder()
.orientation(gtk::Orientation::Horizontal)
.build();
gtk.append(pin);
gtk.append(title);
Self { gtk }
}
// Getters
pub fn gtk(&self) -> &gtk::Box {
&self.gtk
}
}

37
src/browser/main/tab/mod.rs

@ -1,31 +1,30 @@ @@ -1,31 +1,30 @@
mod label;
mod page;
mod widget;
use std::sync::Arc;
use gtk::Notebook;
pub struct Tab {
pub widget: Arc<gtk::Notebook>,
widget: widget::Tab,
}
impl Tab {
pub fn append(&self, current: bool) -> u32 {
let page = page::new();
let page_number = self.widget.append_page(&page, Some(&label::new()));
self.widget.set_tab_reorderable(&page, true);
if current {
self.widget.set_current_page(Some(page_number));
}
// Construct
pub fn new() -> Tab {
let widget = widget::Tab::new();
page_number
Self { widget }
}
}
pub fn new() -> Tab {
let widget = Arc::new(Notebook::builder().scrollable(true).build());
// Actions
pub fn append(&self, current: bool) -> u32 {
self.widget.append(
label::Label::new().widget().gtk(),
page::Page::new().widget().gtk(),
true,
)
}
Tab { widget }
// Getters
pub fn widget(&self) -> &widget::Tab {
&self.widget
}
}

23
src/browser/main/tab/page/content/mod.rs

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

19
src/browser/main/tab/page/content/widget.rs

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
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
}
}

27
src/browser/main/tab/page/mod.rs

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

24
src/browser/main/tab/page/navigation/base/mod.rs

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

21
src/browser/main/tab/page/navigation/base/widget.rs

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
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
}
}

24
src/browser/main/tab/page/navigation/bookmark/mod.rs

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

21
src/browser/main/tab/page/navigation/bookmark/widget.rs

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
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
}
}

24
src/browser/main/tab/page/navigation/history/back/mod.rs

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

21
src/browser/main/tab/page/navigation/history/back/widget.rs

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
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
}
}

24
src/browser/main/tab/page/navigation/history/forward/mod.rs

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

21
src/browser/main/tab/page/navigation/history/forward/widget.rs

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
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
}
}

32
src/browser/main/tab/page/navigation/history/mod.rs

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

27
src/browser/main/tab/page/navigation/history/widget.rs

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
use gtk::prelude::BoxExt;
pub struct History {
gtk: gtk::Box,
}
impl History {
// Construct
pub fn new(back: &gtk::Button, forward: &gtk::Button) -> History {
let gtk = gtk::Box::builder()
.orientation(gtk::Orientation::Horizontal)
.css_classes([
"linked", // merge childs
])
.build();
gtk.append(back);
gtk.append(forward);
Self { gtk }
}
// Getters
pub fn gtk(&self) -> &gtk::Box {
&self.gtk
}
}

39
src/browser/main/tab/page/navigation/mod.rs

@ -4,26 +4,27 @@ mod history; @@ -4,26 +4,27 @@ mod history;
mod reload;
mod request;
use gtk::prelude::BoxExt;
use gtk::Box;
mod widget;
pub fn new() -> Box {
let navigation = Box::builder()
// Tuneup
.orientation(gtk::Orientation::Horizontal)
.spacing(8)
.margin_top(8)
.margin_start(8)
.margin_end(8)
.margin_bottom(8)
.build();
pub struct Navigation {
widget: widget::Navigation,
}
// Compose childs
navigation.append(&base::new());
navigation.append(&history::new());
navigation.append(&reload::new());
navigation.append(&request::new());
navigation.append(&bookmark::new());
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(),
),
}
}
navigation
// Getters
pub fn widget(&self) -> &widget::Navigation {
&self.widget
}
}

24
src/browser/main/tab/page/navigation/reload/mod.rs

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

21
src/browser/main/tab/page/navigation/reload/widget.rs

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
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
}
}

24
src/browser/main/tab/page/navigation/request/mod.rs

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

21
src/browser/main/tab/page/navigation/request/widget.rs

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
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
}
}

38
src/browser/main/tab/page/navigation/widget.rs

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
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
}
}

24
src/browser/main/tab/page/widget.rs

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

30
src/browser/main/tab/widget.rs

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
pub struct Tab {
gtk: gtk::Notebook,
}
impl Tab {
// Construct new object
pub fn new() -> Tab {
Self {
gtk: gtk::Notebook::builder().scrollable(true).build(),
}
}
// Actions
pub fn append(&self, label: &gtk::Box, page: &gtk::Box, current: bool) -> u32 {
let page_number = self.gtk.append_page(page, Some(label));
self.gtk.set_tab_reorderable(page, true);
if current {
self.gtk.set_current_page(Some(page_number));
}
page_number
}
// Getters
pub fn gtk(&self) -> &gtk::Notebook {
&self.gtk
}
}
Loading…
Cancel
Save