54 lines
1.1 KiB
Rust
54 lines
1.1 KiB
Rust
use std::f32::consts::TAU;
|
|
|
|
use rhai::ImmutableString;
|
|
|
|
use super::super::api::Rect;
|
|
use crate::{ui::api::Color, vertexbuffer::types::RadialBarInstance, RenderInput, RenderState};
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct RadialBar {
|
|
pub name: ImmutableString,
|
|
rect: Rect,
|
|
stroke: f32,
|
|
color: Color,
|
|
progress: f32,
|
|
}
|
|
|
|
impl RadialBar {
|
|
pub fn new(
|
|
name: ImmutableString,
|
|
stroke: f32,
|
|
color: Color,
|
|
rect: Rect,
|
|
progress: f32,
|
|
) -> Self {
|
|
Self {
|
|
name,
|
|
rect,
|
|
stroke,
|
|
color,
|
|
progress: progress.clamp(0.0, 1.0),
|
|
}
|
|
}
|
|
|
|
pub fn set_val(&mut self, val: f32) {
|
|
self.progress = val.clamp(0.0, 1.0);
|
|
}
|
|
|
|
pub fn push_to_buffer(&self, input: &RenderInput, state: &mut RenderState) {
|
|
let rect = self
|
|
.rect
|
|
.to_centered(&state.window, input.ct.get_config().ui_scale);
|
|
|
|
state.push_radialbar_buffer(RadialBarInstance {
|
|
position: [rect.pos.x, rect.pos.y],
|
|
diameter: rect.dim.x.min(rect.dim.y),
|
|
stroke: self.stroke * input.ct.get_config().ui_scale,
|
|
color: self.color.as_array(),
|
|
angle: self.progress * TAU,
|
|
});
|
|
}
|
|
|
|
pub fn step(&mut self, _input: &RenderInput, _state: &mut RenderState) {}
|
|
}
|