merge stable version #2
|
@ -5,6 +5,41 @@ use gtk::{prelude::*, *};
|
|||
|
||||
pub type InputLabel = String;
|
||||
|
||||
macro_rules! build_for {
|
||||
( $(($comp:ty,$name:ident)),* ) => {
|
||||
$(
|
||||
pub fn $name(self, input_height: Option<i32>) -> Input<$comp> {
|
||||
let input_component = Box::new(Orientation::Vertical, 0);
|
||||
|
||||
let input_label = Label::builder()
|
||||
.halign(self.align.horizontal)
|
||||
.valign(self.align.vertical)
|
||||
.set_margin(self.margins)
|
||||
.label(self.label)
|
||||
.build();
|
||||
|
||||
let mut input_builder = <$comp>::builder()
|
||||
.set_margin(MarginData::EqualsMargin(6));
|
||||
|
||||
if let Some(height) = input_height {
|
||||
input_builder = input_builder.height_request(height);
|
||||
}
|
||||
|
||||
let input = input_builder.build();
|
||||
|
||||
input_component.append(&input_label);
|
||||
input_component.append(&input);
|
||||
|
||||
Input {
|
||||
component: input_component,
|
||||
input: input.clone(),
|
||||
input_label: input_label.clone(),
|
||||
}
|
||||
}
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Input {
|
||||
component: Box,
|
||||
|
@ -101,4 +136,5 @@ impl InputBuilder {
|
|||
input_label: text_view_label.clone(),
|
||||
}
|
||||
}
|
||||
build_for!((TextView, build), (Entry, build_entry));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue