changed inputs for second section and implemented Clone and Copy traits for Alignment data structure
This commit is contained in:
@@ -1,19 +1,16 @@
|
||||
use gtk4 as gtk;
|
||||
|
||||
use crate::{
|
||||
view::properties::*,
|
||||
model::builder_traits::*
|
||||
};
|
||||
use gtk::{*, prelude::*};
|
||||
use crate::{model::builder_traits::*, view::properties::*};
|
||||
use gtk::{prelude::*, *};
|
||||
|
||||
pub type InputLabel = String;
|
||||
|
||||
pub struct Input {
|
||||
component: Box
|
||||
component: Box,
|
||||
}
|
||||
|
||||
pub struct InputBuilder {
|
||||
align: Align,
|
||||
align: Alignment,
|
||||
label: InputLabel,
|
||||
margins: MarginData,
|
||||
}
|
||||
@@ -21,7 +18,10 @@ pub struct InputBuilder {
|
||||
impl Product<InputBuilder, Box> for Input {
|
||||
fn builder() -> InputBuilder {
|
||||
InputBuilder {
|
||||
align: Align::Start,
|
||||
align: Alignment {
|
||||
horizontal: Align::Start,
|
||||
vertical: Align::Start,
|
||||
},
|
||||
label: String::new(),
|
||||
margins: MarginData::EqualsMargin(5),
|
||||
}
|
||||
@@ -33,37 +33,30 @@ impl Product<InputBuilder, Box> for Input {
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
pub fn set_align(mut self, align: Alignment) -> 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)
|
||||
.halign(self.align.horizontal)
|
||||
.valign(self.align.vertical)
|
||||
.set_margin(self.margins)
|
||||
.label(self.label)
|
||||
.build();
|
||||
@@ -84,9 +77,8 @@ impl InputBuilder {
|
||||
input_component.append(&text_view_input_frame);
|
||||
|
||||
Input {
|
||||
component: input_component
|
||||
component: input_component,
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +1,24 @@
|
||||
use std::ops::Deref;
|
||||
use gtk4 as gtk;
|
||||
|
||||
#[allow(unused)]
|
||||
use gtk::{
|
||||
Box,
|
||||
Stack,
|
||||
Widget,
|
||||
Orientation,
|
||||
StackSidebar,
|
||||
StackSwitcher,
|
||||
StackTransitionType,
|
||||
prelude::{BoxExt, IsA},
|
||||
Box, Orientation, Stack, StackSidebar, StackSwitcher, StackTransitionType, Widget,
|
||||
};
|
||||
|
||||
use crate::view::components::builder_traits::{Builder, Product};
|
||||
|
||||
pub type Page<'a> = (&'a str, &'a str, &'a Box);
|
||||
|
||||
pub struct Pages{
|
||||
wrapper: Box
|
||||
pub struct Pages {
|
||||
wrapper: Box,
|
||||
}
|
||||
|
||||
pub struct PagesBuilder{
|
||||
pub struct PagesBuilder {
|
||||
pages_content: Stack,
|
||||
}
|
||||
|
||||
impl Product<PagesBuilder, Box> for Pages {
|
||||
|
||||
fn builder() -> PagesBuilder {
|
||||
PagesBuilder {
|
||||
pages_content: Stack::new(),
|
||||
@@ -35,11 +28,9 @@ impl Product<PagesBuilder, Box> for Pages {
|
||||
fn get(self) -> Box {
|
||||
self.wrapper
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Builder<Pages, Page<'_>, i32> for PagesBuilder{
|
||||
|
||||
impl Builder<Pages, Page<'_>, i32> for PagesBuilder {
|
||||
fn build(&self, build_param: i32) -> Pages {
|
||||
let stack_sidebar = StackSidebar::new();
|
||||
let stack_switcher = StackSwitcher::new();
|
||||
@@ -52,9 +43,7 @@ impl Builder<Pages, Page<'_>, i32> for PagesBuilder{
|
||||
wrapper.append(&stack_sidebar);
|
||||
wrapper.append(&self.pages_content);
|
||||
|
||||
Pages{
|
||||
wrapper
|
||||
}
|
||||
Pages { wrapper }
|
||||
}
|
||||
|
||||
fn append_item(self, item: Page) -> Self {
|
||||
@@ -70,27 +59,18 @@ impl Builder<Pages, Page<'_>, i32> for PagesBuilder{
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl PagesBuilder {
|
||||
|
||||
fn append_page_private(
|
||||
&self,
|
||||
item: Page
|
||||
) {
|
||||
fn append_page_private(&self, item: Page) {
|
||||
self.pages_content.add_titled(item.2, Some(item.1), item.0);
|
||||
}
|
||||
|
||||
pub fn set_transition(
|
||||
self,
|
||||
type_transition : StackTransitionType,
|
||||
duration: u32
|
||||
) -> Self {
|
||||
pub fn set_transition(self, type_transition: StackTransitionType, duration: u32) -> Self {
|
||||
self.pages_content.set_transition_type(type_transition);
|
||||
self.pages_content.set_transition_duration(duration);
|
||||
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
use gtk4 as gtk;
|
||||
|
||||
use gtk::{Notebook, Label, Box};
|
||||
use super::builder_traits::*;
|
||||
use gtk::{Box, Label, Notebook};
|
||||
|
||||
pub type TabLabel = Label;
|
||||
pub type TabContent = Box;
|
||||
@@ -9,43 +9,32 @@ pub type TabPage<'a> = (&'a str, TabContent);
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TabsBuilder {
|
||||
tabs: Vec<(TabLabel, TabContent)>
|
||||
tabs: Vec<(TabLabel, TabContent)>,
|
||||
}
|
||||
|
||||
pub struct Tabs {
|
||||
tabs_wrapper: Notebook
|
||||
tabs_wrapper: Notebook,
|
||||
}
|
||||
|
||||
impl Product<TabsBuilder, Notebook> for Tabs {
|
||||
|
||||
fn builder() -> TabsBuilder {
|
||||
TabsBuilder {
|
||||
tabs: Vec::new(),
|
||||
}
|
||||
TabsBuilder { tabs: Vec::new() }
|
||||
}
|
||||
|
||||
fn get(self) -> Notebook {
|
||||
self.tabs_wrapper
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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()
|
||||
.group_name(build_param)
|
||||
.build();
|
||||
let tabs_wrapper = Notebook::builder().group_name(build_param).build();
|
||||
|
||||
self.tabs
|
||||
.iter()
|
||||
.for_each(|(label, content)| {
|
||||
tabs_wrapper.append_page(content, Some(label));
|
||||
});
|
||||
self.tabs.iter().for_each(|(label, content)| {
|
||||
tabs_wrapper.append_page(content, Some(label));
|
||||
});
|
||||
|
||||
Tabs {
|
||||
tabs_wrapper
|
||||
}
|
||||
Tabs { tabs_wrapper }
|
||||
}
|
||||
|
||||
fn append_item(mut self, item: TabPage) -> Self {
|
||||
@@ -55,21 +44,18 @@ impl Builder<Tabs, TabPage<'_>, &str> for TabsBuilder{
|
||||
}
|
||||
|
||||
fn append_items(mut self, items: Vec<TabPage>) -> Self {
|
||||
for item in items{
|
||||
for item in items {
|
||||
self.append_tab_private(item);
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
impl TabsBuilder {
|
||||
|
||||
fn append_tab_private(&mut self, item: TabPage) {
|
||||
let tab_label = Label::new(Some(item.0));
|
||||
self.tabs.push((tab_label, item.1));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user