Last active
April 13, 2020 19:50
-
-
Save chaoky/9345858715428747b6c8d1476ef03ad0 to your computer and use it in GitHub Desktop.
covid_chart_thingy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use quicksilver::{ | |
geom::{Rectangle, Vector}, | |
graphics::{Color, Graphics}, | |
lifecycle::{run, EventStream, Settings, Window}, | |
Result, | |
}; | |
use iced::{button, Align, Button, Column, Element, Sandbox, Text}; | |
use iced::Settings as IcedS; | |
fn main() { | |
if cfg!(target_arch = "wasm32") { | |
Counter::run(IcedS::default()); | |
run( | |
Settings { | |
size: Vector::new(800.0, 600.0).into(), | |
title: "Square Example", | |
..Settings::default() | |
}, | |
app, | |
); | |
} else { | |
//don't know yet | |
Counter::run(IcedS::default()); | |
} | |
} | |
// QuickSilver | |
async fn app(window: Window, mut gfx: Graphics, mut events: EventStream) -> Result<()> { | |
// Clear the screen to a blank, white color | |
gfx.clear(Color::WHITE); | |
// Paint a blue square with a red outline in the center of our screen | |
// It should have a top-left of (350, 100) and a size of (150, 100) | |
let rect = Rectangle::new(Vector::new(350.0, 100.0), Vector::new(100.0, 100.0)); | |
gfx.fill_rect(&rect, Color::BLUE); | |
gfx.stroke_rect(&rect, Color::RED); | |
// Send the data to be drawn | |
gfx.present(&window)?; | |
loop { | |
while let Some(_) = events.next_event().await {} | |
} | |
} | |
// Iced | |
#[derive(Default)] | |
struct Counter { | |
value: i32, | |
increment_button: button::State, | |
decrement_button: button::State, | |
} | |
#[derive(Debug, Clone, Copy)] | |
enum Message { | |
IncrementPressed, | |
DecrementPressed, | |
} | |
impl Sandbox for Counter { | |
type Message = Message; | |
fn new() -> Self { | |
Self::default() | |
} | |
fn title(&self) -> String { | |
String::from("Counter - Iced") | |
} | |
fn update(&mut self, message: Message) { | |
match message { | |
Message::IncrementPressed => { | |
self.value += 1; | |
} | |
Message::DecrementPressed => { | |
self.value -= 1; | |
} | |
} | |
} | |
fn view(&mut self) -> Element<Message> { | |
Column::new() | |
.padding(20) | |
.align_items(Align::Center) | |
.push( | |
Button::new(&mut self.increment_button, Text::new("Increment")) | |
.on_press(Message::IncrementPressed), | |
) | |
.push(Text::new(self.value.to_string()).size(50)) | |
.push( | |
Button::new(&mut self.decrement_button, Text::new("Decrement")) | |
.on_press(Message::DecrementPressed), | |
) | |
.into() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment