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 2 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/>.
*/
54 changes: 54 additions & 0 deletions src/layout/left_sidebar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* 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 LeftSidebar {}

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

impl ObjectImpl for LeftSidebar {}
impl WidgetImpl for LeftSidebar {}
impl GridImpl for LeftSidebar {}
}

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

impl Default for LeftSidebar {
fn default() -> Self {
Self::new()
}
}

impl LeftSidebar {
pub fn new() -> Self {
glib::Object::builder()
Alecaddd marked this conversation as resolved.
Show resolved Hide resolved
.property("width-request", 200)
.build()
}
}
19 changes: 19 additions & 0 deletions src/layout/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 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 left_sidebar;

pub mod sidebars {}
Alecaddd marked this conversation as resolved.
Show resolved Hide resolved
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::left_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.style_context().add_class("default-decoration");
Alecaddd marked this conversation as resolved.
Show resolved Hide resolved
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 left_sidebar = left_sidebar::LeftSidebar::new();
let right_sidebar = gtk::Grid::builder().width_request(200).build();

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(&left_sidebar));

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

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

#[cfg(test)]
Expand Down