Skip to content

Commit

Permalink
Cleanup topbar rendering (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex authored Mar 10, 2024
1 parent 87e1f5a commit cc077ff
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 160 deletions.
4 changes: 4 additions & 0 deletions neothesia-core/src/render/quad/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ impl<'a> QuadPipeline {
&mut self.instances.data
}

pub fn push(&mut self, quad: QuadInstance) {
self.instances.data.push(quad)
}

pub fn prepare(&self, queue: &wgpu::Queue) {
self.instances.update(queue);
}
Expand Down
36 changes: 36 additions & 0 deletions neothesia-core/src/utils/bbox.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use super::{Point, Size};

#[derive(Default, Clone, Copy)]
pub struct Bbox {
pub pos: Point<f32>,
pub size: Size<f32>,
}

impl Bbox {
pub fn new(pos: Point<f32>, size: Size<f32>) -> Self {
Self { pos, size }
}

pub fn contains(&self, px: f32, py: f32) -> bool {
let Point { x, y } = self.pos;
let Size { w, h } = self.size;

(x..(x + w)).contains(&px) && (y..(y + h)).contains(&py)
}

pub fn x(&self) -> f32 {
self.pos.x
}

pub fn y(&self) -> f32 {
self.pos.y
}

pub fn w(&self) -> f32 {
self.size.w
}

pub fn h(&self) -> f32 {
self.size.h
}
}
15 changes: 15 additions & 0 deletions neothesia-core/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
pub mod bbox;
pub mod resources;

pub use bbox::Bbox;

#[derive(Debug, Default, Clone, Copy)]
pub struct Point<T> {
pub x: T,
pub y: T,
}

impl<T> Point<T> {
pub fn new(x: T, y: T) -> Self {
Self { x, y }
}
}

impl<T> From<(T, T)> for Point<T> {
fn from((x, y): (T, T)) -> Self {
Self { x, y }
Expand Down Expand Up @@ -54,6 +63,12 @@ pub struct Size<T> {
pub h: T,
}

impl<T> Size<T> {
pub fn new(w: T, h: T) -> Self {
Self { w, h }
}
}

impl<T> From<(T, T)> for Size<T> {
fn from((w, h): (T, T)) -> Self {
Self { w, h }
Expand Down
Loading

0 comments on commit cc077ff

Please sign in to comment.