remove context from ui (again) and create weird trait for it

This commit is contained in:
2025-09-24 17:41:25 -04:00
parent 26c248dcba
commit 719bee4b31
12 changed files with 107 additions and 92 deletions

View File

@@ -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
}
}