Skip to content
Snippets Groups Projects
Commit 92a715df authored by Finn Bear's avatar Finn Bear
Browse files

Grid.

parent 03f17a99
No related branches found
No related tags found
No related merge requests found
pub mod grid;
use eframe::egui::{Align2, Color32, Context, Pos2, Rect, Shape, Stroke, Ui, Vec2, Window};
use eframe::emath;
pub struct Grid {
name: &'static str,
offset_x: f32,
offset_y: f32,
size_cells: usize,
size_pixels: f32,
stroke: Color32,
}
impl Default for Grid {
fn default() -> Self {
Self {
name: "grid",
offset_x: 0.0,
offset_y: 0.0,
size_cells: 16,
size_pixels: 400.0,
stroke: Color32::GRAY,
}
}
}
impl Grid {
pub fn show(&self, ctx: &Context) {
Window::new(self.name)
.title_bar(false)
//.frame(Frame::none())
.anchor(Align2::CENTER_CENTER, Vec2::ZERO)
.fixed_size(Vec2::splat(self.size_pixels))
.show(ctx, |ui| {
let (_id, rect) = ui.allocate_space(Vec2::splat(self.size_pixels));
let to_screen = emath::RectTransform::from_to(
Rect::from_x_y_ranges(0.0..=1.0, 0.0..=1.0),
rect,
);
for c in 0..=self.size_cells {
let coord = c as f32 / self.size_cells as f32;
// Horizontal.
ui.painter().add(Shape::LineSegment {
points: [
to_screen * Pos2::new(0.0, coord),
to_screen * Pos2::new(1.0, coord),
],
stroke: Stroke::new(1.0, self.stroke),
});
// Vertical.
ui.painter().add(Shape::LineSegment {
points: [
to_screen * Pos2::new(coord, 0.0),
to_screen * Pos2::new(coord, 1.0),
],
stroke: Stroke::new(1.0, self.stroke),
});
}
for x in 0..=self.size_cells {
for y in 0..=self.size_cells {}
}
});
}
}
#![feature(derive_default_enum)]
pub mod component;
pub mod image;
pub mod slide;
......
use crate::component::grid::Grid;
use crate::Slide;
use eframe::egui::{
Align2, Color32, Context, Frame, Grid, Pos2, Rect, Shape, Stroke, Ui, Vec2, Window,
};
use eframe::egui::{Align2, Color32, Context, Frame, Pos2, Rect, Shape, Stroke, Ui, Vec2, Window};
use eframe::emath;
#[derive(Default)]
pub struct Conway {}
pub struct Conway {
life: Grid,
}
impl Slide for Conway {
fn show(&mut self, ui: &mut Ui, ctx: &Context) {
let PIXELS: f32 = 400.0;
let CELLS: usize = 32;
Window::new("conway")
.title_bar(false)
//.frame(Frame::none())
.anchor(Align2::CENTER_CENTER, Vec2::ZERO)
.fixed_size(Vec2::splat(PIXELS))
.show(ctx, |ui| {
let (_id, rect) = ui.allocate_space(Vec2::splat(PIXELS));
let to_screen = emath::RectTransform::from_to(
Rect::from_x_y_ranges(0.0..=1.0, 0.0..=1.0),
rect,
);
for c in 0..=CELLS {
let coord = c as f32 / CELLS as f32;
// Horizontal.
ui.painter().add(Shape::LineSegment {
points: [
to_screen * Pos2::new(0.0, coord),
to_screen * Pos2::new(1.0, coord),
],
stroke: Stroke::new(1.0, Color32::BLACK),
});
// Vertical.
ui.painter().add(Shape::LineSegment {
points: [
to_screen * Pos2::new(coord, 0.0),
to_screen * Pos2::new(coord, 1.0),
],
stroke: Stroke::new(1.0, Color32::GRAY),
});
}
for x in 0..=CELLS {
for y in 0..=CELLS {}
}
});
self.life.show(ctx);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment