Browse Source

apply rustfmt

master
yggverse 2 months ago
parent
commit
f8d938a8af
  1. 94
      src/app/browser.rs
  2. 23
      src/app/browser/header.rs
  3. 35
      src/app/browser/header/subject.rs
  4. 46
      src/app/browser/header/subject/description.rs
  5. 49
      src/app/browser/header/subject/title.rs
  6. 33
      src/app/browser/header/tray.rs
  7. 48
      src/app/browser/header/tray/menu.rs
  8. 16
      src/app/browser/header/tray/tab.rs
  9. 22
      src/app/browser/main.rs
  10. 59
      src/app/browser/main/tab.rs
  11. 34
      src/app/browser/main/tab/label.rs
  12. 22
      src/app/browser/main/tab/label/pin.rs
  13. 30
      src/app/browser/main/tab/label/title.rs
  14. 30
      src/app/browser/main/tab/page.rs
  15. 11
      src/app/browser/main/tab/page/content.rs
  16. 58
      src/app/browser/main/tab/page/navigation.rs
  17. 27
      src/app/browser/main/tab/page/navigation/base.rs
  18. 27
      src/app/browser/main/tab/page/navigation/bookmark.rs
  19. 40
      src/app/browser/main/tab/page/navigation/history.rs
  20. 27
      src/app/browser/main/tab/page/navigation/history/back.rs
  21. 27
      src/app/browser/main/tab/page/navigation/history/forward.rs
  22. 25
      src/app/browser/main/tab/page/navigation/reload.rs
  23. 27
      src/app/browser/main/tab/page/navigation/request.rs
  24. 58
      src/main.rs

94
src/app/browser.rs

@ -1,83 +1,39 @@ @@ -1,83 +1,39 @@
#[path = "browser/header.rs"] mod header;
#[path = "browser/main.rs"] mod main;
#[path = "browser/header.rs"]
mod header;
#[path = "browser/main.rs"]
mod main;
use gtk::{
Application,
ApplicationWindow,
gio::ActionEntry,
prelude::{
ActionMapExtManual,
GtkWindowExt
}
prelude::{ActionMapExtManual, GtkWindowExt},
Application, ApplicationWindow,
};
pub fn new(
app: &Application,
width: i32,
height: i32
) -> ApplicationWindow
{
pub fn new(app: &Application, width: i32, height: i32) -> ApplicationWindow {
// Init browser window
let browser = ApplicationWindow::builder()
// Tuneup
.default_width(
width
)
.default_height(
height
)
// Relate
.application(
app
)
// Init components
.titlebar(
&header::new()
)
.child(
&main::new()
)
// Make
.default_width(width)
.default_height(height)
.application(app)
.titlebar(&header::new())
.child(&main::new())
.build();
// Init actions
let action_debug = ActionEntry::builder("debug")
.activate(
|browser: &ApplicationWindow, _, _|
{
browser.emit_enable_debugging(
true
);
}
)
.build();
let action_quit = ActionEntry::builder("quit")
.activate(
|browser: &ApplicationWindow, _, _|
{
browser.close();
}
)
// Init actions
let action_debug = ActionEntry::builder("debug")
.activate(|browser: &ApplicationWindow, _, _| {
browser.emit_enable_debugging(true);
})
.build();
.build();
let action_quit = ActionEntry::builder("quit")
.activate(|browser: &ApplicationWindow, _, _| {
browser.close();
})
.build();
browser.add_action_entries(
[
action_debug,
action_quit
]
);
browser.add_action_entries([action_debug, action_quit]);
// Done
browser
}
}

23
src/app/browser/header.rs

@ -1,21 +1,14 @@ @@ -1,21 +1,14 @@
#[path = "header/subject.rs"] mod subject;
#[path = "header/tray.rs"] mod tray;
#[path = "header/subject.rs"]
mod subject;
#[path = "header/tray.rs"]
mod tray;
use gtk::HeaderBar;
pub fn new() -> HeaderBar
{
pub fn new() -> HeaderBar {
let header = HeaderBar::builder().build();
header.pack_start(
&tray::new()
);
header.set_title_widget(
Some(
&subject::new()
)
);
header.pack_start(&tray::new());
header.set_title_widget(Some(&subject::new()));
header
}
}

35
src/app/browser/header/subject.rs

