sense specific buttons

This commit is contained in:
2025-09-15 22:22:52 -04:00
parent 21aa2b3501
commit b48acccb8d
8 changed files with 167 additions and 107 deletions

View File

@@ -3,7 +3,6 @@ use std::sync::Arc;
use app::App;
use cosmic_text::Family;
use render::Renderer;
use senses::*;
use ui::prelude::*;
use winit::{event::WindowEvent, event_loop::ActiveEventLoop, window::Window};
@@ -73,7 +72,7 @@ impl Client {
let add_button = rect(Color::LIME)
.radius(30)
.on(PRESS_START, move |ctx: &mut Client, _| {
.on(Sense::click(), move |ctx: &mut Client, _| {
let child = ctx
.ui
.add(image(include_bytes!("assets/sungals.png")).center())
@@ -85,7 +84,7 @@ impl Client {
let del_button = rect(Color::RED)
.radius(30)
.on(PRESS_START, move |ctx: &mut Client, _| {
.on(Sense::click(), move |ctx: &mut Client, _| {
ctx.ui[span_add].children.pop();
})
.size(150)
@@ -124,7 +123,7 @@ impl Client {
texts,
text_edit("add")
.font_size(30)
.id_on(PRESS_START, |id, client: &mut Client, ctx| {
.id_on(Sense::click(), |id, client: &mut Client, ctx| {
client.ui.text(id).select(ctx.cursor, ctx.size);
client.selected = Some(id.clone());
})
@@ -135,14 +134,14 @@ impl Client {
let switch_button = |color, to, label| {
let rect = rect(color)
.id_on(PRESS_START, move |id, ctx: &mut Client, _| {
.id_on(Sense::click(), move |id, ctx: &mut Client, _| {
ctx.ui[main].inner.set_static(to);
ctx.ui[id].color = color.add_rgb(-0.2);
})
.edit_on(HOVER_START | PRESS_END, move |r, _| {
.edit_on(Sense::HoverStart | Sense::unclick(), move |r, _| {
r.color = color.add_rgb(0.4);
})
.edit_on(HOVER_END, move |r, _| {
.edit_on(Sense::HoverEnd, move |r, _| {
r.color = color;
});
(rect, text(label).font_size(30)).stack()
@@ -185,7 +184,7 @@ impl Client {
pub fn event(&mut self, event: WindowEvent, event_loop: &ActiveEventLoop) {
self.input.event(&event);
let cursor_state = self.cursor_state();
let cursor_state = self.cursor_state().clone();
let window_size = self.window_size();
run_sensors(self, &cursor_state, window_size);
match event {
@@ -221,6 +220,7 @@ impl Client {
if self.ui.needs_redraw() {
self.renderer.window().request_redraw();
}
self.input.end_frame();
}
}