Skip to content

Commit

Permalink
Update wgpu & iced (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex authored Feb 7, 2024
1 parent 6dc2e9e commit d39e27a
Show file tree
Hide file tree
Showing 24 changed files with 1,026 additions and 894 deletions.
974 changes: 412 additions & 562 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ default-members = ["neothesia"]
resolver = "2"

[workspace.dependencies]
wgpu = "0.18"
glyphon = { git = "https://github.com/grovesNL/glyphon.git", rev = "2caa9fc5e5923c1d827d177c3619cab7e9885b85" }
wgpu = "0.19"
glyphon = "0.5"
log = "0.4"
bytemuck = { version = "1.5", features = ["derive"] }
env_logger = "0.10"
Expand Down
12 changes: 6 additions & 6 deletions neothesia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ oxisynth = { version = "0.0.5", optional = true }
midi-file = { workspace = true }
midi-io = { path = "../midi-io" }

iced_style = {git = "https://github.com/iced-rs/iced.git", rev="fc285d3e461626408c56bbc1605fcf0c974b2f69"}
iced_graphics = {git = "https://github.com/iced-rs/iced.git", rev="fc285d3e461626408c56bbc1605fcf0c974b2f69"}
iced_core = {git = "https://github.com/iced-rs/iced.git", rev="fc285d3e461626408c56bbc1605fcf0c974b2f69"}
iced_runtime = {git = "https://github.com/iced-rs/iced.git", rev="fc285d3e461626408c56bbc1605fcf0c974b2f69"}
iced_wgpu = { git = "https://github.com/iced-rs/iced.git", rev="fc285d3e461626408c56bbc1605fcf0c974b2f69", features = ["image"] }
iced_widget = { git = "https://github.com/iced-rs/iced.git", rev="fc285d3e461626408c56bbc1605fcf0c974b2f69", features = ["image"] }
iced_style = {git = "https://github.com/iced-rs/iced.git", rev="b4dcf4ecf702a493476791efd95e190e5c1db812"}
iced_graphics = {git = "https://github.com/iced-rs/iced.git", rev="b4dcf4ecf702a493476791efd95e190e5c1db812"}
iced_core = {git = "https://github.com/iced-rs/iced.git", rev="b4dcf4ecf702a493476791efd95e190e5c1db812"}
iced_runtime = {git = "https://github.com/iced-rs/iced.git", rev="b4dcf4ecf702a493476791efd95e190e5c1db812"}
iced_wgpu = { git = "https://github.com/iced-rs/iced.git", rev="b4dcf4ecf702a493476791efd95e190e5c1db812", features = ["image"] }
iced_widget = { git = "https://github.com/iced-rs/iced.git", rev="b4dcf4ecf702a493476791efd95e190e5c1db812", features = ["image"] }

[[bin]]
name = "neothesia"
Expand Down
467 changes: 337 additions & 130 deletions neothesia/src/iced_utils/iced_conversion.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion neothesia/src/iced_utils/iced_manager.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use iced_core::text::Renderer;

pub struct IcedManager {
pub renderer: iced_wgpu::Renderer<iced_style::Theme>,
pub renderer: iced_wgpu::Renderer,
pub viewport: iced_wgpu::graphics::Viewport,
pub debug: iced_runtime::Debug,
}
Expand Down
4 changes: 2 additions & 2 deletions neothesia/src/iced_utils/iced_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use iced_style::Theme;
use super::{iced_clipboard::DummyClipboard, iced_conversion};
use crate::target::Target;

pub type Element<'a, M> = iced_core::Element<'a, M, iced_wgpu::Renderer<Theme>>;
pub type Element<'a, M> = iced_core::Element<'a, M, Theme, iced_wgpu::Renderer>;

/// The core of a user interface application following The Elm Architecture.
pub trait Program: Sized {
Expand Down Expand Up @@ -197,7 +197,7 @@ fn build_user_interface<'a, P: Program>(
cache: user_interface::Cache,
size: Size,
target: &mut Target,
) -> UserInterface<'a, P::Message, iced_wgpu::Renderer<Theme>> {
) -> UserInterface<'a, P::Message, Theme, iced_wgpu::Renderer> {
let view = program.view(target);
UserInterface::build(view, size, cache, &mut target.iced_manager.renderer)
}
1 change: 0 additions & 1 deletion neothesia/src/iced_utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod iced_clipboard;
mod iced_manager;

