Commit 87a4e4ac authored by Hubert Figuière's avatar Hubert Figuière
Browse files

Use libadwaita

parent fe3cdb32
......@@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2018"
[dependencies]
adw = { package = "libadwaita", version = "0.1.1" }
anyhow = "1.0.43"
async-channel = "1.6.1"
async-std = { version = "1.9.0", features = ["attributes", "tokio1"] }
......
......@@ -42,7 +42,7 @@ thanks to the authors for the work I directly lifted.
Q: Why not fork existing apps to explore ideas ?
A: Compiano is written in Rust with Gtk3. That's the technological aspect.
A: Compiano is written in Rust with Gtk4. That's the technological aspect.
Q: So what about the intruments ?
......
......@@ -7,10 +7,11 @@ extern crate gtk4;
#[macro_use]
extern crate gtk_macros;
extern crate midi_control;
use adw::prelude::*;
use gettextrs::*;
use gtk4::gio;
use gtk4::glib;
use gtk4::prelude::*;
#[macro_use]
mod utils;
......@@ -44,7 +45,7 @@ fn main() {
.expect("Could not load resources");
gio::resources_register(&res);
let app = gtk4::Application::new(Some(config::APP_ID), Default::default());
let app = adw::Application::new(Some(config::APP_ID), Default::default());
app.connect_activate(move |app| {
let (tx, rx) = async_channel::unbounded();
......
......@@ -15,9 +15,9 @@ use crate::settings;
use crate::toolkit;
use crate::widgets::piano_widget::{PianoWidget, PianoWidgetExt};
use adw::prelude::*;
use gtk4::gio;
use gtk4::glib;
use gtk4::prelude::*;
use gtk4::subclass::prelude::*;
use midi_control as midi;
......@@ -34,7 +34,7 @@ pub struct WindowController {
}
impl WindowController {
pub fn new(app: &gtk4::Application, sender: async_channel::Sender<events::Message>) -> Self {
pub fn new(app: &adw::Application, sender: async_channel::Sender<events::Message>) -> Self {
let win = Window::new(app);
let piano = win.piano().expect("Failed to create piano");
......@@ -239,11 +239,11 @@ impl WindowController {
glib::wrapper! {
pub struct Window(ObjectSubclass<imp::Window>)
@extends gtk4::Widget, gtk4::Window, gtk4::ApplicationWindow;
@extends gtk4::Widget, gtk4::Window, gtk4::ApplicationWindow, adw::ApplicationWindow;
}
impl Window {
pub fn new(app: &gtk4::Application) -> Self {
pub fn new(app: &adw::Application) -> Self {
glib::Object::new(&[("application", app)]).expect("Failed to create Window")
}
......@@ -280,11 +280,11 @@ mod imp {
use std::rc::Rc;
use adw::prelude::*;
use adw::subclass::prelude::*;
use gettextrs::gettext;
use gtk4::gio;
use gtk4::glib;
use gtk4::prelude::*;
use gtk4::subclass::prelude::*;
use once_cell::unsync::OnceCell;
......@@ -350,11 +350,11 @@ mod imp {
self.parent_constructed(obj);
let builder = gtk4::Builder::from_resource("/net/figuiere/compiano/window.ui");
// populate the headerbar
self.setup_headerbar();
// Main box
let main_box: gtk4::Box = builder.object("main_box").expect("Failed to find main box");
// populate the headerbar
self.setup_headerbar(&main_box);
let instrument_view: gtk4::Stack = builder
.object("instrument_view")
.expect("Failed to find instrument view");
......@@ -362,7 +362,7 @@ mod imp {
main_box.set_spacing(4);
main_box.append(&piano);
self.instance().set_child(Some(&main_box));
self.instance().set_content(Some(&main_box));
let instruments_combo: gtk4::ComboBoxText = builder
.object("instruments_combo")
......@@ -392,7 +392,7 @@ mod imp {
impl ObjectSubclass for Window {
const NAME: &'static str = "CompianoWindow";
type Type = super::Window;
type ParentType = gtk4::ApplicationWindow;
type ParentType = adw::ApplicationWindow;
fn new() -> Self {
Self {
......@@ -407,20 +407,9 @@ mod imp {
}
/// Setup the headerbar widget and returns it.
fn setup_headerbar(&self) {
fn setup_headerbar(&self, content: &gtk4::Box) {
let header_bar = gtk4::HeaderBar::new();
let title = gtk4::Label::new(Some("Compiano"));
title.add_css_class("title");
// XXX change this anyway: this should be the instrument
let subtitle = gtk4::Label::new(Some(&gettext("Now playing...")));
subtitle.add_css_class("subtitle");
let title_widget = gtk4::Box::new(gtk4::Orientation::Vertical, 0);
title_widget.append(&title);
title_widget.append(&subtitle);
title_widget.set_margin_top(8);
title_widget.set_margin_bottom(8);
title_widget.set_margin_start(8);
title_widget.set_margin_end(8);
let title_widget = adw::WindowTitle::new("Compiano", &gettext("Now playing..."));
header_bar.set_title_widget(Some(&title_widget));
header_bar.set_show_title_buttons(true);
let button = gtk4::MenuButton::new();
......@@ -429,11 +418,12 @@ mod imp {
get_widget!(builder, gio::Menu, main_menu);
button.set_menu_model(Some(&main_menu));
header_bar.pack_end(&button);
self.instance().set_titlebar(Some(&header_bar));
content.prepend(&header_bar);
}
}
impl WidgetImpl for Window {}
impl WindowImpl for Window {}
impl ApplicationWindowImpl for Window {}
impl AdwApplicationWindowImpl for Window {}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment