remove context from ui (again) and create weird trait for it
This commit is contained in:
1 parent
26c248dcba
commit
719bee4b31
12 files changed
+107
-92
No files matched your search
@@ -9,7 +9,7 @@ pub struct Input {
|
||||
}
|
||||
|
||||
impl Input {
|
||||
pub fn event(&mut self, event: &WindowEvent) {
|
||||
pub fn event(&mut self, event: &WindowEvent) -> bool {
|
||||
match event {
|
||||
WindowEvent::CursorMoved { position, .. } => {
|
||||
self.cursor.pos = Vec2::new(position.x as f32, position.y as f32);
|
||||
@@ -28,8 +28,9 @@ impl Input {
|
||||
WindowEvent::CursorLeft { .. } => {
|
||||
self.cursor.exists = false;
|
||||
}
|
||||
_ => (),
|
||||
_ => return false,
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
pub fn end_frame(&mut self) {
|
||||
|
||||
+9
-6
@@ -19,7 +19,7 @@ pub fn main() {
|
||||
pub struct Client {
|
||||
renderer: Renderer,
|
||||
input: Input,
|
||||
ui: Ui<Client>,
|
||||
ui: Ui,
|
||||
info: WidgetId<Text>,
|
||||
focus: Option<WidgetId<TextEdit>>,
|
||||
}
|
||||
@@ -155,7 +155,8 @@ impl Client {
|
||||
|
||||
let switch_button = |color, to, label| {
|
||||
let rect = rect(color)
|
||||
.id_on(Sense::click(), move |id, ctx: &mut Client, _| {
|
||||
.ctx::<Client>()
|
||||
.id_on(Sense::click(), move |id, ctx, _| {
|
||||
ctx.ui[main].inner.set_static(to);
|
||||
ctx.ui[id].color = color.darker(0.3);
|
||||
})
|
||||
@@ -201,16 +202,18 @@ impl Client {
|
||||
}
|
||||
|
||||
pub fn event(&mut self, event: WindowEvent, event_loop: &ActiveEventLoop) {
|
||||
self.input.event(&event);
|
||||
let input_changed = self.input.event(&event);
|
||||
let cursor_state = self.cursor_state().clone();
|
||||
let window_size = self.window_size();
|
||||
if let Some(focus) = &self.focus
|
||||
&& cursor_state.buttons.left.is_start()
|
||||
{
|
||||
self.ui.text(focus).deselect();
|
||||
self.focus = None;
|
||||
}
|
||||
run_sensors(self, &cursor_state, window_size);
|
||||
if input_changed {
|
||||
let window_size = self.window_size();
|
||||
run_sensors(self, &cursor_state, window_size);
|
||||
}
|
||||
match event {
|
||||
WindowEvent::CloseRequested => event_loop.exit(),
|
||||
WindowEvent::RedrawRequested => {
|
||||
@@ -249,7 +252,7 @@ impl Client {
|
||||
}
|
||||
|
||||
impl UiCtx for Client {
|
||||
fn ui(&mut self) -> &mut Ui<Self> {
|
||||
fn ui(&mut self) -> &mut Ui {
|
||||
&mut self.ui
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ pub struct Renderer {
|
||||
}
|
||||
|
||||
impl Renderer {
|
||||
pub fn update<Ctx>(&mut self, updates: &mut Ui<Ctx>) {
|
||||
pub fn update(&mut self, updates: &mut Ui) {
|
||||
self.ui.update(&self.device, &self.queue, updates);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user