move close button to the parent level

This commit is contained in:
yggverse 2024-12-17 04:36:03 +02:00
parent 0d0eba83b9
commit 20e8d8892b
3 changed files with 16 additions and 19 deletions

View File

@ -1,3 +1,4 @@
mod close;
mod form;
mod placeholder;
mod subject;
@ -28,10 +29,11 @@ impl Search {
let subject = Rc::new(RefCell::new(None));
let form = Rc::new(Form::new(&subject));
let placeholder = Rc::new(Placeholder::new());
let close = close::new();
// Init main container
let g_box = Box::builder()
.orientation(Orientation::Vertical)
.orientation(Orientation::Horizontal)
.valign(Align::Center)
.vexpand(false)
.visible(false)
@ -39,12 +41,16 @@ impl Search {
g_box.append(&form.g_box);
g_box.append(&placeholder.label);
g_box.append(&close);
// Connect events
form.close.connect_clicked({
close.connect_clicked({
let form = form.clone();
let g_box = g_box.clone();
move |_| g_box.set_visible(false)
move |_| {
g_box.set_visible(false);
form.clean()
}
});
// Done

View File

@ -1,4 +1,3 @@
mod close;
mod input;
mod match_case;
mod navigation;
@ -11,12 +10,11 @@ use gtk::{
prelude::{
BoxExt, ButtonExt, CheckButtonExt, EditableExt, TextBufferExt, TextViewExt, WidgetExt,
},
Align, Box, Button, Orientation, TextIter, TextSearchFlags,
Align, Box, Orientation, TextIter, TextSearchFlags,
};
use std::{cell::RefCell, rc::Rc};
pub struct Form {
pub close: Button,
pub input: Rc<Input>,
pub g_box: Box,
}
@ -27,7 +25,6 @@ impl Form {
/// Create new `Self`
pub fn new(subject: &Rc<RefCell<Option<Subject>>>) -> Self {
// Init components
let close = close::new();
let input = Rc::new(Input::new());
let match_case = match_case::new();
let navigation = Rc::new(Navigation::new());
@ -43,14 +40,8 @@ impl Form {
g_box.append(&input.entry);
g_box.append(&navigation.g_box);
g_box.append(&match_case);
g_box.append(&close);
// Connect events
close.connect_clicked({
let input = input.clone();
move |_| input.clean()
});
input.entry.connect_changed({
let input = input.clone();
let match_case = match_case.clone();
@ -113,15 +104,15 @@ impl Form {
});
// Done
Self {
close,
g_box,
input,
}
Self { g_box, input }
}
// Actions
pub fn clean(&self) {
self.input.clean();
}
pub fn show(&self) {
self.g_box.set_visible(true);
self.input.entry.grab_focus();