Skip to content

Commit

Permalink
Merge pull request #13 from onsah/use-libadwaita
Browse files Browse the repository at this point in the history
Use libadwaita
  • Loading branch information
onsah authored Oct 22, 2022
2 parents a81fd5f + 5617ac0 commit 294bab9
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 31 deletions.
132 changes: 128 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
gtk = { version = "0.4.6", package = "gtk4" }
gtk = { version = "=0.4.6", package = "gtk4" }
glib = "^0"
gio = "^0"
gdk = "^0"
Expand All @@ -24,3 +24,4 @@ scraper = "0.12.0"
thiserror = "1.0.25"
pango = "0.9.1"
openssl = { version = "0.10", features = ["vendored"] }
adw = { version = "=0.1.1", package = "libadwaita" }
2 changes: 1 addition & 1 deletion src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct LyricsApplication {
}

impl LyricsApplication {
pub fn new(app: &gtk::Application) -> Self {
pub fn new(app: &adw::Application) -> Self {
let window = ApplicationWindow::new(app);

window.present();
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use application::LyricsApplication;
use gio::prelude::*;
use gdk::{prelude::{ApplicationExt, ApplicationExtManual}, gio::ApplicationFlags};

mod app_state;
mod application;
Expand All @@ -11,9 +11,9 @@ mod utils;

#[tokio::main]
async fn main() {
let application = gtk::Application::new(
let application = adw::Application::new(
Some("com.github.onsah.sync-lyrics"),
gio::ApplicationFlags::empty(),
ApplicationFlags::empty(),
);

application.connect_activate(|app| {
Expand Down
37 changes: 17 additions & 20 deletions src/widgets/headerbar.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
use glib::{IsA, ObjectExt};
use gdk::prelude::{IsA};
use gtk::{
Align, Image, Switch, ToggleButton,
Align, Image, ToggleButton,
Widget, Label,
};
use gtk::prelude::{ButtonExt, GtkWindowExt, WidgetExt, BoxExt};
use gtk::prelude::{ButtonExt, GtkWindowExt, WidgetExt};

pub struct HeaderBar {
pub container: gtk::HeaderBar,
}

impl HeaderBar {
const LIGHT_ICON_NAME: &'static str = "display-brightness-symbolic";
const DARK_ICON_NAME: &'static str = "weather-clear-night-symbolic";

pub fn new(window: impl GtkWindowExt) -> Self {
let headerbar = gtk::HeaderBar::new();

Expand All @@ -21,7 +18,7 @@ impl HeaderBar {

headerbar.pack_start(&Self::create_pin_toggle(window));

headerbar.pack_end(&Self::create_switch());
// headerbar.pack_end(&Self::create_switch(style_manager.clone()));
headerbar.set_widget_name("headerbar");

HeaderBar {
Expand Down Expand Up @@ -49,7 +46,11 @@ impl HeaderBar {
toggle
}

fn create_switch() -> impl IsA<Widget> {
// TODO: Add color switch option in settings with 3 options:
// 1. Default
// 2. Dark
// 3. Light
/* fn create_switch(style_manager: adw::StyleManager) -> impl IsA<Widget> {
let hbox = gtk::Box::new(gtk::Orientation::Horizontal, 5);
hbox.set_margin_end(10);
Expand All @@ -65,22 +66,18 @@ impl HeaderBar {
switch.set_hexpand(false);
switch.set_valign(Align::Center);
let settings = gtk::Settings::default().unwrap();

settings
.bind_property("gtk_application_prefer_dark_theme", &switch, "active")
.flags(
glib::BindingFlags::DEFAULT
| glib::BindingFlags::SYNC_CREATE
| glib::BindingFlags::BIDIRECTIONAL
| glib::BindingFlags::INVERT_BOOLEAN,
)
.build();
switch.connect_state_set(move |_, enabled| {
style_manager.set_color_scheme(match enabled {
true => ColorScheme::PreferLight,
false => ColorScheme::PreferDark,
});
Inhibit(false)
});
hbox.append(&dark_icon);
hbox.append(&switch);
hbox.append(&light_icon);
hbox
}
} */
}
3 changes: 1 addition & 2 deletions src/widgets/lyrics_view.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use gdk::gdk_pixbuf::{Pixbuf, PixbufLoader};
use gdk::prelude::PixbufLoaderExt;
use gdk::prelude::{PixbufLoaderExt, IsA};
use gdk::pango::EllipsizeMode;
use glib::IsA;

use gtk::prelude::{BoxExt};
use gtk::traits::{WidgetExt, StyleContextExt, OrientableExt, GridExt};
Expand Down

0 comments on commit 294bab9

Please sign in to comment.