contextless gaming
This commit is contained in:
@@ -38,7 +38,7 @@ impl<W: WidgetLike<Tag>, Tag> Sensable<W::Widget, Tag> for W {
|
|||||||
{
|
{
|
||||||
self.with_id(move |ui, id| {
|
self.with_id(move |ui, id| {
|
||||||
let id2 = id.clone();
|
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(
|
fn edit_on(
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ pub struct SenseTrigger {
|
|||||||
pub shape: SenseShape,
|
pub shape: SenseShape,
|
||||||
pub sense: Sense,
|
pub sense: Sense,
|
||||||
}
|
}
|
||||||
|
#[derive(Default)]
|
||||||
pub struct SensorGroup {
|
pub struct SensorGroup {
|
||||||
pub hover: ActivationState,
|
pub hover: ActivationState,
|
||||||
pub cursor: 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 {
|
impl Clone for SensorGroup {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
pub mod core;
|
pub mod core;
|
||||||
pub mod layout;
|
pub mod layout;
|
||||||
pub mod render;
|
pub mod render;
|
||||||
mod util;
|
pub mod util;
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use crate::core::*;
|
pub use crate::core::*;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use ui::layout::Ui;
|
|
||||||
use winit::{
|
use winit::{
|
||||||
application::ApplicationHandler,
|
application::ApplicationHandler,
|
||||||
event::WindowEvent,
|
event::WindowEvent,
|
||||||
@@ -10,7 +9,7 @@ use super::Client;
|
|||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct App {
|
pub struct App {
|
||||||
client: Option<(Client, Ui)>,
|
client: Option<Client>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
@@ -26,14 +25,13 @@ impl ApplicationHandler for App {
|
|||||||
let window = event_loop
|
let window = event_loop
|
||||||
.create_window(Window::default_attributes())
|
.create_window(Window::default_attributes())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let (ui, cui) = Client::create_ui();
|
let client = Client::new(window.into());
|
||||||
let client = Client::new(window.into(), cui);
|
self.client = Some(client);
|
||||||
self.client = Some((client, ui));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn window_event(&mut self, event_loop: &ActiveEventLoop, _id: WindowId, event: WindowEvent) {
|
fn window_event(&mut self, event_loop: &ActiveEventLoop, _id: WindowId, event: WindowEvent) {
|
||||||
let (client, ui) = self.client.as_mut().unwrap();
|
let client = self.client.as_mut().unwrap();
|
||||||
client.event(event, event_loop, ui);
|
client.event(event, event_loop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,16 +18,15 @@ pub fn main() {
|
|||||||
pub struct Client {
|
pub struct Client {
|
||||||
renderer: Renderer,
|
renderer: Renderer,
|
||||||
input: Input,
|
input: Input,
|
||||||
ui: ClientUi,
|
ui: Ui,
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ClientUi {
|
|
||||||
info: WidgetId<Text>,
|
info: WidgetId<Text>,
|
||||||
old_info: String,
|
old_info: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Client {
|
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 mut ui = Ui::new();
|
||||||
let rect = Rect {
|
let rect = Rect {
|
||||||
color: UiColor::WHITE,
|
color: UiColor::WHITE,
|
||||||
@@ -148,52 +147,44 @@ impl Client {
|
|||||||
.span(Dir::DOWN, [fixed(40), ratio(1)])
|
.span(Dir::DOWN, [fixed(40), ratio(1)])
|
||||||
.label("root"),
|
.label("root"),
|
||||||
);
|
);
|
||||||
(
|
|
||||||
ui,
|
|
||||||
ClientUi {
|
|
||||||
info,
|
|
||||||
old_info: String::new(),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new(window: Arc<Window>, ui: ClientUi) -> Self {
|
|
||||||
let renderer = Renderer::new(window);
|
|
||||||
Self {
|
Self {
|
||||||
renderer,
|
renderer,
|
||||||
input: Input::default(),
|
input: Input::default(),
|
||||||
ui,
|
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);
|
self.input.event(&event);
|
||||||
let cursor_state = self.cursor_state();
|
let cursor_state = self.cursor_state();
|
||||||
let window_size = self.window_size();
|
let window_size = self.window_size();
|
||||||
ui.run_sensors(&cursor_state, window_size);
|
self.ui.run_sensors(&cursor_state, window_size);
|
||||||
match event {
|
match event {
|
||||||
WindowEvent::CloseRequested => event_loop.exit(),
|
WindowEvent::CloseRequested => event_loop.exit(),
|
||||||
WindowEvent::RedrawRequested => {
|
WindowEvent::RedrawRequested => {
|
||||||
ui.update();
|
self.ui.update();
|
||||||
self.renderer.update(ui);
|
self.renderer.update(&mut self.ui);
|
||||||
self.renderer.draw()
|
self.renderer.draw()
|
||||||
}
|
}
|
||||||
WindowEvent::Resized(size) => {
|
WindowEvent::Resized(size) => {
|
||||||
ui.resize((size.width, size.height));
|
self.ui.resize((size.width, size.height));
|
||||||
self.renderer.resize(&size)
|
self.renderer.resize(&size)
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
let new = format!(
|
let new = format!(
|
||||||
"widgets: {}\nviews: {}",
|
"widgets: {}\nviews: {}",
|
||||||
ui.num_widgets(),
|
self.ui.num_widgets(),
|
||||||
self.renderer.ui.view_count()
|
self.renderer.ui.view_count()
|
||||||
);
|
);
|
||||||
if new != self.ui.old_info {
|
if new != self.old_info {
|
||||||
ui[&self.ui.info].content = new.clone();
|
self.ui[&self.info].content = new.clone();
|
||||||
self.ui.old_info = new;
|
self.old_info = new;
|
||||||
}
|
}
|
||||||
if ui.needs_redraw() {
|
if self.ui.needs_redraw() {
|
||||||
self.renderer.window().request_redraw();
|
self.renderer.window().request_redraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ mod id;
|
|||||||
mod math;
|
mod math;
|
||||||
mod refcount;
|
mod refcount;
|
||||||
|
|
||||||
pub use id::*;
|
pub(crate) use id::*;
|
||||||
pub use math::*;
|
pub(crate) use math::*;
|
||||||
pub use refcount::*;
|
pub(crate) use refcount::*;
|
||||||
|
|
||||||
pub type HashMap<K, V> = std::collections::HashMap<K, V>;
|
pub type HashMap<K, V> = std::collections::HashMap<K, V>;
|
||||||
pub type HashSet<K> = std::collections::HashSet<K>;
|
pub type HashSet<K> = std::collections::HashSet<K>;
|
||||||
|
|||||||
Reference in New Issue
Block a user