contextless gaming

This commit is contained in:
2025-08-25 19:21:39 -04:00
parent e8b255c8f9
commit e9037cdc14
6 changed files with 27 additions and 46 deletions

View File

@@ -38,7 +38,7 @@ impl<W: WidgetLike<Tag>, Tag> Sensable<W::Widget, Tag> for W {
{
self.with_id(move |ui, id| {
let id2 = id.clone();
ui.add(id.on(sense, move |ctx| f(&id2, ctx)))
ui.add(id.on(sense, move |ui| f(&id2, ui)))
})
}
fn edit_on(

View File

@@ -43,6 +43,7 @@ pub struct SenseTrigger {
pub shape: SenseShape,
pub sense: Sense,
}
#[derive(Default)]
pub struct SensorGroup {
pub hover: ActivationState,
pub cursor: ActivationState,
@@ -134,15 +135,6 @@ impl ActivationState {
}
}
impl Default for SensorGroup {
fn default() -> Self {
Self {
hover: Default::default(),
cursor: Default::default(),
sensors: Default::default(),
}
}
}
impl Clone for SensorGroup {
fn clone(&self) -> Self {
Self {

View File

@@ -7,7 +7,7 @@
pub mod core;
pub mod layout;
pub mod render;
mod util;
pub mod util;
pub mod prelude {
pub use crate::core::*;

View File

@@ -1,4 +1,3 @@
use ui::layout::Ui;
use winit::{
application::ApplicationHandler,
event::WindowEvent,
@@ -10,7 +9,7 @@ use super::Client;
#[derive(Default)]
pub struct App {
client: Option<(Client, Ui)>,
client: Option<Client>,
}
impl App {
@@ -26,14 +25,13 @@ impl ApplicationHandler for App {
let window = event_loop
.create_window(Window::default_attributes())
.unwrap();
let (ui, cui) = Client::create_ui();
let client = Client::new(window.into(), cui);
self.client = Some((client, ui));
let client = Client::new(window.into());
self.client = Some(client);
}
}
fn window_event(&mut self, event_loop: &ActiveEventLoop, _id: WindowId, event: WindowEvent) {
let (client, ui) = self.client.as_mut().unwrap();
client.event(event, event_loop, ui);
let client = self.client.as_mut().unwrap();
client.event(event, event_loop);
}
}

View File

@@ -18,16 +18,15 @@ pub fn main() {
pub struct Client {
renderer: Renderer,
input: Input,
ui: ClientUi,
}
pub struct ClientUi {
ui: Ui,
info: WidgetId<Text>,
old_info: String,
}
impl Client {
pub fn create_ui() -> (Ui, ClientUi) {
pub fn new(window: Arc<Window>) -> Self {
let renderer = Renderer::new(window);
let mut ui = Ui::new();
let rect = Rect {
color: UiColor::WHITE,
@@ -148,52 +147,44 @@ impl Client {
.span(Dir::DOWN, [fixed(40), ratio(1)])
.label("root"),
);
(
ui,
ClientUi {
info,
old_info: String::new(),
},
)
}
pub fn new(window: Arc<Window>, ui: ClientUi) -> Self {
let renderer = Renderer::new(window);
Self {
renderer,
input: Input::default(),
ui,
info,
old_info: String::new(),
}
}
pub fn event(&mut self, event: WindowEvent, event_loop: &ActiveEventLoop, ui: &mut Ui) {
pub fn event(&mut self, event: WindowEvent, event_loop: &ActiveEventLoop) {
self.input.event(&event);
let cursor_state = self.cursor_state();
let window_size = self.window_size();
ui.run_sensors(&cursor_state, window_size);
self.ui.run_sensors(&cursor_state, window_size);
match event {
WindowEvent::CloseRequested => event_loop.exit(),
WindowEvent::RedrawRequested => {
ui.update();
self.renderer.update(ui);
self.ui.update();
self.renderer.update(&mut self.ui);
self.renderer.draw()
}
WindowEvent::Resized(size) => {
ui.resize((size.width, size.height));
self.ui.resize((size.width, size.height));
self.renderer.resize(&size)
}
_ => (),
}
let new = format!(
"widgets: {}\nviews: {}",
ui.num_widgets(),
self.ui.num_widgets(),
self.renderer.ui.view_count()
);
if new != self.ui.old_info {
ui[&self.ui.info].content = new.clone();
self.ui.old_info = new;
if new != self.old_info {
self.ui[&self.info].content = new.clone();
self.old_info = new;
}
if ui.needs_redraw() {
if self.ui.needs_redraw() {
self.renderer.window().request_redraw();
}
}

View File

@@ -2,9 +2,9 @@ mod id;
mod math;
mod refcount;
pub use id::*;
pub use math::*;
pub use refcount::*;
pub(crate) use id::*;
pub(crate) use math::*;
pub(crate) use refcount::*;
pub type HashMap<K, V> = std::collections::HashMap<K, V>;
pub type HashSet<K> = std::collections::HashSet<K>;