Skip to content

Commit

Permalink
Merge pull request #17 from sundaram123krishnan/master
Browse files Browse the repository at this point in the history
Adding basic 40 pin layout
  • Loading branch information
andrewdavidmackenzie authored May 14, 2024
2 parents 50e0afc + d932749 commit 4dc9351
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const NO_CONFIG: Option<PinConfig> = None;
// If no specific config is set on a pin, it will have None
#[derive(Debug)]
pub struct GPIOConfig {
pin_configs: [Option<PinConfig>; 40]
pub pin_configs: [Option<PinConfig>; 40]
}

impl GPIOConfig {
Expand Down
65 changes: 55 additions & 10 deletions src/piggui.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
mod gpio;

use gpio::PinConfig;
// 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 iced::widget::text;
use iced::{window, Element, Sandbox, Settings};
use iced::widget::{button, container, row, Column, Text};
use iced::{alignment, window, Element, Length, Sandbox, Settings};

fn main() -> Result<(), iced::Error> {
fn main() -> iced::Result {
let window = window::Settings {
resizable: false,
..Default::default()
Expand All @@ -22,27 +23,71 @@ fn main() -> Result<(), iced::Error> {
})
}

struct Gpio;
struct Gpio {
pins: [Option<PinConfig>; 40],
clicked: bool,
}

#[derive(Debug, Clone, Copy)]

#[derive(Debug)]
enum Message {}
enum Message {
Activate,
}

impl Sandbox for Gpio {
type Message = Message;

fn new() -> Self {
Self
let config = gpio::GPIOConfig::new();
Self {
pins: config.pin_configs,
clicked: false,
}
}

fn title(&self) -> String {
String::from("Piggui")
}

fn update(&mut self, message: Message) {
match message {}
match message {
Message::Activate => self.clicked = true,
}
}
fn view(&self) -> Element<'_, Message> {
text("Hello iced").into()

fn view(&self) -> iced::Element<Self::Message> {
container(pin_view(&self.pins))
.height(Length::Fill)
.width(Length::Fill)
.align_x(alignment::Horizontal::Center)
.align_y(alignment::Vertical::Center)
.into()
}

fn scale_factor(&self) -> f64 {
0.75
}

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

fn pin_view(pins: &[Option<PinConfig>; 40]) -> Element<'static, Message> {
let mut column = Column::new()
.spacing(20)
.align_items(iced::Alignment::Center)
.width(Length::Fill)
.height(Length::Fill);

for _i in 0..pins.len() / 2 {
let row = row!(
// add radio button
button(Text::new("pin1")).on_press(Message::Activate),
button(Text::new("pin2")).on_press(Message::Activate)
)
.spacing(10);
column = column.push(row);
}
container(column).height(2000).width(2000).into()
}

0 comments on commit 4dc9351

Please sign in to comment.