Skip to content

Commit e9c8570

Browse files
committed
check
1 parent 9eabeb8 commit e9c8570

File tree

11 files changed

+162
-211
lines changed

11 files changed

+162
-211
lines changed

Cargo.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ paste = { version = "1.0", optional = true }
5050
document-features = { version = "0.2", optional = true }
5151
# aalo = { path = "../aalo", version = "0.0", optional = true }
5252

53-
# TODO: use MoonZoon's futures-signals/futures-util extensions directly when it is published as a crate
54-
haalka_futures_signals_ext = { version = "0.0.3", path = "MoonZoon/crates/futures_signals_ext", optional = false }
53+
haalka_futures_signals_ext = { version = "0.0.3", path = "MoonZoon/crates/futures_signals_ext", optional = true }
5554

5655
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
5756
async-io = { version = "2.4", optional = true }
@@ -213,11 +212,14 @@ name = "dragging"
213212
path = "examples/dragging.rs"
214213
doc-scrape-examples = true
215214

215+
[[example]]
216+
name = "futures_signals_jonmo_compat"
217+
path = "examples/futures_signals_jonmo_compat.rs"
218+
required-features = ["futures_signals_ui"]
219+
doc-scrape-examples = true
220+
216221
[[example]]
217222
name = "utils"
218223
path = "examples/utils.rs"
219224
doc-scrape-examples = true
220225
crate-type = ["lib"]
221-
222-
[patch.crates-io]
223-
jonmo = { path = "../jonmo" }

examples/align.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn alignment_button<R: Resource + Clone + Deref<Target = bool> + DerefMut>(label
9595
.map_in(Some)
9696
})
9797
.align_content(Align::center())
98-
.on_click(|_: In<_>, mut enabled: ResMut<R>| {
98+
.on_click(|In(_), mut enabled: ResMut<R>| {
9999
**enabled = !**enabled;
100100
})
101101
.child(

examples/calculator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn clear_button() -> impl Element {
146146
.map_in(Some),
147147
)
148148
.cursor_disableable_signal(CursorIcon::System(SystemCursorIcon::Pointer), output_empty)
149-
.on_click(|_: In<_>, mut output: ResMut<Output>| output.0.clear())
149+
.on_click(|In(_), mut output: ResMut<Output>| output.0.clear())
150150
}
151151

152152
fn ui_root() -> impl Element {

examples/futures_signals_jonmo_compat.rs

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
//! Demonstrates that both futures-signals and jonmo signals backends can be used together.
2-
//!
3-
//! This example shows two buttons side by side:
4-
//! - Left button uses the deprecated futures-signals backend (existing code)
5-
//! - Right button uses the new jonmo-based backend (code being migrated to)
6-
//!
7-
//! The UI root uses futures-signals, showing how users can incrementally migrate
8-
//! from futures-signals to jonmo while keeping both working in tandem.
9-
//!
10-
//! Run with: `cargo run --example futures_signals_jonmo_compat --features futures_signals_ui`
112
123
mod utils;
134
use utils::*;
@@ -18,8 +9,8 @@ use bevy::{prelude::*, ui::Pressed};
189
use haalka::{
1910
futures_signals::prelude::*,
2011
prelude::{
21-
Align as jAlign, Alignable as _, BuilderPassThrough, BuilderWrapper, Column as jColumn, Draggable, Dragged,
22-
El as jEl, Element as jElement, Hoverable, Hovered, LazyEntity, Pressable, SignalExt as _, signal,
12+
Align as jAlign, Alignable as _, BuilderPassThrough, BuilderWrapper, Draggable, El as jEl,
13+
Element as jElement, Hoverable, Hovered, LazyEntity, Pressable, SignalExt as _, signal,
2314
},
2415
};
2516

@@ -56,7 +47,6 @@ fn futures_signals_button() -> impl Element {
5647
node.height = Val::Px(65.);
5748
node.border = UiRect::all(Val::Px(5.0));
5849
})
59-
.cursor(CursorIcon::System(SystemCursorIcon::Pointer))
6050
.align_content(Align::center())
6151
.border_color_signal(
6252
pressed_hovered
@@ -95,17 +85,18 @@ fn futures_signals_button() -> impl Element {
9585
font_size: 25.0,
9686
..default()
9787
})
88+
.text_shadow(TextShadow::default())
9889
.text_color(TextColor(Color::srgb(0.9, 0.9, 0.9)))
9990
.text_signal(
10091
pressed_hovered
10192
.signal()
10293
.map(|(pressed, hovered)| {
10394
if pressed {
104-
"FS Press"
95+
"Press"
10596
} else if hovered {
106-
"FS Hover"
97+
"Hover"
10798
} else {
108-
"FuturesSignals"
99+
"futures-signals"
109100
}
110101
})
111102
.map(Text::new),
@@ -119,29 +110,27 @@ fn jonmo_button() -> impl jElement {
119110
let pressed = signal::from_entity(lazy_entity.clone())
120111
.has_component::<Pressed>()
121112
.dedupe();
122-
let dragged = jonmo::signal::from_entity(lazy_entity.clone())
123-
.has_component::<Dragged>()
124-
.dedupe();
125-
let hovered = jonmo::signal::from_entity(lazy_entity.clone())
113+
let hovered = signal::from_entity(lazy_entity.clone())
126114
.has_component::<Hovered>()
127115
.dedupe();
128-
let pressed_hovered = jonmo::signal::zip!(jonmo::signal::any!(pressed, dragged), hovered).dedupe();
116+
let pressed_hovered = signal::zip!(pressed, hovered).dedupe();
129117

130118
jEl::<Node>::new()
131119
.with_node(|mut node| {
132120
node.width = Val::Px(150.0);
133121
node.height = Val::Px(65.);
134122
node.border = UiRect::all(Val::Px(5.0));
135123
})
136-
.insert((Pickable::default(), Hoverable, Pressable, Draggable, BorderRadius::MAX))
124+
.insert((Pickable::default(), Hoverable, Pressable, Draggable))
137125
.align_content(jAlign::center())
126+
.border_radius(BorderRadius::MAX)
138127
.lazy_entity(lazy_entity)
139128
.border_color_signal(
140129
pressed_hovered
141130
.clone()
142131
.map_in(|(pressed, hovered)| {
143132
if pressed {
144-
bevy::color::palettes::basic::BLUE.into()
133+
bevy::color::palettes::basic::RED.into()
145134
} else if hovered {
146135
Color::WHITE
147136
} else {
@@ -169,19 +158,20 @@ fn jonmo_button() -> impl jElement {
169158
.child(
170159
jEl::<Text>::new()
171160
.text_font(TextFont {
172-
font_size: 25.0,
161+
font_size: 33.0,
173162
..default()
174163
})
164+
.text_shadow(TextShadow::default())
175165
.text_color(TextColor(Color::srgb(0.9, 0.9, 0.9)))
176166
.text_signal(
177167
pressed_hovered
178168
.map_in(|(pressed, hovered)| {
179169
if pressed {
180-
"Jonmo Press"
170+
"Press"
181171
} else if hovered {
182-
"Jonmo Hover"
172+
"Hover"
183173
} else {
184-
"Jonmo"
174+
"jonmo"
185175
}
186176
})
187177
.map_in(Text::new)
@@ -208,28 +198,11 @@ fn ui_root() -> impl Element {
208198
.with_node(|mut node| {
209199
node.column_gap = Val::Px(50.);
210200
})
211-
.item(
212-
Column::<Node>::new()
213-
.with_node(|mut node| {
214-
node.row_gap = Val::Px(10.);
215-
})
216-
.align(Align::center())
217-
.item(El::<Text>::new().text(Text::new("futures-signals\n(deprecated)")))
218-
.item(futures_signals_button()),
219-
)
220-
.item(
221-
Column::<Node>::new()
222-
.with_node(|mut node| {
223-
node.row_gap = Val::Px(10.);
224-
})
225-
.align(Align::center())
226-
.item(El::<Text>::new().text(Text::new("jonmo\n(recommended)")))
227-
.item(El::<Node>::new().update_raw_el(|raw_el| {
228-
raw_el.on_spawn(|world, entity| {
229-
// use jonmo_compat::JonmoBW as _;
230-
let _ = jonmo_button().into_builder().spawn_on_entity(world, entity);
231-
})
232-
})),
233-
),
201+
.item(futures_signals_button())
202+
.item(El::<Node>::new().update_raw_el(|raw_el| {
203+
raw_el.on_spawn(|world, entity| {
204+
jonmo_button().into_builder().spawn_on_entity(world, entity).unwrap();
205+
})
206+
})),
234207
)
235208
}

examples/healthbar.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,8 @@ fn sync_tracking_healthbar_position(
144144
}
145145

146146
fn health_signal() -> impl Signal<Item = u32> + Clone + Send + Sync + 'static {
147-
signal::from_system(|In(_): In<()>, health: Option<Single<&Health>>| {
148-
health.map(deref_copied).map(|health| health.0)
149-
})
150-
.dedupe()
147+
signal::from_system(|In(_), health: Option<Single<&Health>>| health.map(deref_copied).map(|health| health.0))
148+
.dedupe()
151149
}
152150

153151
fn healthbar(max: u32, height: f32, color_gradient: impl Gradient + Send + Sync + 'static) -> Stack<Node> {

examples/inventory.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ struct PressHandlingDisabled;
281281
struct TooltipOrigin(Option<Vec2>);
282282

283283
fn is_dragging() -> impl Signal<Item = bool> + Clone {
284-
signal::from_system(|_: In<()>, dragging: Option<Res<Dragging>>| dragging.is_some()).dedupe()
284+
signal::from_system(|In(_), dragging: Option<Res<Dragging>>| dragging.is_some()).dedupe()
285285
}
286286

287287
fn pointer_position_signal() -> impl Signal<Item = Vec2> + Clone {
@@ -644,7 +644,7 @@ fn arrow() -> impl Element {
644644

645645
fn craft_output_cell() -> impl Element {
646646
let output_action = signal::from_system(
647-
|_: In<()>,
647+
|In(_),
648648
mut prev_filled: Local<Option<bool>>,
649649
changed: Query<(), (With<CraftInputCell>, Changed<CellContent>)>,
650650
input_cells: Query<&CellContent, With<CraftInputCell>>,
@@ -690,7 +690,7 @@ fn craft_output_cell() -> impl Element {
690690
)
691691
.task();
692692
let output_empty =
693-
signal::from_system(|_: In<()>, output: Single<&CellContent, With<CraftOutputSlot>>| output.is_none()).dedupe();
693+
signal::from_system(|In(_), output: Single<&CellContent, With<CraftOutputSlot>>| output.is_none()).dedupe();
694694
let press_disabled = signal::any!(is_dragging(), output_empty.clone()).dedupe();
695695
cell(false)
696696
.insert(CraftOutputSlot)
@@ -855,11 +855,11 @@ fn ui_root() -> impl Element {
855855
.layer(inventory())
856856
// dragging icon
857857
.layer_signal(is_dragging().dedupe().map_true_in(move || {
858-
let index = signal::from_system(|_: In<()>, dragging: Option<Res<Dragging>>| {
858+
let index = signal::from_system(|In(_), dragging: Option<Res<Dragging>>| {
859859
dragging.map(|d| d.item.index).unwrap_or(0)
860860
})
861861
.dedupe();
862-
let count = signal::from_system(|_: In<()>, dragging: Option<Res<Dragging>>| {
862+
let count = signal::from_system(|In(_), dragging: Option<Res<Dragging>>| {
863863
dragging.map(|d| d.item.count).unwrap_or(0)
864864
})
865865
.dedupe();

0 commit comments

Comments
 (0)