feat(component): add input_label and input_frame fields and methods for them

This commit is contained in:
doryan 2024-08-10 01:08:41 +04:00
parent 09801147b9
commit 2c331c4ed7

View File

@ -5,10 +5,12 @@ use gtk::{prelude::*, *};
pub type InputLabel = String;
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct Input {
component: Box,
input: TextView,
input_label: Label,
input_frame: Frame,
}
pub struct InputBuilder {
@ -35,25 +37,33 @@ impl Product<InputBuilder, Box> for Input {
}
impl Input {
pub fn get_input(self) -> TextView {
self.input
pub fn get_input(&self) -> &TextView {
&self.input
}
pub fn get_frame(&self) -> &Frame {
&self.input_frame
}
pub fn get_label(&self) -> &Label {
&self.input_label
}
}
impl InputBuilder {
pub fn set_label(mut self, label: &str) -> Self {
self.label = String::from(label);
pub fn label(mut self, label: &str) -> Self {
self.label = label.into();
self
}
pub fn set_align(mut self, align: Alignment) -> Self {
pub fn align(mut self, align: Alignment) -> Self {
self.align = align;
self
}
pub fn set_margins(mut self, margin: MarginData) -> Self {
pub fn margins(mut self, margin: MarginData) -> Self {
self.margins = margin;
self
@ -62,7 +72,7 @@ impl InputBuilder {
pub fn build(self, monospace: bool, wrap_mode: WrapMode, input_height: i32) -> Input {
let input_component = Box::new(Orientation::Vertical, 0);
let input_label = Label::builder()
let text_view_label = Label::builder()
.halign(self.align.horizontal)
.valign(self.align.vertical)
.set_margin(self.margins)
@ -81,12 +91,14 @@ impl InputBuilder {
.set_margin(MarginData::MultipleMargin((0, 5, 0, 5)))
.build();
input_component.append(&input_label);
input_component.append(&text_view_label);
input_component.append(&text_view_input_frame);
Input {
component: input_component,
input: text_view_input,
input: text_view_input.clone(),
input_frame: text_view_input_frame.clone(),
input_label: text_view_label.clone(),
}
}
}