added inputs components and created page for fifth lab

This commit is contained in:
2024-03-17 21:34:12 +04:00
parent 5bd783b75b
commit 5687d6773a
11 changed files with 359 additions and 168 deletions

View File

@@ -1,17 +0,0 @@
pub trait Product<B, T> {
fn builder() -> B;
fn get(self) -> T;
}
pub trait Builder<T, I, P> {
fn build(&self, build_arg: P) -> T;
fn append_item(self, item: I) -> Self;
fn append_items(self, items: Vec<I>) -> Self;
}

View File

@@ -0,0 +1,92 @@
use gtk4 as gtk;
use crate::{
view::properties::*,
model::builder_traits::*
};
use gtk::{*, prelude::*};
pub type InputLabel = String;
pub struct Input {
component: Box
}
pub struct InputBuilder {
align: Align,
label: InputLabel,
margins: MarginData,
}
impl Product<InputBuilder, Box> for Input {
fn builder() -> InputBuilder {
InputBuilder {
align: Align::Start,
label: String::new(),
margins: MarginData::EqualsMargin(5),
}
}
fn get(self) -> Box {
self.component
}
}
impl InputBuilder {
pub fn set_label(mut self, label: &str) -> Self {
self.label = String::from(label);
self
}
pub fn set_align(mut self, align: Align) -> Self {
self.align = align;
self
}
pub fn set_margins(mut self, margin: MarginData) -> Self {
self.margins = margin;
self
}
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()
.halign(self.align)
.set_margin(self.margins)
.label(self.label)
.build();
let text_view_input = TextView::builder()
.monospace(monospace)
.height_request(input_height)
.set_text_view_margin(MarginData::EqualsMargin(6))
.wrap_mode(wrap_mode)
.build();
let text_view_input_frame = Frame::builder()
.child(&text_view_input)
.set_margin(MarginData::MultipleMargin((0, 5, 0, 5)))
.build();
input_component.append(&input_label);
input_component.append(&text_view_input_frame);
Input {
component: input_component
}
}
}

View File

@@ -1,5 +1,7 @@
pub mod tabs;
pub mod input;
pub mod pages;
pub mod switch;
pub mod wrapper;
pub mod builder_pattern_traits;
use crate::model::builder_traits;

View File

@@ -12,7 +12,7 @@ use gtk::{
prelude::{BoxExt, IsA},
};
use crate::view::components::builder_pattern_traits::{Builder, Product};
use crate::view::components::builder_traits::{Builder, Product};
pub type Page<'a> = (&'a str, &'a str, &'a Box);
@@ -25,6 +25,7 @@ pub struct PagesBuilder{
}
impl Product<PagesBuilder, Box> for Pages {
fn builder() -> PagesBuilder {
PagesBuilder {
pages_content: Stack::new(),
@@ -34,9 +35,11 @@ impl Product<PagesBuilder, Box> for Pages {
fn get(self) -> Box {
self.wrapper
}
}
impl Builder<Pages, Page<'_>, i32> for PagesBuilder{
fn build(&self, build_param: i32) -> Pages {
let stack_sidebar = StackSidebar::new();
let stack_switcher = StackSwitcher::new();
@@ -56,17 +59,18 @@ impl Builder<Pages, Page<'_>, i32> for PagesBuilder{
fn append_item(self, item: Page) -> Self {
self.append_page_private(item);
self
}
fn append_items(self, items: Vec<Page>) -> Self {
items.iter()
.for_each(|&item| {
self.append_page_private(item);
});
for item in items {
self.append_page_private(item);
}
self
}
}
impl PagesBuilder {

View File

@@ -1,12 +1,11 @@
use gtk4 as gtk;
use std::boxed::Box as BoxPtr;
use gtk::{Notebook, Label, Box};
use super::builder_pattern_traits::*;
use super::builder_traits::*;
pub type TabLabel = Label;
pub type TabContent = Box;
pub type TabPage = (BoxPtr<str>, TabContent);
pub type TabPage<'a> = (&'a str, TabContent);
#[derive(Clone)]
pub struct TabsBuilder {
@@ -31,7 +30,7 @@ impl Product<TabsBuilder, Notebook> for Tabs {
}
impl Builder<Tabs, TabPage, &str> for TabsBuilder{
impl Builder<Tabs, TabPage<'_>, &str> for TabsBuilder{
fn build(&self, build_param: &str) -> Tabs {
let tabs_wrapper = Notebook::builder()
@@ -50,14 +49,14 @@ impl Builder<Tabs, TabPage, &str> for TabsBuilder{
}
fn append_item(mut self, item: TabPage) -> Self {
self.append_tab_private(&item.0, item.1);
self.append_tab_private(item);
self
}
fn append_items(mut self, items: Vec<TabPage>) -> Self {
for item in items{
self.append_tab_private(&item.0, item.1);
self.append_tab_private(item);
}
self
@@ -68,9 +67,9 @@ impl Builder<Tabs, TabPage, &str> for TabsBuilder{
impl TabsBuilder {
fn append_tab_private(&mut self, label: &str, page: TabContent) {
let tab_label = Label::new(Some(label));
self.tabs.push((tab_label, page));
fn append_tab_private(&mut self, item: TabPage) {
let tab_label = Label::new(Some(item.0));
self.tabs.push((tab_label, item.1));
}
}