Skip to content

Commit

Permalink
Restyle dashboard (#16)
Browse files Browse the repository at this point in the history
* Add simple cover image to README.md

* Add docs for widget creation

* Restyle dashboard
  • Loading branch information
eliabieri authored Dec 15, 2022
1 parent 5229881 commit 8492643
Show file tree
Hide file tree
Showing 20 changed files with 201 additions and 98 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# WG Display

[![Cargo test](https://github.com/eliabieri/wg_display/actions/workflows/cargo_test.yml/badge.svg)](https://github.com/eliabieri/wg_display/actions/workflows/cargo_test.yml)
#### All that goes on in your city at one glance. Extensible, open-source and connected to the local community.

## All that goes on in your city at one glance

## Extensible, open-source and connected to the local community

![WG Display image front](docs/images/wg_display.jpg)
8 changes: 4 additions & 4 deletions app/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ impl Renderer {
self.widgets.iter().for_each(|widget| {
let name_widget = LinearLayout::horizontal().child(TextView::new(format!(
"{:width$}",
widget.get_name().as_str(),
widget.get_meta_data().name(),
width = self.name_column_width()
)));

let content_widget =
TextView::new(widget.get_content()).with_name(widget.get_name().as_str());
TextView::new(widget.get_content()).with_name(widget.get_meta_data().name());

let padded_view = name_widget.child(content_widget);
linear_layout.add_child(padded_view);
Expand All @@ -95,7 +95,7 @@ impl Renderer {
));

self.widgets.iter_mut().for_each(|widget| {
siv.call_on_name(widget.get_name().as_str(), |view: &mut TextView| {
siv.call_on_name(widget.get_meta_data().name(), |view: &mut TextView| {
view.set_content(widget.get_content());
});
});
Expand All @@ -104,7 +104,7 @@ impl Renderer {
fn name_column_width(&self) -> usize {
self.widgets
.iter()
.map(|widget| widget.get_name().as_str().len())
.map(|widget| widget.get_meta_data().name().len())
.max()
.unwrap()
+ 2
Expand Down
6 changes: 3 additions & 3 deletions app/src/renderer/widgets/aare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::time::{Duration, Instant};

use super::base::Widget;
use common::models::WidgetConfiguration;
use common::widgets::WidgetName;
use common::widget_meta_data::WidgetMetaData;
use serde::Deserialize;

#[derive(Deserialize)]
Expand Down Expand Up @@ -32,8 +32,8 @@ impl Widget for Aare {
}
}

fn get_name(&self) -> WidgetName {
WidgetName::Aare
fn get_meta_data(&self) -> common::widget_meta_data::WidgetMetaData {
WidgetMetaData::Aare
}

fn get_content(&self) -> &str {
Expand Down
4 changes: 2 additions & 2 deletions app/src/renderer/widgets/base.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use async_trait::async_trait;
use common::models::WidgetConfiguration;
use common::widgets::WidgetName;
use common::widget_meta_data::WidgetMetaData;

#[async_trait]
pub trait Widget {
fn new() -> Self
where
Self: Sized;
fn get_name(&self) -> WidgetName;
fn get_meta_data(&self) -> WidgetMetaData;
fn get_content(&self) -> &str;

async fn update(&mut self, config: &WidgetConfiguration);
Expand Down
6 changes: 3 additions & 3 deletions app/src/renderer/widgets/bernaqua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::time::{Duration, Instant};

use super::base::Widget;
use common::models::WidgetConfiguration;
use common::widgets::WidgetName;
use common::widget_meta_data::WidgetMetaData;
use serde::Deserialize;

#[derive(Deserialize)]
Expand Down Expand Up @@ -35,8 +35,8 @@ impl Widget for Bernaqua {
}
}

fn get_name(&self) -> WidgetName {
WidgetName::Bernaqua
fn get_meta_data(&self) -> common::widget_meta_data::WidgetMetaData {
WidgetMetaData::Bernaqua
}

fn get_content(&self) -> &str {
Expand Down
6 changes: 3 additions & 3 deletions app/src/renderer/widgets/cafete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::time::{Duration, Instant};

use super::base::Widget;
use common::models::WidgetConfiguration;
use common::widgets::WidgetName;
use common::widget_meta_data::WidgetMetaData;
use serde::Deserialize;

#[derive(Deserialize)]
Expand Down Expand Up @@ -37,8 +37,8 @@ impl Widget for Cafete {
}
}

fn get_name(&self) -> WidgetName {
WidgetName::Cafete
fn get_meta_data(&self) -> common::widget_meta_data::WidgetMetaData {
WidgetMetaData::Cafete
}

fn get_content(&self) -> &str {
Expand Down
7 changes: 4 additions & 3 deletions app/src/renderer/widgets/public_transport.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::time::{Duration, Instant};

use common::{models::WidgetConfiguration, widgets::WidgetName};
use common::models::WidgetConfiguration;
use common::widget_meta_data::WidgetMetaData;
use serde::Deserialize;
use time::OffsetDateTime;
use time_humanize::{Accuracy, HumanTime, Tense};
Expand Down Expand Up @@ -66,8 +67,8 @@ impl Widget for PublicTransport {
}
}

fn get_name(&self) -> common::widgets::WidgetName {
WidgetName::PublicTransport
fn get_meta_data(&self) -> common::widget_meta_data::WidgetMetaData {
WidgetMetaData::PublicTransport
}

fn get_content(&self) -> &str {
Expand Down
7 changes: 4 additions & 3 deletions app/src/renderer/widgets/time.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::base::Widget;
use async_trait::async_trait;
use common::{models::WidgetConfiguration, widgets::WidgetName};
use common::models::WidgetConfiguration;
use common::widget_meta_data::WidgetMetaData;

extern crate chrono;
use chrono::Local;
Expand All @@ -17,8 +18,8 @@ impl Widget for Time {
}
}

fn get_name(&self) -> WidgetName {
WidgetName::Time
fn get_meta_data(&self) -> common::widget_meta_data::WidgetMetaData {
WidgetMetaData::Time
}

fn get_content(&self) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod models;
pub mod widgets;
pub mod widget_meta_data;
30 changes: 30 additions & 0 deletions common/src/widget_meta_data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#[derive(PartialEq, Clone)]
pub enum WidgetMetaData {
Cafete,
Aare,
Time,
Bernaqua,
PublicTransport,
}

impl WidgetMetaData {
pub fn name(&self) -> &'static str {
match self {
WidgetMetaData::Cafete => "Cafete",
WidgetMetaData::Aare => "Aare",
WidgetMetaData::Time => "Time",
WidgetMetaData::Bernaqua => "Bernaqua",
WidgetMetaData::PublicTransport => "Next departure",
}
}

pub fn description(&self) -> &'static str {
match self {
WidgetMetaData::Cafete => "Events happening at the Cafete Club in Bern",
WidgetMetaData::Aare => "The temperature of the Aare river in Bern",
WidgetMetaData::Time => "The current time",
WidgetMetaData::Bernaqua => "Occupancy of the Bernaqua facilities",
WidgetMetaData::PublicTransport => "Next public transport departures",
}
}
}
19 changes: 0 additions & 19 deletions common/src/widgets.rs

This file was deleted.

Binary file added docs/images/wg_display.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions docs/write_new_widget.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Writing a new widget

## What is a widget

A widget represents an information displayed on the display.
It has a name and a corresponding value, that is updated dinamically.
Additionally, a widget consumes a configuration, that is entered by the user via the dashboard.

## What is needed to build a widget

- A Yew component that visualizes the configuration options in the dashboard.
- An implementation of the `Widget` trait. In here, the value of the widget is fetched or computed.

```text
💡 Simple widgets can use the DefaultWidgetConfig component, that only allows for the widget to be enabled or disabled
```

## Learning by example
Loading

0 comments on commit 8492643

Please sign in to comment.