Skip to content

Commit

Permalink
Merge pull request #30 from naomijub/patch-style
Browse files Browse the repository at this point in the history
Patch Style and updates version 0.5
  • Loading branch information
tasgon authored Jul 1, 2024
2 parents 87f7eaa + af7ea2f commit 7b9f496
Show file tree
Hide file tree
Showing 9 changed files with 885 additions and 810 deletions.
1,601 changes: 839 additions & 762 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_iced"
version = "0.4.0"
version = "0.5.0"
edition = "2021"
description = "Iced integration for Bevy"
authors = ["tasgon <[email protected]>"]
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ See the [examples](https://github.com/tasgon/bevy_iced/tree/master/examples) and

|Bevy Version |Crate Version |
|--------------|---------------|
|`0.11` |`0.4`, `master`|
|`0.10` |`0.3`, |
|`0.13` |`0.5`, `master`|
|`0.11` |`0.4` |
|`0.10` |`0.3` |
|`0.9` |`0.2` |
|`0.7` |`0.1` |

Expand Down
6 changes: 3 additions & 3 deletions examples/fonts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bevy_iced::iced::{
use bevy_iced::{iced, IcedContext, IcedPlugin};

const ALPHAPROTA_FONT: Font = Font::with_name("Alpha Prota");
const ALPHAPROTA_FONT_BYTES: &'static [u8] = include_bytes!("../assets/fonts/AlphaProta.ttf");
const ALPHAPROTA_FONT_BYTES: &[u8] = include_bytes!("../assets/fonts/AlphaProta.ttf");

#[derive(Event)]
pub enum UiMessage {}
Expand All @@ -30,7 +30,7 @@ pub fn main() {

fn ui_system(mut ctx: IcedContext<UiMessage>) {
ctx.display(column!(
text(format!("I am the default font")).font(font::Font::DEFAULT),
text(format!("I am another font"))
text("I am the default font".to_string()).font(font::Font::DEFAULT),
text("I am another font".to_string())
));
}
5 changes: 2 additions & 3 deletions examples/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn main() {
}))
.add_plugins((
IcedPlugin::default(),
FrameTimeDiagnosticsPlugin::default(),
FrameTimeDiagnosticsPlugin,
LogDiagnosticsPlugin::default(),
))
.add_event::<UiMessage>()
Expand All @@ -53,7 +53,6 @@ pub fn main() {
style: Style {
text_color: iced::Color::from_rgb(0.0, 1.0, 1.0),
},
..Default::default()
})
.add_systems(Startup, build_program)
.add_systems(
Expand Down Expand Up @@ -98,7 +97,7 @@ fn box_system(
data.scale = *new_scale;
}
UiMessage::Text(s) => {
data.text = s.clone();
data.text.clone_from(s);
for mut i in &mut sprites.iter_mut() {
i.color = Color::rgba_u8(rng(), rng(), rng(), rng());
}
Expand Down
7 changes: 3 additions & 4 deletions src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ pub fn key_code(virtual_keycode: &BevyKey) -> IcedKey {
use iced_core::keyboard::key::Named;
match virtual_keycode {
BevyKey::Character(s) => IcedKey::Character(s.clone()),
BevyKey::Unidentified(_) => IcedKey::Unidentified,
BevyKey::Dead(_) => IcedKey::Unidentified,
BevyKey::Alt => IcedKey::Named(Named::Alt),
BevyKey::AltGraph => IcedKey::Named(Named::AltGraph),
BevyKey::CapsLock => IcedKey::Named(Named::CapsLock),
Expand Down Expand Up @@ -320,11 +318,12 @@ pub fn key_code(virtual_keycode: &BevyKey) -> IcedKey {
BevyKey::F33 => IcedKey::Named(Named::F33),
BevyKey::F34 => IcedKey::Named(Named::F34),
BevyKey::F35 => IcedKey::Named(Named::F35),
BevyKey::Unidentified(_) | BevyKey::Dead(_) => IcedKey::Unidentified,
_ => IcedKey::Unidentified,
}
}

pub fn mouse_button(button: MouseButton) -> iced_core::mouse::Button {
pub const fn mouse_button(button: MouseButton) -> iced_core::mouse::Button {
use iced_core::mouse::Button;
match button {
MouseButton::Left => Button::Left,
Expand All @@ -336,7 +335,7 @@ pub fn mouse_button(button: MouseButton) -> iced_core::mouse::Button {
}
}

pub fn touch_event(bevy_touch_input: &TouchInput) -> touch::Event {
pub const fn touch_event(bevy_touch_input: &TouchInput) -> touch::Event {
match *bevy_touch_input {
TouchInput {
phase: TouchPhase::Started,
Expand Down
14 changes: 5 additions & 9 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ pub const TEXTURE_FMT: TextureFormat = TextureFormat::Bgra8UnormSrgb;
#[derive(Resource, Deref, DerefMut, Clone)]
pub struct ViewportResource(pub Viewport);

pub(crate) fn update_viewport(
pub fn update_viewport(
windows: Query<&Window>,
iced_settings: Res<IcedSettings>,
mut commands: Commands,
) {
let window = windows.single();
let scale_factor = iced_settings
.scale_factor
.unwrap_or(window.scale_factor().into());
.unwrap_or_else(|| window.scale_factor().into());
let viewport = Viewport::with_physical_size(
Size::new(window.physical_width(), window.physical_height()),
scale_factor,
Expand All @@ -52,7 +52,7 @@ pub(crate) fn update_viewport(
#[derive(Resource, Deref, DerefMut)]
struct DidDrawBasic(bool);

pub(crate) fn extract_iced_data(
pub fn extract_iced_data(
mut commands: Commands,
viewport: Extract<Res<ViewportResource>>,
did_draw: Extract<Res<DidDraw>>,
Expand All @@ -77,7 +77,7 @@ impl IcedNode {

impl Node for IcedNode {
fn update(&mut self, _world: &mut World) {
self.staging_belt.lock().unwrap().recall()
self.staging_belt.lock().unwrap().recall();
}

fn run(
Expand Down Expand Up @@ -106,11 +106,7 @@ impl Node for IcedNode {
let render_queue = world.resource::<RenderQueue>();
let viewport = world.resource::<ViewportResource>();

if !world
.get_resource::<DidDrawBasic>()
.map(|x| x.0)
.unwrap_or(false)
{
if !world.get_resource::<DidDrawBasic>().is_some_and(|x| x.0) {
return Ok(());
}
let view = extracted_window.swap_chain_texture_view.as_ref().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn process_input(
event_queue.push(IcedEvent::Mouse(match ev.state {
ButtonState::Pressed => iced_core::mouse::Event::ButtonPressed(button),
ButtonState::Released => iced_core::mouse::Event::ButtonReleased(button),
}))
}));
}

for _ev in events.cursor_entered.read() {
Expand Down
53 changes: 28 additions & 25 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::IcedContext;
use bevy_math::Vec2;
use bevy_window::Window;

pub(crate) fn process_cursor_position(
pub fn process_cursor_position(
position: Vec2,
bounds: iced_core::Size,
window: &Window,
Expand All @@ -15,34 +15,37 @@ pub(crate) fn process_cursor_position(
}

/// To correctly process input as last resort events are used
pub(crate) fn process_touch_input<M: bevy_ecs::event::Event>(
pub fn process_touch_input<M: bevy_ecs::event::Event>(
context: &IcedContext<M>,
) -> Option<iced::Point> {
context
.touches
.first_pressed_position()
.or(context
.touches
.iter_just_released()
.map(|touch| touch.position())
.next())
.or_else(|| {
context
.touches
.iter_just_released()
.map(bevy_input::touch::Touch::position)
.next()
})
.map(|Vec2 { x, y }| iced::Point { x, y })
.or(context
.events
.iter()
.filter_map(|ev| {
if let iced::Event::Touch(
iced::touch::Event::FingerLifted { position, .. }
| iced::touch::Event::FingerLost { position, .. }
| iced::touch::Event::FingerMoved { position, .. }
| iced::touch::Event::FingerPressed { position, .. },
) = ev
{
Some(position)
} else {
None
}
})
.next()
.copied())
.or_else(|| {
context
.events
.iter()
.find_map(|ev| {
if let iced::Event::Touch(
iced::touch::Event::FingerLifted { position, .. }
| iced::touch::Event::FingerLost { position, .. }
| iced::touch::Event::FingerMoved { position, .. }
| iced::touch::Event::FingerPressed { position, .. },
) = ev
{
Some(position)
} else {
None
}
})
.copied()
})
}

0 comments on commit 7b9f496

Please sign in to comment.