Compare commits
4 Commits
main
...
fitnesstra
Author | SHA1 | Date |
---|---|---|
Savanni D'Gerinel | 4144325ede | |
Savanni D'Gerinel | 74617d4f44 | |
Savanni D'Gerinel | d1c61a638b | |
Savanni D'Gerinel | 9afc7d73c0 |
|
@ -14,8 +14,11 @@ General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with FitnessTrax. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with FitnessTrax. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
mod modal;
|
||||||
|
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
|
pub use modal::Modal;
|
||||||
use std::{cell::RefCell, path::PathBuf, rc::Rc};
|
use std::{cell::RefCell, path::PathBuf, rc::Rc};
|
||||||
|
|
||||||
pub struct FileChooserRowPrivate {
|
pub struct FileChooserRowPrivate {
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
//! The Modal is a reusable component with a title, arbitrary content, and up to three action
|
||||||
|
//! buttons. It does not itself enforce being a modal, but is meant to become a child of an Overlay
|
||||||
|
//! component.
|
||||||
|
use glib::Object;
|
||||||
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
|
use std::{
|
||||||
|
cell::RefCell,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct ModalPrivate {
|
||||||
|
title: gtk::Label,
|
||||||
|
content: RefCell<gtk::Widget>,
|
||||||
|
primary_action: RefCell<gtk::Button>,
|
||||||
|
// secondary_action: RefCell<Option<gtk::Button>>,
|
||||||
|
// tertiary_action: RefCell<Option<gtk::Button>>,
|
||||||
|
footer: gtk::Box,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[glib::object_subclass]
|
||||||
|
impl ObjectSubclass for ModalPrivate {
|
||||||
|
const NAME: &'static str = "Modal";
|
||||||
|
type Type = Modal;
|
||||||
|
type ParentType = gtk::Box;
|
||||||
|
|
||||||
|
fn new() -> Self {
|
||||||
|
let title = gtk::Label::builder().label("Modal").build();
|
||||||
|
let content = gtk::Box::new(gtk::Orientation::Vertical, 0);
|
||||||
|
let primary_action = gtk::Button::builder().label("Primary").build();
|
||||||
|
|
||||||
|
let footer = gtk::Box::builder()
|
||||||
|
.orientation(gtk::Orientation::Horizontal)
|
||||||
|
.hexpand(true)
|
||||||
|
.build();
|
||||||
|
footer.append(&primary_action);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
title,
|
||||||
|
content: RefCell::new(content.upcast()),
|
||||||
|
primary_action: RefCell::new(primary_action),
|
||||||
|
// secondary_action: RefCell::new(None),
|
||||||
|
// tertiary_action: RefCell::new(None),
|
||||||
|
footer,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ObjectImpl for ModalPrivate {}
|
||||||
|
impl WidgetImpl for ModalPrivate {}
|
||||||
|
impl BoxImpl for ModalPrivate {}
|
||||||
|
|
||||||
|
glib::wrapper! {
|
||||||
|
pub struct Modal(ObjectSubclass<ModalPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Modal {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
let s: Self = Object::builder().build();
|
||||||
|
|
||||||
|
s.set_margin_start(100);
|
||||||
|
s.set_margin_end(100);
|
||||||
|
s.set_margin_top(100);
|
||||||
|
s.set_margin_bottom(100);
|
||||||
|
s.set_orientation(gtk::Orientation::Vertical);
|
||||||
|
|
||||||
|
s.append(&s.imp().title);
|
||||||
|
s.append(&*s.imp().content.borrow());
|
||||||
|
s.append(&s.imp().footer);
|
||||||
|
|
||||||
|
s
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_title(&self, text: &str) {
|
||||||
|
self.imp().title.set_text(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_content(&self, content: gtk::Widget) {
|
||||||
|
self.remove(&*self.imp().content.borrow());
|
||||||
|
self.insert_child_after(&content, Some(&self.imp().title));
|
||||||
|
*self.imp().content.borrow_mut() = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_primary_action(&self, action: gtk::Button) {
|
||||||
|
self.imp()
|
||||||
|
.footer
|
||||||
|
.remove(&*self.imp().primary_action.borrow());
|
||||||
|
*self.imp().primary_action.borrow_mut() = action;
|
||||||
|
self.imp()
|
||||||
|
.footer
|
||||||
|
.append(&*self.imp().primary_action.borrow());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue