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

23
src/app/browser/header.rs

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

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

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

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

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

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

@ -1,50 +1,23 @@
use gtk::Label; use gtk::Label;
pub fn new() -> Label pub fn new() -> Label {
{
let title = Label::builder() let title = Label::builder()
.css_classes(["title"])
.css_classes( .single_line_mode(true)
[ .ellipsize(gtk::pango::EllipsizeMode::End)
"title"
]
)
.single_line_mode(
true
)
.ellipsize(
gtk::pango::EllipsizeMode::End
)
.build(); .build();
update( update(&title, "Welcome");
&title,
"Welcome"
);
return title; return title;
} }
pub fn update( pub fn update(title: &Label, text: &str) {
title: &Label,
text: &str
) {
let default_text = "Yoda"; // @TODO let default_text = "Yoda"; // @TODO
if text.is_empty() if text.is_empty() {
{ title.set_text(default_text);
title.set_text( } else {
default_text 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 @@
#[path = "tray/menu.rs"] mod menu; #[path = "tray/menu.rs"]
#[path = "tray/tab.rs"] mod tab; mod menu;
#[path = "tray/tab.rs"]
mod tab;
use gtk::Box;
use gtk::prelude::BoxExt; use gtk::prelude::BoxExt;
use gtk::Box;
pub fn new() -> Box pub fn new() -> Box {
{
let tray = Box::builder() let tray = Box::builder()
.orientation(gtk::Orientation::Horizontal)
// Tuneup
.orientation(
gtk::Orientation::Horizontal
)
.spacing(8) .spacing(8)
// Make
.build(); .build();
// Compose childs // Compose childs
tray.append( tray.append(&menu::new());
&menu::new() tray.append(&tab::new());
);
tray.append(
&tab::new()
);
tray tray
} }

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

@ -1,45 +1,17 @@
use gtk::{ use gtk::{gio, MenuButton};
gio,
MenuButton
};
pub fn new() -> MenuButton pub fn new() -> MenuButton {
{ let menu = MenuButton::builder().tooltip_text("Menu").build();
let menu = MenuButton::builder()
.tooltip_text(
"Menu"
)
.build();
let model = gio::Menu::new(); 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_tab.append( model.append(Some("Debug"), Some("win.debug"));
Some("Append"), model.append(Some("Quit"), Some("win.quit"));
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( menu.set_menu_model(Some(&model));
Some(&model)
);
menu menu
} }

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

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

22
src/app/browser/main.rs

@ -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::prelude::BoxExt;
use gtk::Box;
pub fn new() -> Box pub fn new() -> Box {
{ let main = Box::builder()
let main = Box::builder().orientation( .orientation(gtk::Orientation::Vertical)
gtk::Orientation::Vertical .build();
).build();
main.append( main.append(&tab::new());
&tab::new()
);
return main; main
} }

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

@ -1,54 +1,29 @@
#[path = "tab/label.rs"] mod label; #[path = "tab/label.rs"]
#[path = "tab/page.rs"] mod page; mod label;
#[path = "tab/page.rs"]
mod page;
use gtk::Notebook; use gtk::Notebook;
pub fn new() -> Notebook pub fn new() -> Notebook {
{ let tab = Notebook::builder().scrollable(true).build();
let tab = Notebook::builder()
.scrollable(
true
)
.build();
// Add test tab @TODO restore from session // Add test tab @TODO restore from session
append( append(&tab, true);
&tab,
true
);
return tab; tab
} }
pub fn append( pub fn append(tab: &Notebook, current: bool) -> u32 {
tab: &Notebook,
current: bool
) -> u32
{
let page = page::new(); let page = page::new();
let page_number = tab.append_page( let page_number = tab.append_page(&page, Some(&label::new()));
&page,
Some( tab.set_tab_reorderable(&page, true);
&label::new()
) if current {
); tab.set_current_page(Some(page_number));
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 @@
#[path = "label/pin.rs"] mod pin; #[path = "label/pin.rs"]
#[path = "label/title.rs"] mod title; mod pin;
#[path = "label/title.rs"]
mod title;
use gtk::Box;
use gtk::prelude::BoxExt; use gtk::prelude::BoxExt;
use gtk::Box;
pub fn new() -> Box pub fn new() -> Box {
{
let label = Box::builder() let label = Box::builder()
.orientation(gtk::Orientation::Horizontal)
// Tuneup
.orientation(
gtk::Orientation::Horizontal
)
.build(); .build();
// Components label.append(&pin::new(false));
label.append( label.append(&title::new());
&pin::new(
false
)
);
label.append(
&title::new()
);
return label; label
} }

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

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

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

@ -1,24 +1,10 @@
use gtk::Label; use gtk::Label;
pub fn new() -> Label pub fn new() -> Label {
{ Label::builder()
return Label::builder() .label("New page")
.ellipsize(gtk::pango::EllipsizeMode::End)
.label( .width_chars(16)
"New page" .single_line_mode(true)
) .build()
}
.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 @@
#[path = "page/navigation.rs"] mod navigation; #[path = "page/content.rs"]
#[path = "page/content.rs"] mod content; mod content;
#[path = "page/navigation.rs"]
mod navigation;
use gtk::Box;
use gtk::prelude::BoxExt; use gtk::prelude::BoxExt;
use gtk::Box;
pub fn new() -> Box pub fn new() -> Box {
{ let page = Box::builder()
let page = Box::builder().orientation( .orientation(gtk::Orientation::Vertical)
gtk::Orientation::Vertical .build();
).build();
page.append(
&navigation::new()
);
page.append( page.append(&navigation::new());
&content::new() page.append(&content::new());
);
return page; page
} }

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

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

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

@ -1,50 +1,34 @@
#[path = "navigation/base.rs"] mod base; #[path = "navigation/base.rs"]
#[path = "navigation/history.rs"] mod history; mod base;
#[path = "navigation/reload.rs"] mod reload; #[path = "navigation/bookmark.rs"]
#[path = "navigation/request.rs"] mod request; mod bookmark;
#[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::prelude::BoxExt;
use gtk::Box;
pub fn new() -> Box pub fn new() -> Box {
{
let navigation = Box::builder() let navigation = Box::builder()
// Tuneup // Tuneup
.orientation( .orientation(gtk::Orientation::Horizontal)
gtk::Orientation::Horizontal
)
.spacing(8) .spacing(8)
.margin_top(8) .margin_top(8)
.margin_start(8) .margin_start(8)
.margin_end(8) .margin_end(8)
.margin_bottom(8) .margin_bottom(8)
.build(); .build();
// Compose childs // Compose childs
navigation.append( navigation.append(&base::new());
&base::new() navigation.append(&history::new());
); navigation.append(&reload::new());
navigation.append(&request::new());
navigation.append( navigation.append(&bookmark::new());
&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 @@
use gtk::Button; use gtk::Button;
pub fn new() -> Button pub fn new() -> Button {
{ Button::builder()
let button = Button::builder() .icon_name("go-home-symbolic")
.tooltip_text("Base")
.icon_name( .sensitive(false)
"go-home-symbolic" .build()
) }
.tooltip_text(
"Base"
)
.sensitive(
false
)
.build();
return button;
}

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

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

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

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

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

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

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

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

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

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

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

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

58
src/main.rs

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

Loading…
Cancel
Save