@ -1,33 +1,22 @@ @@ -1,33 +1,22 @@
#[path = "subject/title.rs"] mod title;
#[path = "subject/description.rs"] mod description;
#[path = "subject/description.rs"]
mod description;
#[path = "subject/title.rs"]
mod title;
use gtk::Box;
use gtk::prelude::BoxExt;
use gtk::Box;
pub fn new() -> Box
{
pub fn new() -> Box {
let subject = Box::builder()
// Tuneup
.orientation(
gtk::Orientation::Vertical
)
.valign(
gtk::Align::Center
)
.orientation(gtk::Orientation::Vertical)
.valign(gtk::Align::Center)
.build();
// Compose childs
subject.append(
&title::new()
);
subject.append(
&description::new()
);
// Compose childs
subject.append(&title::new());
subject.append(&description::new());
// Done
subject
}
}

46
src/app/browser/header/subject/description.rs

@ -1,49 +1,27 @@ @@ -1,49 +1,27 @@
use gtk::Label;
use gtk::prelude::WidgetExt;
use gtk::Label;
pub fn new() -> Label
{
pub fn new() -> Label {
let description = Label::builder()
.css_classes(
[
"subtitle"
]
)
.single_line_mode(
true
)
.ellipsize(
gtk::pango::EllipsizeMode::End
)
.css_classes(["subtitle"])
.single_line_mode(true)
.ellipsize(gtk::pango::EllipsizeMode::End)
.build();
update(
&description,
"" // @TODO
"", // @TODO
);
return description;
description
}
pub fn update(
description: &Label,
text: &str
) {
description.set_text(
text
);
pub fn update(description: &Label, text: &str) {
description.set_text(text);
if text.is_empty()
{
if text.is_empty() {
description.hide();
}
else
{
} else {
description.show();
}
}
}

49
src/app/browser/header/subject/title.rs

@ -1,50 +1,23 @@ @@ -1,50 +1,23 @@
use gtk::Label;
pub fn new() -> Label
{
pub fn new() -> Label {
let title = Label::builder()
.css_classes(
[
"title"
]
)
.single_line_mode(
true
)
.ellipsize(
gtk::pango::EllipsizeMode::End
)
.css_classes(["title"])
.single_line_mode(true)
.ellipsize(gtk::pango::EllipsizeMode::End)
.build();
update(
&title,
"Welcome"
);
update(&title, "Welcome");
return title;
}
pub fn update(
title: &Label,
text: &str
) {
pub fn update(title: &Label, text: &str) {
let default_text = "Yoda"; // @TODO
if text.is_empty()
{
title.set_text(
default_text
);
if text.is_empty() {
title.set_text(default_text);
} else {
title.set_text(&format!("{} - {}", text, default_text));
}
else
{
title.set_text(
&format!("{} - {}", text, default_text)
);
}
}
}

33
src/app/browser/header/tray.rs

@ -1,31 +1,20 @@ @@ -1,31 +1,20 @@
#[path = "tray/menu.rs"] mod menu;
#[path = "tray/tab.rs"] mod tab;
#[path = "tray/menu.rs"]
mod menu;
#[path = "tray/tab.rs"]
mod tab;
use gtk::Box;
use gtk::prelude::BoxExt;
use gtk::Box;
pub fn new() -> Box
{
pub fn new() -> Box {
let tray = Box::builder()
// Tuneup
.orientation(
gtk::Orientation::Horizontal
)
.orientation(gtk::Orientation::Horizontal)
.spacing(8)
// Make
.build();
// Compose childs
tray.append(
&menu::new()
);
tray.append(
&tab::new()
);
// Compose childs
tray.append(&menu::new());
tray.append(&tab::new());
tray
}
}

48
src/app/browser/header/tray/menu.rs

@ -1,45 +1,17 @@ @@ -1,45 +1,17 @@
use gtk::{
gio,
MenuButton
};
use gtk::{gio, MenuButton};
pub fn new() -> MenuButton
{
let menu = MenuButton::builder()
.tooltip_text(
"Menu"
)
.build();
pub fn new() -> MenuButton {
let menu = MenuButton::builder().tooltip_text("Menu").build();
let model = gio::Menu::new();
let model_tab = gio::Menu::new();
let model_tab = gio::Menu::new();
model_tab.append(
Some("Append"),
Some("win.tab_append")
);
model.append_submenu(
Some("Tab"),
&model_tab
);
model.append(
Some("Debug"),
Some("win.debug")
);
model.append(
Some("Quit"),
Some("win.quit")
);
model_tab.append(Some("Append"), Some("win.tab_append"));
model.append_submenu(Some("Tab"), &model_tab);
model.append(Some("Debug"), Some("win.debug"));
model.append(Some("Quit"), Some("win.quit"));
menu.set_menu_model(
Some(&model)
);
menu.set_menu_model(Some(&model));
menu
}
}

16
src/app/browser/header/tray/tab.rs

@ -1,18 +1,10 @@ @@ -1,18 +1,10 @@
use gtk::Button;
pub fn new() -> Button
{
pub fn new() -> Button {
let tab = Button::builder()
.icon_name(
"tab-new-symbolic"
)
.tooltip_text(
"New tab"
)
.icon_name("tab-new-symbolic")
.tooltip_text("New tab")
.build();
return tab;
}
}

22
src/app/browser/main.rs

@ -1,17 +1,15 @@ @@ -1,17 +1,15 @@
#[path = "main/tab.rs"] mod tab;
#[path = "main/tab.rs"]
mod tab;
use gtk::Box;
use gtk::prelude::BoxExt;
use gtk::Box;
pub fn new() -> Box
{
let main = Box::builder().orientation(
gtk::Orientation::Vertical
).build();
pub fn new() -> Box {
let main = Box::builder()
.orientation(gtk::Orientation::Vertical)
.build();
main.append(
&tab::new()
);
main.append(&tab::new());
return main;
}
main
}

59
src/app/browser/main/tab.rs

@ -1,54 +1,29 @@ @@ -1,54 +1,29 @@
#[path = "tab/label.rs"] mod label;
#[path = "tab/page.rs"] mod page;
#[path = "tab/label.rs"]
mod label;
#[path = "tab/page.rs"]
mod page;
use gtk::Notebook;
pub fn new() -> Notebook
{
let tab = Notebook::builder()
.scrollable(
true
)
.build();
pub fn new() -> Notebook {
let tab = Notebook::builder().scrollable(true).build();
// Add test tab @TODO restore from session
append(
&tab,
true
);
append(&tab, true);
return tab;
tab
}
pub fn append(
tab: &Notebook,
current: bool
) -> u32
{
pub fn append(tab: &Notebook, current: bool) -> u32 {
let page = page::new();
let page_number = tab.append_page(
&page,
Some(
&label::new()
)
);
tab.set_tab_reorderable(
&page,
true
);
if current
{
tab.set_current_page(
Some(
page_number
)
);
let page_number = tab.append_page(&page, Some(&label::new()));
tab.set_tab_reorderable(&page, true);
if current {
tab.set_current_page(Some(page_number));
}
return page_number;
}
page_number
}

34
src/app/browser/main/tab/label.rs

@ -1,30 +1,18 @@ @@ -1,30 +1,18 @@
#[path = "label/pin.rs"] mod pin;
#[path = "label/title.rs"] mod title;
#[path = "label/pin.rs"]
mod pin;
#[path = "label/title.rs"]
mod title;
use gtk::Box;
use gtk::prelude::BoxExt;
use gtk::Box;
pub fn new() -> Box
{
pub fn new() -> Box {
let label = Box::builder()
// Tuneup
.orientation(
gtk::Orientation::Horizontal
)
.orientation(gtk::Orientation::Horizontal)
.build();
// Components
label.append(
&pin::new(
false
)
);
label.append(
&title::new()
);
label.append(&pin::new(false));
label.append(&title::new());
return label;
}
label
}

22
src/app/browser/main/tab/label/pin.rs

@ -1,18 +1,8 @@ @@ -1,18 +1,8 @@
use gtk::Image;
pub fn new(
visible : bool
) -> Image
{
return Image::builder()
.icon_name(
"view-pin-symbolic"
)
.visible(
visible
)
.build();
}
pub fn new(visible: bool) -> Image {
Image::builder()
.icon_name("view-pin-symbolic")
.visible(visible)
.build()
}

30
src/app/browser/main/tab/label/title.rs

@ -1,24 +1,10 @@ @@ -1,24 +1,10 @@
use gtk::Label;
pub fn new() -> Label
{
return Label::builder()
.label(
"New page"
)
.ellipsize(
gtk::pango::EllipsizeMode::End
)
.width_chars(
16
)
.single_line_mode(
true
)
.build();
}
pub fn new() -> Label {
Label::builder()
.label("New page")
.ellipsize(gtk::pango::EllipsizeMode::End)
.width_chars(16)
.single_line_mode(true)
.build()
}

30
src/app/browser/main/tab/page.rs

@ -1,22 +1,18 @@ @@ -1,22 +1,18 @@
#[path = "page/navigation.rs"] mod navigation;
#[path = "page/content.rs"] mod content;
#[path = "page/content.rs"]
mod content;
#[path = "page/navigation.rs"]
mod navigation;
use gtk::Box;
use gtk::prelude::BoxExt;
use gtk::Box;
pub fn new() -> Box
{
let page = Box::builder().orientation(
gtk::Orientation::Vertical
).build();
page.append(
&navigation::new()
);
pub fn new() -> Box {
let page = Box::builder()
.orientation(gtk::Orientation::Vertical)
.build();
page.append(
&content::new()
);
page.append(&navigation::new());
page.append(&content::new());
return page;
}
page
}

11
src/app/browser/main/tab/page/content.rs

@ -1,9 +1,8 @@ @@ -1,9 +1,8 @@
use gtk::Box;
// use gtk::prelude::BoxExt; @TODO append
pub fn new() -> Box
{
return Box::builder().orientation(
gtk::Orientation::Vertical
).build();
}
pub fn new() -> Box {
Box::builder()
.orientation(gtk::Orientation::Vertical)
.build()
}

58
src/app/browser/main/tab/page/navigation.rs

@ -1,50 +1,34 @@ @@ -1,50 +1,34 @@
#[path = "navigation/base.rs"] mod base;
#[path = "navigation/history.rs"] mod history;
#[path = "navigation/reload.rs"] mod reload;
#[path = "navigation/request.rs"] mod request;
#[path = "navigation/bookmark.rs"] mod bookmark;
#[path = "navigation/base.rs"]
mod base;
#[path = "navigation/bookmark.rs"]
mod bookmark;
#[path = "navigation/history.rs"]
mod history;
#[path = "navigation/reload.rs"]
mod reload;
#[path = "navigation/request.rs"]
mod request;
use gtk::Box;
use gtk::prelude::BoxExt;
use gtk::Box;
pub fn new() -> Box
{
pub fn new() -> Box {
let navigation = Box::builder()
// Tuneup
.orientation(
gtk::Orientation::Horizontal
)
.orientation(gtk::Orientation::Horizontal)
.spacing(8)
.margin_top(8)
.margin_start(8)
.margin_end(8)
.margin_bottom(8)
.build();
// Compose childs
navigation.append(
&base::new()
);
navigation.append(
&history::new()
);
navigation.append(
&reload::new()
);
navigation.append(
&request::new()
);
navigation.append(
&bookmark::new()
);
// Compose childs
navigation.append(&base::new());
navigation.append(&history::new());
navigation.append(&reload::new());
navigation.append(&request::new());
navigation.append(&bookmark::new());
return navigation;
}
navigation
}

27
src/app/browser/main/tab/page/navigation/base.rs

@ -1,22 +1,9 @@ @@ -1,22 +1,9 @@
use gtk::Button;
pub fn new() -> Button
{
let button = Button::builder()
.icon_name(
"go-home-symbolic"
)
.tooltip_text(
"Base"
)
.sensitive(
false
)
.build();
return button;
}
pub fn new() -> Button {
Button::builder()
.icon_name("go-home-symbolic")
.tooltip_text("Base")
.sensitive(false)
.build()
}

27
src/app/browser/main/tab/page/navigation/bookmark.rs

@ -1,22 +1,9 @@ @@ -1,22 +1,9 @@
use gtk::Button;
pub fn new() -> Button
{
let button = Button::builder()
.icon_name(
"starred-symbolic"
)
.tooltip_text(
"Toggle bookmark"
)
.sensitive(
false
)
.build();
return button;
}
pub fn new() -> Button {
Button::builder()
.icon_name("starred-symbolic")
.tooltip_text("Toggle bookmark")
.sensitive(false)
.build()
}

40
src/app/browser/main/tab/page/navigation/history.rs

@ -1,34 +1,22 @@ @@ -1,34 +1,22 @@
#[path = "history/back.rs"] mod back;
#[path = "history/forward.rs"] mod forward;
#[path = "history/back.rs"]
mod back;
#[path = "history/forward.rs"]
mod forward;
use gtk::Box;
use gtk::prelude::BoxExt;
use gtk::Box;
pub fn new() -> Box
{
pub fn new() -> Box {
let history = Box::builder()
// Tuneup
.orientation(
gtk::Orientation::Horizontal
)
.css_classes(
[
"linked" // merge childs
]
)
.orientation(gtk::Orientation::Horizontal)
.css_classes([
"linked", // merge childs
])
.build();
// Compose childs
history.append(
&back::new()
);
history.append(
&forward::new()
);
history.append(&back::new());
history.append(&forward::new());
return history;
}
history
}

27
src/app/browser/main/tab/page/navigation/history/back.rs

@ -1,22 +1,9 @@ @@ -1,22 +1,9 @@
use gtk::Button;
pub fn new() -> Button
{
let button = Button::builder()
.icon_name(
"go-previous-symbolic"
)
.tooltip_text(
"Back"
)
.sensitive(
false
)
.build();
return button;
}
pub fn new() -> Button {
Button::builder()
.icon_name("go-previous-symbolic")
.tooltip_text("Back")
.sensitive(false)
.build()
}

27
src/app/browser/main/tab/page/navigation/history/forward.rs

@ -1,22 +1,9 @@ @@ -1,22 +1,9 @@
use gtk::Button;
pub fn new() -> Button
{
let button = Button::builder()
.icon_name(
"go-next-symbolic"
)
.tooltip_text(
"Forward"
)
.sensitive(
false
)
.build();
return button;
}
pub fn new() -> Button {
Button::builder()
.icon_name("go-next-symbolic")
.tooltip_text("Forward")
.sensitive(false)
.build()
}

25
src/app/browser/main/tab/page/navigation/reload.rs

@ -1,22 +1,9 @@ @@ -1,22 +1,9 @@
use gtk::Button;
pub fn new() -> Button
{
let button = Button::builder()
.icon_name(
"view-refresh-symbolic"
)
.tooltip_text(
"Reload"
)
.sensitive(
false
)
pub fn new() -> Button {
return Button::builder()
.icon_name("view-refresh-symbolic")
.tooltip_text("Reload")
.sensitive(false)
.build();
return button;
}
}

27
src/app/browser/main/tab/page/navigation/request.rs

@ -1,22 +1,9 @@ @@ -1,22 +1,9 @@
use gtk::Entry;
pub fn new() -> Entry
{
let entry = Entry::builder()
.placeholder_text(
"URL or search term..."
)
.hexpand(
true
)
.progress_pulse_step(
0.1
)
.build();
return entry;
}
pub fn new() -> Entry {
Entry::builder()
.placeholder_text("URL or search term...")
.hexpand(true)
.progress_pulse_step(0.1)
.build()
}

58
src/main.rs

@ -1,53 +1,27 @@ @@ -1,53 +1,27 @@
#[path = "app/browser.rs"] mod browser;
#[path = "app/browser.rs"]
mod browser;
use gtk::prelude::{
ApplicationExt,
ApplicationExtManual,
GtkApplicationExt,
GtkWindowExt
};
use gtk::prelude::{ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt};
use gtk::{
Application,
glib
};
use gtk::{glib, Application};
fn main() -> glib::ExitCode
{
fn main() -> glib::ExitCode {
// Init app
let app = Application::builder().application_id(
"io.github.yggverse.Yoda.app"
).build();
let app = Application::builder()
.application_id("io.github.yggverse.Yoda.app")
.build();
// Init accels
app.set_accels_for_action(
"win.tab_append", &["<Ctrl>t"]
);
app.set_accels_for_action(
"win.tab_close", &["<Ctrl>q"]
);
app.set_accels_for_action(
"win.debug", &["<Ctrl>i"]
);
app.set_accels_for_action(
"win.quit", &["<Ctrl>Escape"]
);
app.set_accels_for_action("win.tab_append", &["<Ctrl>t"]);
app.set_accels_for_action("win.tab_close", &["<Ctrl>q"]);
app.set_accels_for_action("win.debug", &["<Ctrl>i"]);
app.set_accels_for_action("win.quit", &["<Ctrl>Escape"]);
// Create new window
app.connect_activate(
|app|
{
browser::new(
app,
640,
480
).present();
}
);
app.connect_activate(|app| {
browser::new(app, 640, 480).present();
});
// Start
app.run()
}
}

Loading…
Cancel
Save