implement separated mod for file chooser form components

This commit is contained in:
yggverse 2025-02-07 14:11:49 +02:00
parent afedeb81f0
commit a8f3e4fe2e
2 changed files with 29 additions and 8 deletions

View File

@ -1,4 +1,5 @@
mod control;
mod form;
use super::Header;
use gtk::Box;
@ -10,6 +11,8 @@ pub trait File {
impl File for Box {
fn file() -> Self {
use control::Control;
use form::Form;
use gtk::Button;
use std::{cell::Cell, rc::Rc};
// Init components
@ -18,14 +21,7 @@ impl File for Box {
token: None,
}));
let control = Box::control(&header);
let form = {
const MARGIN: i32 = 8;
gtk::Button::builder()
.label("Choose a file..")
.margin_bottom(MARGIN)
.margin_top(MARGIN)
.build()
};
let form = Button::form();
// Init main widget
{

View File

@ -0,0 +1,25 @@
use gtk::Button;
pub trait Form {
fn form() -> Self;
}
impl Form for Button {
fn form() -> Self {
use gtk::prelude::{ButtonExt, WidgetExt};
const MARGIN: i32 = 8;
let button = Button::builder()
.label("Choose a file..")
.margin_bottom(MARGIN)
.margin_top(MARGIN)
.build();
button.connect_clicked(|this| {
this.set_sensitive(false); // lock
});
button
}
}