Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aligning pin layout #28

Merged
merged 1 commit into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 82 additions & 32 deletions src/piggui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use std::env;
// This binary will only be built with the "iced" feature enabled, by use of "required-features"
// in Cargo.toml so no need for the feature to be used here for conditional compiling
use crate::gpio::{PinDescription, GPIO_DESCRIPTION, GPIOConfig};
use crate::gpio::{GPIOConfig, PinDescription, GPIO_DESCRIPTION};
// Using Custom Widgets
use custom_widgets::{circle::circle, line::line};
use iced::widget::{button, container, Column, Row, Text};
Expand Down Expand Up @@ -65,7 +65,7 @@
// TODO put this on the UI in some way
println!("GPIO Config loaded from file: {filename}");
config
},
}
_ => {
// TODO put this on the UI in some way
println!("Failed to load GPIO Config from file: {filename}");
Expand Down Expand Up @@ -104,52 +104,102 @@
}

fn scale_factor(&self) -> f64 {
0.54
0.7

Check warning on line 107 in src/piggui.rs

View check run for this annotation

Codecov / codecov/patch

src/piggui.rs#L107

Added line #L107 was not covered by tests
}

fn theme(&self) -> iced::Theme {
iced::Theme::Dark
}
}

fn pin_view(pin_descriptions: &[PinDescription; 40],
_pin_config: &GPIOConfig) -> Element<'static, Message> {
// TODO: Align Layout
let mut column = Column::new()
.spacing(20)
.align_items(iced::Alignment::Center)
.width(Length::Fill)
.height(Length::Fill);
fn pin_view(
pin_descriptions: &[PinDescription; 40],
_pin_config: &GPIOConfig,
) -> Element<'static, Message> {
let mut column = Column::new().width(Length::Shrink).height(Length::Shrink);

Check warning on line 119 in src/piggui.rs

View check run for this annotation

Codecov / codecov/patch

src/piggui.rs#L115-L119

Added lines #L115 - L119 were not covered by tests

for pair in pin_descriptions.chunks(2) {
let mut row = Row::new()
.padding(10)
.spacing(10)


// TODO: Style Button

let mut pin_name_left = Column::new()
.width(Length::Fixed(50f32))
.align_items(Alignment::Center);

let mut pin_name_left_row = Row::new().align_items(Alignment::Center);
pin_name_left_row = pin_name_left_row.push(Text::new(pair[0].name));

pin_name_left = pin_name_left.push(pin_name_left_row);

let mut pin_name_right = Column::new()
.width(Length::Fixed(50f32))
.align_items(Alignment::Center);

let mut pin_name_right_row = Row::new().align_items(Alignment::Center);
pin_name_right_row = pin_name_right_row.push(Text::new(pair[1].name));

pin_name_right = pin_name_right.push(pin_name_right_row);

let mut pin_arrow_left = Column::new()
.width(Length::Fixed(60f32))

Check warning on line 145 in src/piggui.rs

View check run for this annotation

Codecov / codecov/patch

src/piggui.rs#L122-L145

Added lines #L122 - L145 were not covered by tests
.align_items(Alignment::Center);

row = row.push(Text::new(pair[0].name).size(20));
let mut pin_arrow_left_row = Row::new().align_items(Alignment::Center);
pin_arrow_left_row = pin_arrow_left_row.push(circle(5.0));
pin_arrow_left_row = pin_arrow_left_row.push(line(50.0));

Check warning on line 150 in src/piggui.rs

View check run for this annotation

Codecov / codecov/patch

src/piggui.rs#L148-L150

Added lines #L148 - L150 were not covered by tests

let mut r1 = Row::new().align_items(Alignment::Center);
r1 = r1.push(circle(5.0));
r1 = r1.push(line(50.0));
row = row.push(r1);
pin_arrow_left = pin_arrow_left.push(pin_arrow_left_row);

Check warning on line 152 in src/piggui.rs

View check run for this annotation

Codecov / codecov/patch

src/piggui.rs#L152

Added line #L152 was not covered by tests

row = row.push(
button(Text::new(pair[0].board_pin_number.to_string()))
.on_press(Message::Activate)
.width(Length::Fixed(50f32)),
let mut pin_arrow_right = Column::new()
.width(Length::Fixed(60f32))
.align_items(Alignment::Center);

let mut pin_arrow_right_row = Row::new().align_items(Alignment::Center);
pin_arrow_right_row = pin_arrow_right_row.push(line(50.0));
pin_arrow_right_row = pin_arrow_right_row.push(circle(5.0));

pin_arrow_right = pin_arrow_right.push(pin_arrow_right_row);

let mut left_pin = Column::new()
.width(Length::Fixed(40f32))
.height(Length::Shrink)
.spacing(20)
.align_items(Alignment::Center);

let mut left_pin_row = Row::new().align_items(Alignment::Center);
left_pin_row = left_pin_row.push(
button(Text::new(pair[0].board_pin_number.to_string()).size(20))
.padding(10)
.on_press(Message::Activate),

Check warning on line 174 in src/piggui.rs

View check run for this annotation

Codecov / codecov/patch

src/piggui.rs#L154-L174

Added lines #L154 - L174 were not covered by tests
);
row = row.push(
button(Text::new(pair[1].board_pin_number.to_string()))
.on_press(Message::Activate)
.width(Length::Fixed(50f32)),

left_pin = left_pin.push(left_pin_row);

let mut right_pin = Column::new()
.width(Length::Fixed(40f32))
.height(Length::Shrink)
.spacing(20)
.align_items(Alignment::Center);

let mut right_pin_row = Row::new().align_items(Alignment::Center);
right_pin_row = right_pin_row.push(
button(Text::new(pair[1].board_pin_number.to_string()).size(20))
.padding(10)
.on_press(Message::Activate),

Check warning on line 189 in src/piggui.rs

View check run for this annotation

Codecov / codecov/patch

src/piggui.rs#L176-L189

Added lines #L176 - L189 were not covered by tests
);
let mut r2 = Row::new().align_items(Alignment::Center);
r2 = r2.push(line(50.0));
r2 = r2.push(circle(5.0));
row = row.push(r2);

row = row.push(Text::new(pair[1].name).size(20));
right_pin = right_pin.push(right_pin_row);

let row = Row::new()
.push(pin_name_left)
.push(pin_arrow_left)
.push(left_pin)
.push(right_pin)
.push(pin_arrow_right)
.push(pin_name_right)
.spacing(10)
.align_items(Alignment::Center);

Check warning on line 202 in src/piggui.rs

View check run for this annotation

Codecov / codecov/patch

src/piggui.rs#L192-L202

Added lines #L192 - L202 were not covered by tests

column = column.push(row);
}
Expand Down
Loading