Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,141 changes: 1,147 additions & 994 deletions Cargo.lock

Large diffs are not rendered by default.

32 changes: 15 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,22 @@ homepage = "https://github.com/tasgon/bevy_iced"
repository = "https://github.com/tasgon/bevy_iced"
documentation = "https://docs.rs/bevy_iced"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy_app = "0.13"
bevy_derive = "0.13"
bevy_ecs = "0.13"
bevy_input = "0.13"
bevy_math = "0.13"
bevy_render = "0.13"
bevy_utils = "0.13"
bevy_window = "0.13"
bevy_app = "0.15"
bevy_derive = "0.15"
bevy_ecs = "0.15"
bevy_input = "0.15"
bevy_math = "0.15"
bevy_render = "0.15"
bevy_utils = "0.15"
bevy_window = "0.15"

iced_core = "0.12"
iced_runtime = "0.12"
iced_wgpu = "0.12"
iced_widget = "0.12"
iced_renderer = { version = "0.12", features = ["wgpu"] }
iced_core = { git = "https://github.com/Azorlogh/iced", rev = "47af5890d8cf80b8bfd5909eee1ef3b1d5c05421" }
iced_runtime = { git = "https://github.com/Azorlogh/iced", rev = "47af5890d8cf80b8bfd5909eee1ef3b1d5c05421" }
iced_wgpu = { git = "https://github.com/Azorlogh/iced", rev = "47af5890d8cf80b8bfd5909eee1ef3b1d5c05421" }
iced_widget = { git = "https://github.com/Azorlogh/iced", rev = "47af5890d8cf80b8bfd5909eee1ef3b1d5c05421" }
iced_renderer = { git = "https://github.com/Azorlogh/iced", features = ["wgpu"], rev = "47af5890d8cf80b8bfd5909eee1ef3b1d5c05421" }

[dev-dependencies]
bevy = "0.13"
rand = "0.8"
bevy = "0.15"
rand = "0.8"
2 changes: 1 addition & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ pub fn main() {
fn ui_system(time: Res<Time>, mut ctx: IcedContext<UiMessage>) {
ctx.display(text(format!(
"Hello Iced! Running for {:.2} seconds.",
time.elapsed_seconds()
time.elapsed_secs()
)));
}
19 changes: 9 additions & 10 deletions examples/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ pub fn main() {
}

fn build_program(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.spawn(Camera2d::default());
}

fn tick(mut sprites: Query<&mut Sprite>, time: Res<Time>, data: Res<UiData>) {
let scale = data.scale;
for mut s in sprites.iter_mut() {
s.custom_size = Some(Vec2::new(scale, scale) * time.elapsed_seconds().sin().abs());
s.custom_size = Some(Vec2::new(scale, scale) * time.elapsed_secs().sin().abs());
}
}

Expand All @@ -83,15 +83,14 @@ fn box_system(
for msg in messages.read() {
match msg {
UiMessage::BoxRequested => {
commands.spawn(SpriteBundle {
sprite: Sprite {
color: Color::rgba_u8(rng(), rng(), rng(), rng()),
commands.spawn((
Sprite {
color: Color::srgba_u8(rng(), rng(), rng(), rng()),
custom_size: Some(Vec2::new(50.0, 50.0)),
..Default::default()
},
transform: Transform::from_translation(pos),
..Default::default()
});
Transform::from_translation(pos),
));
}
UiMessage::Scale(new_scale) => {
data.scale = *new_scale;
Expand Down Expand Up @@ -140,7 +139,7 @@ fn ui_system(

let row = Row::new()
.spacing(10)
.align_items(Alignment::Center)
.align_y(Alignment::Center)
.push(Button::new(text("Request box")).on_press(UiMessage::BoxRequested))
.push(text(format!(
"{} boxes (amplitude: {})",
Expand All @@ -149,7 +148,7 @@ fn ui_system(
)));
let edit = text_input("", &data.text).on_input(UiMessage::Text);
let column = Column::new()
.align_items(Alignment::Center)
.align_x(Alignment::Center)
.spacing(10)
.push(edit)
.push(slider(0.0..=100.0, data.scale, UiMessage::Scale))
Expand Down
230 changes: 227 additions & 3 deletions src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,237 @@ use crate::iced::{
touch::{self, Finger},
Point,
};
use bevy_input::keyboard::Key as BevyKey;
use bevy_input::keyboard::{Key as BevyKey, NativeKeyCode as BevyNativeCode};
use bevy_input::prelude::MouseButton;
use bevy_input::touch::{TouchInput, TouchPhase};
use bevy_math::Vec2;
use iced_core::keyboard::Key as IcedKey;
use iced_core::{
keyboard::{
key::{Code, Named as IcedNamed, NativeCode as IcedNativeCode, Physical},
Key as IcedKey,
},
SmolStr,
};

pub fn key_text(key: &IcedKey) -> Option<SmolStr> {
match key {
IcedKey::Named(named) => match named {
IcedNamed::Space => Some(" ".into()),
_ => None,
},
IcedKey::Character(c) => Some(c.clone()),
IcedKey::Unidentified => None,
}
}

pub fn key_code(key_code: bevy_input::keyboard::KeyCode) -> Physical {
use bevy_input::keyboard::KeyCode;
match key_code {
KeyCode::Unidentified(native_key_code) => Physical::Unidentified(match native_key_code {
BevyNativeCode::Unidentified => IcedNativeCode::Unidentified,
BevyNativeCode::Android(x) => IcedNativeCode::Android(x),
BevyNativeCode::MacOS(x) => IcedNativeCode::MacOS(x),
BevyNativeCode::Windows(x) => IcedNativeCode::Windows(x),
BevyNativeCode::Xkb(x) => IcedNativeCode::Xkb(x),
}),
KeyCode::Backquote => Physical::Code(Code::Backquote),
KeyCode::Backslash => Physical::Code(Code::Backslash),
KeyCode::BracketLeft => Physical::Code(Code::BracketLeft),
KeyCode::BracketRight => Physical::Code(Code::BracketRight),
KeyCode::Comma => Physical::Code(Code::Comma),
KeyCode::Digit0 => Physical::Code(Code::Digit0),
KeyCode::Digit1 => Physical::Code(Code::Digit1),
KeyCode::Digit2 => Physical::Code(Code::Digit2),
KeyCode::Digit3 => Physical::Code(Code::Digit3),
KeyCode::Digit4 => Physical::Code(Code::Digit4),
KeyCode::Digit5 => Physical::Code(Code::Digit5),
KeyCode::Digit6 => Physical::Code(Code::Digit6),
KeyCode::Digit7 => Physical::Code(Code::Digit7),
KeyCode::Digit8 => Physical::Code(Code::Digit8),
KeyCode::Digit9 => Physical::Code(Code::Digit9),
KeyCode::Equal => Physical::Code(Code::Equal),
KeyCode::IntlBackslash => Physical::Code(Code::IntlBackslash),
KeyCode::IntlRo => Physical::Code(Code::IntlRo),
KeyCode::IntlYen => Physical::Code(Code::IntlYen),
KeyCode::KeyA => Physical::Code(Code::KeyA),
KeyCode::KeyB => Physical::Code(Code::KeyB),
KeyCode::KeyC => Physical::Code(Code::KeyC),
KeyCode::KeyD => Physical::Code(Code::KeyD),
KeyCode::KeyE => Physical::Code(Code::KeyE),
KeyCode::KeyF => Physical::Code(Code::KeyF),
KeyCode::KeyG => Physical::Code(Code::KeyG),
KeyCode::KeyH => Physical::Code(Code::KeyH),
KeyCode::KeyI => Physical::Code(Code::KeyI),
KeyCode::KeyJ => Physical::Code(Code::KeyJ),
KeyCode::KeyK => Physical::Code(Code::KeyK),
KeyCode::KeyL => Physical::Code(Code::KeyL),
KeyCode::KeyM => Physical::Code(Code::KeyM),
KeyCode::KeyN => Physical::Code(Code::KeyN),
KeyCode::KeyO => Physical::Code(Code::KeyO),
KeyCode::KeyP => Physical::Code(Code::KeyP),
KeyCode::KeyQ => Physical::Code(Code::KeyQ),
KeyCode::KeyR => Physical::Code(Code::KeyR),
KeyCode::KeyS => Physical::Code(Code::KeyS),
KeyCode::KeyT => Physical::Code(Code::KeyT),
KeyCode::KeyU => Physical::Code(Code::KeyU),
KeyCode::KeyV => Physical::Code(Code::KeyV),
KeyCode::KeyW => Physical::Code(Code::KeyW),
KeyCode::KeyX => Physical::Code(Code::KeyX),
KeyCode::KeyY => Physical::Code(Code::KeyY),
KeyCode::KeyZ => Physical::Code(Code::KeyZ),
KeyCode::Minus => Physical::Code(Code::Minus),
KeyCode::Period => Physical::Code(Code::Period),
KeyCode::Quote => Physical::Code(Code::Quote),
KeyCode::Semicolon => Physical::Code(Code::Semicolon),
KeyCode::Slash => Physical::Code(Code::Slash),
KeyCode::AltLeft => Physical::Code(Code::AltLeft),
KeyCode::AltRight => Physical::Code(Code::AltRight),
KeyCode::Backspace => Physical::Code(Code::Backspace),
KeyCode::CapsLock => Physical::Code(Code::CapsLock),
KeyCode::ContextMenu => Physical::Code(Code::ContextMenu),
KeyCode::ControlLeft => Physical::Code(Code::ControlLeft),
KeyCode::ControlRight => Physical::Code(Code::ControlRight),
KeyCode::Enter => Physical::Code(Code::Enter),
KeyCode::SuperLeft => Physical::Code(Code::SuperLeft),
KeyCode::SuperRight => Physical::Code(Code::SuperRight),
KeyCode::ShiftLeft => Physical::Code(Code::ShiftLeft),
KeyCode::ShiftRight => Physical::Code(Code::ShiftRight),
KeyCode::Space => Physical::Code(Code::Space),
KeyCode::Tab => Physical::Code(Code::Tab),
KeyCode::Convert => Physical::Code(Code::Convert),
KeyCode::KanaMode => Physical::Code(Code::KanaMode),
KeyCode::Lang1 => Physical::Code(Code::Lang1),
KeyCode::Lang2 => Physical::Code(Code::Lang2),
KeyCode::Lang3 => Physical::Code(Code::Lang3),
KeyCode::Lang4 => Physical::Code(Code::Lang4),
KeyCode::Lang5 => Physical::Code(Code::Lang5),
KeyCode::NonConvert => Physical::Code(Code::NonConvert),
KeyCode::Delete => Physical::Code(Code::Delete),
KeyCode::End => Physical::Code(Code::End),
KeyCode::Help => Physical::Code(Code::Help),
KeyCode::Home => Physical::Code(Code::Home),
KeyCode::Insert => Physical::Code(Code::Insert),
KeyCode::PageDown => Physical::Code(Code::PageDown),
KeyCode::PageUp => Physical::Code(Code::PageUp),
KeyCode::ArrowDown => Physical::Code(Code::ArrowDown),
KeyCode::ArrowLeft => Physical::Code(Code::ArrowLeft),
KeyCode::ArrowRight => Physical::Code(Code::ArrowRight),
KeyCode::ArrowUp => Physical::Code(Code::ArrowUp),
KeyCode::NumLock => Physical::Code(Code::NumLock),
KeyCode::Numpad0 => Physical::Code(Code::Numpad0),
KeyCode::Numpad1 => Physical::Code(Code::Numpad1),
KeyCode::Numpad2 => Physical::Code(Code::Numpad2),
KeyCode::Numpad3 => Physical::Code(Code::Numpad3),
KeyCode::Numpad4 => Physical::Code(Code::Numpad4),
KeyCode::Numpad5 => Physical::Code(Code::Numpad5),
KeyCode::Numpad6 => Physical::Code(Code::Numpad6),
KeyCode::Numpad7 => Physical::Code(Code::Numpad7),
KeyCode::Numpad8 => Physical::Code(Code::Numpad8),
KeyCode::Numpad9 => Physical::Code(Code::Numpad9),
KeyCode::NumpadAdd => Physical::Code(Code::NumpadAdd),
KeyCode::NumpadBackspace => Physical::Code(Code::NumpadBackspace),
KeyCode::NumpadClear => Physical::Code(Code::NumpadClear),
KeyCode::NumpadClearEntry => Physical::Code(Code::NumpadClearEntry),
KeyCode::NumpadComma => Physical::Code(Code::NumpadComma),
KeyCode::NumpadDecimal => Physical::Code(Code::NumpadDecimal),
KeyCode::NumpadDivide => Physical::Code(Code::NumpadDivide),
KeyCode::NumpadEnter => Physical::Code(Code::NumpadEnter),
KeyCode::NumpadEqual => Physical::Code(Code::NumpadEqual),
KeyCode::NumpadHash => Physical::Code(Code::NumpadHash),
KeyCode::NumpadMemoryAdd => Physical::Code(Code::NumpadMemoryAdd),
KeyCode::NumpadMemoryClear => Physical::Code(Code::NumpadMemoryClear),
KeyCode::NumpadMemoryRecall => Physical::Code(Code::NumpadMemoryRecall),
KeyCode::NumpadMemoryStore => Physical::Code(Code::NumpadMemoryStore),
KeyCode::NumpadMemorySubtract => Physical::Code(Code::NumpadMemorySubtract),
KeyCode::NumpadMultiply => Physical::Code(Code::NumpadMultiply),
KeyCode::NumpadParenLeft => Physical::Code(Code::NumpadParenLeft),
KeyCode::NumpadParenRight => Physical::Code(Code::NumpadParenRight),
KeyCode::NumpadStar => Physical::Code(Code::NumpadStar),
KeyCode::NumpadSubtract => Physical::Code(Code::NumpadSubtract),
KeyCode::Escape => Physical::Code(Code::Escape),
KeyCode::Fn => Physical::Code(Code::Fn),
KeyCode::FnLock => Physical::Code(Code::FnLock),
KeyCode::PrintScreen => Physical::Code(Code::PrintScreen),
KeyCode::ScrollLock => Physical::Code(Code::ScrollLock),
KeyCode::Pause => Physical::Code(Code::Pause),
KeyCode::BrowserBack => Physical::Code(Code::BrowserBack),
KeyCode::BrowserFavorites => Physical::Code(Code::BrowserFavorites),
KeyCode::BrowserForward => Physical::Code(Code::BrowserForward),
KeyCode::BrowserHome => Physical::Code(Code::BrowserHome),
KeyCode::BrowserRefresh => Physical::Code(Code::BrowserRefresh),
KeyCode::BrowserSearch => Physical::Code(Code::BrowserSearch),
KeyCode::BrowserStop => Physical::Code(Code::BrowserStop),
KeyCode::Eject => Physical::Code(Code::Eject),
KeyCode::LaunchApp1 => Physical::Code(Code::LaunchApp1),
KeyCode::LaunchApp2 => Physical::Code(Code::LaunchApp2),
KeyCode::LaunchMail => Physical::Code(Code::LaunchMail),
KeyCode::MediaPlayPause => Physical::Code(Code::MediaPlayPause),
KeyCode::MediaSelect => Physical::Code(Code::MediaSelect),
KeyCode::MediaStop => Physical::Code(Code::MediaStop),
KeyCode::MediaTrackNext => Physical::Code(Code::MediaTrackNext),
KeyCode::MediaTrackPrevious => Physical::Code(Code::MediaTrackPrevious),
KeyCode::Power => Physical::Code(Code::Power),
KeyCode::Sleep => Physical::Code(Code::Sleep),
KeyCode::AudioVolumeDown => Physical::Code(Code::AudioVolumeDown),
KeyCode::AudioVolumeMute => Physical::Code(Code::AudioVolumeMute),
KeyCode::AudioVolumeUp => Physical::Code(Code::AudioVolumeUp),
KeyCode::WakeUp => Physical::Code(Code::WakeUp),
KeyCode::Meta => Physical::Code(Code::Meta),
KeyCode::Hyper => Physical::Code(Code::Hyper),
KeyCode::Turbo => Physical::Code(Code::Turbo),
KeyCode::Abort => Physical::Code(Code::Abort),
KeyCode::Resume => Physical::Code(Code::Resume),
KeyCode::Suspend => Physical::Code(Code::Suspend),
KeyCode::Again => Physical::Code(Code::Again),
KeyCode::Copy => Physical::Code(Code::Copy),
KeyCode::Cut => Physical::Code(Code::Cut),
KeyCode::Find => Physical::Code(Code::Find),
KeyCode::Open => Physical::Code(Code::Open),
KeyCode::Paste => Physical::Code(Code::Paste),
KeyCode::Props => Physical::Code(Code::Props),
KeyCode::Select => Physical::Code(Code::Select),
KeyCode::Undo => Physical::Code(Code::Undo),
KeyCode::Hiragana => Physical::Code(Code::Hiragana),
KeyCode::Katakana => Physical::Code(Code::Katakana),
KeyCode::F1 => Physical::Code(Code::F1),
KeyCode::F2 => Physical::Code(Code::F2),
KeyCode::F3 => Physical::Code(Code::F3),
KeyCode::F4 => Physical::Code(Code::F4),
KeyCode::F5 => Physical::Code(Code::F5),
KeyCode::F6 => Physical::Code(Code::F6),
KeyCode::F7 => Physical::Code(Code::F7),
KeyCode::F8 => Physical::Code(Code::F8),
KeyCode::F9 => Physical::Code(Code::F9),
KeyCode::F10 => Physical::Code(Code::F10),
KeyCode::F11 => Physical::Code(Code::F11),
KeyCode::F12 => Physical::Code(Code::F12),
KeyCode::F13 => Physical::Code(Code::F13),
KeyCode::F14 => Physical::Code(Code::F14),
KeyCode::F15 => Physical::Code(Code::F15),
KeyCode::F16 => Physical::Code(Code::F16),
KeyCode::F17 => Physical::Code(Code::F17),
KeyCode::F18 => Physical::Code(Code::F18),
KeyCode::F19 => Physical::Code(Code::F19),
KeyCode::F20 => Physical::Code(Code::F20),
KeyCode::F21 => Physical::Code(Code::F21),
KeyCode::F22 => Physical::Code(Code::F22),
KeyCode::F23 => Physical::Code(Code::F23),
KeyCode::F24 => Physical::Code(Code::F24),
KeyCode::F25 => Physical::Code(Code::F25),
KeyCode::F26 => Physical::Code(Code::F26),
KeyCode::F27 => Physical::Code(Code::F27),
KeyCode::F28 => Physical::Code(Code::F28),
KeyCode::F29 => Physical::Code(Code::F29),
KeyCode::F30 => Physical::Code(Code::F30),
KeyCode::F31 => Physical::Code(Code::F31),
KeyCode::F32 => Physical::Code(Code::F32),
KeyCode::F33 => Physical::Code(Code::F33),
KeyCode::F34 => Physical::Code(Code::F34),
KeyCode::F35 => Physical::Code(Code::F35),
}
}

pub fn key_code(virtual_keycode: &BevyKey) -> IcedKey {
pub fn key(virtual_keycode: &BevyKey) -> IcedKey {
use iced_core::keyboard::key::Named;
match virtual_keycode {
BevyKey::Character(s) => IcedKey::Character(s.clone()),
Expand Down
11 changes: 3 additions & 8 deletions src/iced.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
// Largely taken from https://github.com/iced-rs/iced/blob/0.10/src/lib.rs

use iced_widget::renderer;
use iced_widget::style;

pub use style::theme;

pub use iced_core::alignment;
pub use iced_core::border;
pub use iced_core::event;
pub use iced_core::gradient;
pub use iced_core::{
color, Alignment, Background, Border, Color, ContentFit, Degrees, Gradient, Length, Padding,
Pixels, Point, Radians, Rectangle, Size, Vector,
Pixels, Point, Radians, Rectangle, Size, Theme, Vector,
};
pub use iced_runtime::Command;

pub mod clipboard {
//! Access the clipboard.
Expand Down Expand Up @@ -44,7 +40,7 @@ pub mod overlay {
/// This is an alias of an `iced_native` element with a default `Renderer`.
///
/// [`Overlay`]: iced_native::Overlay
pub type Element<'a, Message, Theme = super::theme::Theme, Renderer = crate::Renderer> =
pub type Element<'a, Message, Theme = iced_core::Theme, Renderer = crate::Renderer> =
iced_core::overlay::Element<'a, Message, Theme, Renderer>;

pub use iced_widget::overlay::*;
Expand All @@ -71,15 +67,14 @@ pub mod widget {

pub use event::Event;
pub use font::Font;
pub use theme::Theme;

/// The default renderer.
pub type Renderer = renderer::Renderer;

/// A generic widget.
///
/// This is an alias of an `iced_native` element with a default `Renderer`.
pub type Element<'a, Message, Theme = theme::Theme, Renderer = crate::Renderer> =
pub type Element<'a, Message, Theme = iced_core::Theme, Renderer = crate::Renderer> =
iced_core::Element<'a, Message, Theme, Renderer>;

pub use iced_core::renderer::Style;
Expand Down
Loading