pub use iced_clipboard::DummyClipboard;
pub use iced_manager::IcedManager;

pub mod iced_conversion;
Expand Down
47 changes: 28 additions & 19 deletions neothesia/src/scene/menu_scene/iced_menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use iced_core::{
Alignment, Length, Padding,
};
use iced_runtime::Command;
use iced_style::Theme;
use iced_widget::{column as col, container, image, row, text, vertical_space};

use crate::{
Expand Down Expand Up @@ -160,7 +161,7 @@ impl Program for AppUi {
}

fn mouse_input(&self, event: &iced_core::mouse::Event, _target: &Target) -> Option<Message> {
if let iced_core::mouse::Event::ButtonPressed(iced_core::mouse::Button::Other(99)) = event {
if let iced_core::mouse::Event::ButtonPressed(iced_core::mouse::Button::Back) = event {
Some(Message::GoToPage(self.current.previous_step()))
} else {
None
Expand All @@ -172,34 +173,42 @@ impl Program for AppUi {
event: &iced_runtime::keyboard::Event,
_target: &Target,
) -> Option<Message> {
use iced_runtime::keyboard::{Event, KeyCode};

if let Event::KeyPressed { key_code, .. } = event {
match key_code {
KeyCode::Tab => match self.current {
use iced_runtime::keyboard::{key::Named, Event, Key};

match event {
Event::KeyPressed {
key: Key::Named(key),
..
} => match key {
Named::Tab => match self.current {
Step::Main => Some(midi_file_picker::open().into()),
Step::Settings => Some(Message::Settings(SettingsMessage::OpenSoundFontPicker)),
_ => None,
},
KeyCode::S => match self.current {
Step::Main => Some(Message::GoToPage(Step::Settings)),
_ => None,
},
KeyCode::Enter => match self.current {
Named::Enter => match self.current {
Step::Exit => Some(Message::ExitApp),
Step::Main => Some(Message::Play),
Step::TrackSelection => Some(Message::Play),
_ => None,
},
KeyCode::T => match self.current {
Named::Escape => Some(Message::GoToPage(self.current.previous_step())),
_ => None,
},
Event::KeyPressed {
key: Key::Character(ch),
..
} => match ch.as_ref() {
"s" => match self.current {
Step::Main => Some(Message::GoToPage(Step::Settings)),
_ => None,
},
"t" => match self.current {
Step::Main => Some(Message::GoToPage(Step::TrackSelection)),
_ => None,
},
KeyCode::Escape => Some(Message::GoToPage(self.current.previous_step())),
_ => None,
}
} else {
None
},
_ => None,
}
}

Expand Down Expand Up @@ -322,15 +331,15 @@ impl<'a> Step {
}
}

fn centered_text<'a>(label: impl ToString) -> iced_widget::Text<'a, Renderer> {
fn centered_text<'a>(label: impl ToString) -> iced_widget::Text<'a, Theme, Renderer> {
text(label)
.horizontal_alignment(Horizontal::Center)
.vertical_alignment(Vertical::Center)
}

fn top_padded<'a, MSG: 'a>(
content: impl Into<Element<'a, MSG>>,
) -> iced_widget::Column<'a, MSG, Renderer> {
) -> iced_widget::Column<'a, MSG, Theme, Renderer> {
let spacer = vertical_space(Length::FillPortion(1));
let content = container(content)
.height(Length::FillPortion(4))
Expand All @@ -345,7 +354,7 @@ fn top_padded<'a, MSG: 'a>(

fn center_x<'a, MSG: 'a>(
content: impl Into<Element<'a, MSG>>,
) -> iced_widget::Container<'a, MSG, Renderer> {
) -> iced_widget::Container<'a, MSG, Theme, Renderer> {
container(content)
.width(Length::Fill)
.height(Length::Fill)
Expand Down
54 changes: 38 additions & 16 deletions neothesia/src/scene/menu_scene/iced_menu/theme.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::rc::Rc;

use iced_core::BorderRadius;
use iced_core::border::{Border, Radius};
use iced_graphics::core::Color;
use iced_style::{button, pick_list};

Expand All @@ -24,9 +24,11 @@ impl iced_style::pick_list::StyleSheet for PickListStyle {
text_color: Color::WHITE,
background: iced_core::Background::Color(Color::from_rgba8(74, 68, 88, 1.0)),
placeholder_color: Color::WHITE,
border_radius: iced_core::BorderRadius::from(5.0),
border_width: 0.0,
border_color: SURFACE,
border: Border {
radius: Radius::from(5.0),
width: 0.0,
color: SURFACE,
},
handle_color: Color::WHITE,
}
}
Expand Down Expand Up @@ -54,9 +56,11 @@ impl iced_style::menu::StyleSheet for MenuStyle {
iced_style::menu::Appearance {
text_color: Color::WHITE,
background: iced_core::Background::from(iced_core::Color::from_rgba8(27, 25, 32, 1.0)),
border_width: 0.0,
border_radius: iced_core::BorderRadius::from(5.0),
border_color: SURFACE,
border: Border {
width: 0.0,
radius: Radius::from(5.0),
color: SURFACE,
},
selected_text_color: Color::WHITE,
selected_background: iced_core::Background::Color(accent),
}
Expand All @@ -75,8 +79,11 @@ impl iced_style::button::StyleSheet for ButtonStyle {
fn active(&self, _style: &Self::Style) -> button::Appearance {
button::Appearance {
text_color: Color::WHITE,
border_width: 0.0,
border_radius: BorderRadius::from(5.0),
border: Border {
width: 0.0,
radius: Radius::from(5.0),
..Default::default()
},
background: Some(iced_core::Background::Color(Color::from_rgba8(
74, 68, 88, 1.0,
))),
Expand Down Expand Up @@ -107,16 +114,24 @@ impl iced_style::button::StyleSheet for RoundButtonStyle {
type Style = iced_style::Theme;

fn active(&self, style: &Self::Style) -> button::Appearance {
let def = ButtonStyle::active(&ButtonStyle, style);
button::Appearance {
border_radius: BorderRadius::from(f32::MAX),
..ButtonStyle::active(&ButtonStyle, style)
border: Border {
radius: Radius::from(f32::MAX),
..def.border
},
..def
}
}

fn hovered(&self, style: &Self::Style) -> button::Appearance {
let def = ButtonStyle::hovered(&ButtonStyle, style);
button::Appearance {
border_radius: BorderRadius::from(f32::MAX),
..ButtonStyle::hovered(&ButtonStyle, style)
border: Border {
radius: Radius::from(f32::MAX),
..def.border
},
..def
}
}
}
Expand All @@ -135,9 +150,11 @@ impl iced_style::checkbox::StyleSheet for CheckboxStyle {
iced_style::checkbox::Appearance {
background: if is_checked { active } else { SURFACE }.into(),
text_color: Some(Color::WHITE),
border_radius: iced_core::BorderRadius::from(2.0),
border_width: 1.0,
border_color: active,
border: Border {
radius: Radius::from(2.0),
width: 1.0,
color: active,
},
icon_color: Color::WHITE,
}
}
Expand All @@ -153,6 +170,11 @@ impl iced_style::checkbox::StyleSheet for CheckboxStyle {
..self.active(style, is_checked)
}
}

fn disabled(&self, style: &Self::Style, is_checked: bool) -> iced_style::checkbox::Appearance {
// TODO
self.active(style, is_checked)
}
}

pub fn toggler() -> iced_style::theme::Toggler {
Expand Down
8 changes: 5 additions & 3 deletions neothesia/src/scene/menu_scene/icons.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use iced_style::Theme;

use super::Renderer;

static ICONS: iced_core::Font = iced_core::Font::with_name("bootstrap-icons");

pub fn play_icon<'a>() -> iced_widget::Text<'a, Renderer> {
pub fn play_icon<'a>() -> iced_widget::Text<'a, Theme, Renderer> {
iced_widget::text('\u{f49d}').font(ICONS)
}

pub fn note_list_icon<'a>() -> iced_widget::Text<'a, Renderer> {
pub fn note_list_icon<'a>() -> iced_widget::Text<'a, Theme, Renderer> {
iced_widget::text('\u{f451}').font(ICONS)
}

pub fn left_arrow_icon<'a>() -> iced_widget::Text<'a, Renderer> {
pub fn left_arrow_icon<'a>() -> iced_widget::Text<'a, Theme, Renderer> {
iced_widget::text('\u{f12f}').font(ICONS)
}
18 changes: 11 additions & 7 deletions neothesia/src/scene/menu_scene/layout.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::iced_utils::iced_state::Element;
use iced_core::{Alignment, Length};
use iced_core::{Alignment, Length, Renderer};
use iced_style::Theme;
use iced_widget::{column as col, row};

pub struct Layout<'a, Message> {
Expand Down Expand Up @@ -126,11 +127,11 @@ impl<'a, M: 'static> From<BarLayout<'a, M>> for Element<'a, M> {
}

pub trait PushIf<'a, M, R> {
fn push_if(self, item: Option<impl Into<iced_core::Element<'a, M, R>>>) -> Self;
fn push_if(self, item: Option<impl Into<iced_core::Element<'a, M, Theme, R>>>) -> Self;
}

impl<'a, M, R> PushIf<'a, M, R> for iced_widget::Row<'a, M, R> {
fn push_if(self, item: Option<impl Into<iced_core::Element<'a, M, R>>>) -> Self {
impl<'a, M, R: Renderer> PushIf<'a, M, R> for iced_widget::Row<'a, M, Theme, R> {
fn push_if(self, item: Option<impl Into<iced_core::Element<'a, M, Theme, R>>>) -> Self {
if let Some(item) = item {
self.push(item)
} else {
Expand All @@ -139,8 +140,8 @@ impl<'a, M, R> PushIf<'a, M, R> for iced_widget::Row<'a, M, R> {
}
}

impl<'a, M, R> PushIf<'a, M, R> for iced_widget::Column<'a, M, R> {
fn push_if(self, item: Option<impl Into<iced_core::Element<'a, M, R>>>) -> Self {
impl<'a, M, R: Renderer> PushIf<'a, M, R> for iced_widget::Column<'a, M, Theme, R> {
fn push_if(self, item: Option<impl Into<iced_core::Element<'a, M, Theme, R>>>) -> Self {
if let Some(item) = item {
self.push(item)
} else {
Expand All @@ -152,7 +153,10 @@ impl<'a, M, R> PushIf<'a, M, R> for iced_widget::Column<'a, M, R> {
impl<'a, M: 'a> PushIf<'a, M, super::Renderer>
for super::preferences_group::PreferencesGroup<'a, M>
{
fn push_if(self, item: Option<impl Into<iced_core::Element<'a, M, super::Renderer>>>) -> Self {
fn push_if(
self,
item: Option<impl Into<iced_core::Element<'a, M, Theme, super::Renderer>>>,
) -> Self {
if let Some(item) = item {
self.push(item)
} else {
Expand Down
5 changes: 2 additions & 3 deletions neothesia/src/scene/menu_scene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ mod wrap;
use std::time::Duration;

use iced_menu::AppUi;
use iced_style::Theme;
use neothesia_core::render::BgPipeline;

use wgpu_jumpstart::{TransformUniform, Uniform};
Expand All @@ -28,7 +27,7 @@ use crate::{
target::Target,
};

type Renderer = iced_wgpu::Renderer<Theme>;
type Renderer = iced_wgpu::Renderer;

pub struct MenuScene {
bg_pipeline: BgPipeline,
Expand Down Expand Up @@ -99,7 +98,7 @@ impl Scene for MenuScene {
let modifiers = ModifiersState::default();

if let Some(event) = iced_conversion::window_event(
event,
event.clone(),
target.iced_manager.viewport.scale_factor(),
modifiers,
) {
Expand Down
Loading

0 comments on commit d39e27a

Please sign in to comment.