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

Labels #4

Merged
merged 6 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
os:
- windows
#- windows
- linux
- osx
language: rust
Expand Down
93 changes: 57 additions & 36 deletions Cargo.lock

Large diffs are not rendered by default.

Binary file added assets/FiraSans-Regular.ttf
Binary file not shown.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

A cross platform UI toolkit based on Piston.

Pronounced "ru-su-ee".
Pronounced "are-sue-we".

## Principles

Expand Down
4 changes: 2 additions & 2 deletions scripts/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export UNAME="$(uname -s)"
case "${UNAME}" in
Linux*) export DIST=linux ZIP_EXT=tgz;;
Darwin*) export DIST=darwin ZIP_EXT=tgz;;
CYGWIN*) export DIST=windows ZIP_EXT=zip;;
MINGW*) export DIST=windows ZIP_EXT=zip;;
CYGWIN*) export DIST=windows ZIP_EXT=zip ALLOW_FAILURE=true;;
MINGW*) export DIST=windows ZIP_EXT=zip ALLOW_FAILURE=true;;
*) export DIST="UNKNOWN:${UNAME}"
esac
echo DIST=${DIST} EXT=$ZIP_EXT
Expand Down
14 changes: 9 additions & 5 deletions src/drawing_window.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use piston_window::{PistonWindow, WindowSettings, Window};
use piston_window::{PistonWindow, WindowSettings, Window, Glyphs, TextureSettings};
use glfw_window::GlfwWindow;

use crate::widget::Widget;

pub struct DrawingWindow<'a> {
pub window: PistonWindow<GlfwWindow>,
pub root: &'a Widget,
pub glyphs: Glyphs
}

impl<'a> DrawingWindow<'a> {
Expand All @@ -15,22 +16,25 @@ impl<'a> DrawingWindow<'a> {
WindowSettings::new("title", [640, 480])
.build().unwrap();

// let window: PistonWindow = WindowSettings::new("Title", [640, 480])
// .build()
// .unwrap();
let font_data: &[u8] = include_bytes!("../assets/FiraSans-Regular.ttf");
let factory = window.factory.clone();
let glyphs = Glyphs::from_bytes(font_data, factory, TextureSettings::new()).unwrap();

DrawingWindow {
window,
root,
glyphs
}
}

pub fn run(&mut self) {
let root = self.root;
let glyphs = &mut self.glyphs;
while let Some(event) = self.window.next() {
let width = self.window.size().width;
let height = self.window.size().height;
self.window.draw_2d(&event, |context, gl| {
root.draw(context, gl, width, height);
root.draw(context, gl, width, height, glyphs);
});
// if let Some(Button::Keyboard(key)) = event.press_args() {
// self.handle_key_input(key);
Expand Down
24 changes: 17 additions & 7 deletions src/grid_panel.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use piston_window::{G2d, Context, Rectangle, rectangle, line};
use piston_window::*;
use piston_window::text::Text;

use crate::widget::Widget;

Expand All @@ -15,17 +16,26 @@ impl GridPanel {
}

impl Widget for GridPanel {
fn draw(&self, context: Context, gl: &mut G2d, width: f64, height: f64) {
fn draw(&self, c: Context, gl: &mut G2d, width: f64, height: f64, glyphs: &mut Glyphs) {
let grid_size = 25;
let rectangle = Rectangle::new(self.background_color);
let square = rectangle::rectangle_by_corners(0.0, 0.0, width as f64, height as f64);
rectangle.draw(square, &context.draw_state, context.transform.clone(), gl);
rectangle.draw(square, &c.draw_state, c.transform.clone(), gl);

let white = [1.0, 1.0, 1.0, 1.0];
for x in (0..(width as i32)).step_by(100) {
line(white, 1.0, [x as f64, 0.0, x as f64, height], context.transform.clone(), gl);
for x in (0..(width as i32)).step_by(grid_size) {
if x % 100 == 0 {
let transform = c.transform.trans(x as f64 + 2.0, 21.0);
Text::new_color(white, 24).draw(&x.to_string(), glyphs, &c.draw_state, transform, gl)
.unwrap();
}
line(white, 1.0, [x as f64, 0.0, x as f64, height], c.transform.clone(), gl);
}
for y in (0..(height as i32)).step_by(100) {
line(white, 1.0, [0.0, y as f64, width, y as f64], context.transform.clone(), gl);
for y in (0..(height as i32)).step_by(grid_size) {
line(white, 1.0, [0.0, y as f64, width, y as f64], c.transform.clone(), gl);
let transform = c.transform.trans(0.0, y as f64 - 4.0);
Text::new_color(white, 24).draw(&y.to_string(), glyphs, &c.draw_state, transform, gl)
.unwrap();
}
}
}
4 changes: 2 additions & 2 deletions src/widget.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use piston_window::{G2d, Context};
use piston_window::{G2d, Context, Glyphs};

pub trait Widget {
fn draw(&self, context: Context, gl: &mut G2d, width: f64, height: f64);
fn draw(&self, context: Context, gl: &mut G2d, width: f64, height: f64, glyphs: &mut Glyphs);
}