From 2c331c4ed7333d10d59835e3c97047d4fbcf9aa6 Mon Sep 17 00:00:00 2001 From: doryan Date: Sat, 10 Aug 2024 01:08:41 +0400 Subject: [PATCH] feat(component): add input_label and input_frame fields and methods for them --- src/view/components/input.rs | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/view/components/input.rs b/src/view/components/input.rs index fa1fc67..01935fd 100644 --- a/src/view/components/input.rs +++ b/src/view/components/input.rs @@ -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 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(), } } }