Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Rust layout #761

Merged
merged 3 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/canvas/canvas.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* This file is part of Akira.
*
* Copyright (c) 2024 Alessandro Castellani
*
* Akira is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* Akira is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* Akira. If not, see <https://www.gnu.org/ licenses/>.
*/
17 changes: 17 additions & 0 deletions src/layout/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* This file is part of Akira.
*
* Copyright (c) 2024 Alessandro Castellani
*
* Akira is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* Akira is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* Akira. If not, see <https://www.gnu.org/ licenses/>.
*/
pub mod sidebar;
48 changes: 48 additions & 0 deletions src/layout/sidebar/layers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* This file is part of Akira.
*
* Copyright (c) 2024 Alessandro Castellani
*
* Akira is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* Akira is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* Akira. If not, see <https://www.gnu.org/ licenses/>.
*/
use gtk::glib;
use gtk::subclass::prelude::*;

mod imp {
use super::*;

#[derive(Debug, Default)]
pub struct Layers {}

#[glib::object_subclass]
impl ObjectSubclass for Layers {
const NAME: &'static str = "Layers";
type Type = super::Layers;
type ParentType = gtk::Grid;
}

impl ObjectImpl for Layers {}
impl WidgetImpl for Layers {}
impl GridImpl for Layers {}
}

glib::wrapper! {
pub struct Layers(ObjectSubclass<imp::Layers>) @extends gtk::Widget, gtk::Grid;
}

impl Default for Layers {
fn default() -> Self {
glib::Object::builder()
.property("width-request", 200)
.build()
}
}
18 changes: 18 additions & 0 deletions src/layout/sidebar/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* This file is part of Akira.
*
* Copyright (c) 2024 Alessandro Castellani
*
* Akira is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* Akira is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* Akira. If not, see <https://www.gnu.org/ licenses/>.
*/
pub mod layers;
pub mod options;
48 changes: 48 additions & 0 deletions src/layout/sidebar/options.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* This file is part of Akira.
*
* Copyright (c) 2024 Alessandro Castellani
*
* Akira is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* Akira is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* Akira. If not, see <https://www.gnu.org/ licenses/>.
*/
use gtk::glib;
use gtk::subclass::prelude::*;

mod imp {
use super::*;

#[derive(Debug, Default)]
pub struct Options {}

#[glib::object_subclass]
impl ObjectSubclass for Options {
const NAME: &'static str = "Options";
type Type = super::Options;
type ParentType = gtk::Grid;
}

impl ObjectImpl for Options {}
impl WidgetImpl for Options {}
impl GridImpl for Options {}
}

glib::wrapper! {
pub struct Options(ObjectSubclass<imp::Options>) @extends gtk::Widget, gtk::Grid;
}

impl Default for Options {
fn default() -> Self {
glib::Object::builder()
.property("width-request", 200)
.build()
}
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
mod application;
mod config;
mod layout;
mod window;

use config::{APP_ID, GETTEXT_PACKAGE, LOCALEDIR};
Expand Down
78 changes: 57 additions & 21 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use gtk::{gio, gio::Settings, glib, prelude::*, ApplicationWindow};
use once_cell::sync::OnceCell;

use crate::config::APP_ID;
use crate::layout::sidebar::*;

mod imp {
use super::*;
Expand All @@ -44,27 +45,8 @@ mod imp {

obj.setup_settings();
obj.load_window_size();

let mode_switch = granite::ModeSwitch::builder()
.primary_icon_name("display-brightness-symbolic")
.secondary_icon_name("weather-clear-night-symbolic")
.primary_icon_tooltip_text(gettext("Light Background"))
.secondary_icon_tooltip_text(gettext("Dark Background"))
.valign(gtk::Align::Center)
.build();

let gtk_settings = gtk::Settings::default().expect("Unable to get GtkSettings object");
mode_switch
.bind_property("active", &gtk_settings, "gtk-application-prefer-dark-theme")
.bidirectional()
.build();

let header_bar = gtk::HeaderBar::builder().show_title_buttons(true).build();

header_bar.style_context().add_class("default-decoration");
header_bar.pack_end(&mode_switch);

obj.set_titlebar(Some(&header_bar));
obj.build_headerbar();
obj.build_body();
}
}

Expand Down Expand Up @@ -132,6 +114,60 @@ impl AppWindow {
self.maximize();
}
}

fn build_headerbar(&self) {
let mode_switch = granite::ModeSwitch::builder()
.primary_icon_name("display-brightness-symbolic")
.secondary_icon_name("weather-clear-night-symbolic")
.primary_icon_tooltip_text(gettext("Light Background"))
.secondary_icon_tooltip_text(gettext("Dark Background"))
.valign(gtk::Align::Center)
.build();

let gtk_settings = gtk::Settings::default().expect("Unable to get GtkSettings object");
mode_switch
.bind_property("active", &gtk_settings, "gtk-application-prefer-dark-theme")
.bidirectional()
.build();

let header_bar = gtk::HeaderBar::builder().show_title_buttons(true).build();

header_bar.add_css_class("default-decoration");
header_bar.pack_end(&mode_switch);

self.set_titlebar(Some(&header_bar));
}

fn build_body(&self) {
let main_area = gtk::Grid::builder()
.orientation(gtk::Orientation::Vertical)
.build();
let options = options::Options::default();
let layers = layers::Layers::default();

let pane1 = gtk::Paned::builder()
.orientation(gtk::Orientation::Horizontal)
.resize_start_child(false)
.resize_end_child(true)
.shrink_start_child(false)
.shrink_end_child(false)
.build();
let pane2 = gtk::Paned::builder()
.orientation(gtk::Orientation::Horizontal)
.resize_start_child(true)
.resize_end_child(false)
.shrink_start_child(true)
.shrink_end_child(false)
.build();

pane1.set_end_child(Some(&pane2));
pane1.set_start_child(Some(&options));

pane2.set_start_child(Some(&main_area));
pane2.set_end_child(Some(&layers));

self.set_child(Some(&pane1));
}
}

#[cfg(test)]
Expand Down