From 5aa9c6a0a80524abdcb34a2a578cded0b583a41f Mon Sep 17 00:00:00 2001 From: PolyMeilex Date: Fri, 7 Jun 2024 22:25:45 +0200 Subject: [PATCH] Update iced to new styling API --- Cargo.lock | 102 +++--- Cargo.toml | 16 +- neothesia-iced-widgets/Cargo.toml | 1 - neothesia-iced-widgets/src/lib.rs | 2 +- neothesia-iced-widgets/src/neo_btn.rs | 58 +-- neothesia-iced-widgets/src/piano_range.rs | 3 +- .../src/preferences_group/mod.rs | 11 +- .../src/preferences_group/theme.rs | 59 ++- .../src/scroll_listener/mod.rs | 3 +- .../src/segment_button/mod.rs | 59 ++- .../src/segment_button/theme.rs | 87 ++--- neothesia-iced-widgets/src/track_card/mod.rs | 7 +- .../src/track_card/theme.rs | 73 ++-- neothesia-iced-widgets/src/wrap.rs | 3 +- neothesia/Cargo.toml | 2 +- neothesia/src/context.rs | 1 + neothesia/src/iced_utils/iced_conversion.rs | 1 + neothesia/src/iced_utils/iced_manager.rs | 22 +- neothesia/src/iced_utils/iced_state.rs | 8 +- neothesia/src/main.rs | 34 +- .../src/scene/menu_scene/iced_menu/exit.rs | 2 +- .../src/scene/menu_scene/iced_menu/main.rs | 2 +- .../src/scene/menu_scene/iced_menu/mod.rs | 11 +- .../scene/menu_scene/iced_menu/settings.rs | 18 +- .../src/scene/menu_scene/iced_menu/theme.rs | 345 +++++++----------- .../src/scene/menu_scene/iced_menu/tracks.rs | 4 +- neothesia/src/scene/menu_scene/icons.rs | 2 +- wgpu-jumpstart/src/gpu.rs | 7 +- 28 files changed, 433 insertions(+), 510 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 619b2243..79558c55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1528,6 +1528,18 @@ dependencies = [ "wgpu", ] +[[package]] +name = "glyphon" +version = "0.5.0" +source = "git+https://github.com/hecrj/glyphon.git?rev=f07e7bab705e69d39a5e6e52c73039a93c4552f8#f07e7bab705e69d39a5e6e52c73039a93c4552f8" +dependencies = [ + "cosmic-text", + "etagere", + "lru", + "rustc-hash", + "wgpu", +] + [[package]] name = "gpu-alloc" version = "0.6.0" @@ -1651,40 +1663,40 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "iced_core" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d7e6bbd197f311ed3d8b71651876b0ce01318fde52cda862a9a7a4373c9b930" +version = "0.13.0-dev" +source = "git+https://github.com/iced-rs/iced.git?rev=e2b00f98a0fab96da6502610b135a4c86fbd63b5#e2b00f98a0fab96da6502610b135a4c86fbd63b5" dependencies = [ "bitflags 2.5.0", + "bytes", "glam", "log", "num-traits", + "once_cell", "palette", "raw-window-handle 0.6.2", + "rustc-hash", "smol_str", "thiserror", - "web-time 0.2.4", - "xxhash-rust", + "web-time", ] [[package]] name = "iced_futures" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "370bad88fb3832cbeeb3fa6c486b4701fb7e8da32a753b3101d4ce81fc1d9497" +version = "0.13.0-dev" +source = "git+https://github.com/iced-rs/iced.git?rev=e2b00f98a0fab96da6502610b135a4c86fbd63b5#e2b00f98a0fab96da6502610b135a4c86fbd63b5" dependencies = [ "futures", "iced_core", "log", + "rustc-hash", "wasm-bindgen-futures", "wasm-timer", ] [[package]] name = "iced_graphics" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a044c193ef0840eacabfa05424717331d1fc5b3ecb9a89316200c75da2ba9a4" +version = "0.13.0-dev" +source = "git+https://github.com/iced-rs/iced.git?rev=e2b00f98a0fab96da6502610b135a4c86fbd63b5#e2b00f98a0fab96da6502610b135a4c86fbd63b5" dependencies = [ "bitflags 2.5.0", "bytemuck", @@ -1700,14 +1712,12 @@ dependencies = [ "rustc-hash", "thiserror", "unicode-segmentation", - "xxhash-rust", ] [[package]] name = "iced_renderer" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c281e03001d566058f53dec9325bbe61c62da715341206d2627f57a3ecc7f69" +version = "0.13.0-dev" +source = "git+https://github.com/iced-rs/iced.git?rev=e2b00f98a0fab96da6502610b135a4c86fbd63b5#e2b00f98a0fab96da6502610b135a4c86fbd63b5" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -1718,32 +1728,20 @@ dependencies = [ [[package]] name = "iced_runtime" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a79f852c01cc6d61663c94379cb3974ac3ad315a28c504e847d573e094f46822" +version = "0.13.0-dev" +source = "git+https://github.com/iced-rs/iced.git?rev=e2b00f98a0fab96da6502610b135a4c86fbd63b5#e2b00f98a0fab96da6502610b135a4c86fbd63b5" dependencies = [ + "bytes", "iced_core", "iced_futures", "raw-window-handle 0.6.2", "thiserror", ] -[[package]] -name = "iced_style" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ea42a740915d2a5a9ff9c3aa0bca28b16e9fb660bc8f675eed71d186cadb579" -dependencies = [ - "iced_core", - "once_cell", - "palette", -] - [[package]] name = "iced_tiny_skia" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c2228781f4d381a1cbbd7905a9f077351aa8d37269094021d5d9e779f130aff" +version = "0.13.0-dev" +source = "git+https://github.com/iced-rs/iced.git?rev=e2b00f98a0fab96da6502610b135a4c86fbd63b5#e2b00f98a0fab96da6502610b135a4c86fbd63b5" dependencies = [ "bytemuck", "cosmic-text", @@ -1753,37 +1751,36 @@ dependencies = [ "rustc-hash", "softbuffer", "tiny-skia", - "xxhash-rust", ] [[package]] name = "iced_wgpu" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c243b6700452886aac1ee1987e84d9fb43b56b53fea9a1eb67713fd0fde244" +version = "0.13.0-dev" +source = "git+https://github.com/iced-rs/iced.git?rev=e2b00f98a0fab96da6502610b135a4c86fbd63b5#e2b00f98a0fab96da6502610b135a4c86fbd63b5" dependencies = [ "bitflags 2.5.0", "bytemuck", "futures", "glam", - "glyphon", + "glyphon 0.5.0 (git+https://github.com/hecrj/glyphon.git?rev=f07e7bab705e69d39a5e6e52c73039a93c4552f8)", "guillotiere", "iced_graphics", "log", "once_cell", + "rustc-hash", + "thiserror", "wgpu", ] [[package]] name = "iced_widget" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e01b2212adecf1cb80e2267f302c0e0c263e55f97812056949199ccf9f0b908" +version = "0.13.0-dev" +source = "git+https://github.com/iced-rs/iced.git?rev=e2b00f98a0fab96da6502610b135a4c86fbd63b5#e2b00f98a0fab96da6502610b135a4c86fbd63b5" dependencies = [ "iced_renderer", "iced_runtime", - "iced_style", "num-traits", + "rustc-hash", "thiserror", "unicode-segmentation", ] @@ -2263,8 +2260,8 @@ dependencies = [ "futures", "iced_core", "iced_graphics", + "iced_renderer", "iced_runtime", - "iced_style", "iced_wgpu", "iced_widget", "image", @@ -2302,7 +2299,7 @@ name = "neothesia-core" version = "0.1.0" dependencies = [ "bytemuck", - "glyphon", + "glyphon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "log", "midi-file", "objc", @@ -2320,7 +2317,6 @@ version = "0.1.0" dependencies = [ "iced_core", "iced_graphics", - "iced_style", "iced_wgpu", "iced_widget", "piano-math", @@ -4043,16 +4039,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "web-time" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa30049b1c872b72c89866d458eae9f20380ab280ffd1b1e18df2d3e2d98cfe0" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "web-time" version = "1.1.0" @@ -4564,7 +4550,7 @@ dependencies = [ "wayland-protocols", "wayland-protocols-plasma", "web-sys", - "web-time 1.1.0", + "web-time", "windows-sys 0.52.0", "x11-dl", "x11rb", @@ -4672,12 +4658,6 @@ version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "791978798f0597cfc70478424c2b4fdc2b7a8024aaff78497ef00f24ef674193" -[[package]] -name = "xxhash-rust" -version = "0.8.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927da81e25be1e1a2901d59b81b37dd2efd1fc9c9345a55007f09bf5a2d3ee03" - [[package]] name = "yazi" version = "0.1.6" diff --git a/Cargo.toml b/Cargo.toml index 6fd4f0f5..37d9a062 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,9 +31,13 @@ piano-math = { path = "./piano-math" } profiling = "1.0" -iced_style = "0.12" -iced_graphics = "0.12" -iced_core = "0.12" -iced_runtime = "0.12" -iced_wgpu = { version = "0.12", features = ["image"] } -iced_widget = { version = "0.12", features = ["image"] } +iced_graphics = { git = "https://github.com/iced-rs/iced.git", rev = "e2b00f98a0fab96da6502610b135a4c86fbd63b5" } +iced_core = { git = "https://github.com/iced-rs/iced.git", rev = "e2b00f98a0fab96da6502610b135a4c86fbd63b5" } +iced_runtime = { git = "https://github.com/iced-rs/iced.git", rev = "e2b00f98a0fab96da6502610b135a4c86fbd63b5" } +iced_renderer = { git = "https://github.com/iced-rs/iced.git", rev = "e2b00f98a0fab96da6502610b135a4c86fbd63b5" } +iced_wgpu = { git = "https://github.com/iced-rs/iced.git", rev = "e2b00f98a0fab96da6502610b135a4c86fbd63b5", features = [ + "image", +] } +iced_widget = { git = "https://github.com/iced-rs/iced.git", rev = "e2b00f98a0fab96da6502610b135a4c86fbd63b5", features = [ + "image", +] } diff --git a/neothesia-iced-widgets/Cargo.toml b/neothesia-iced-widgets/Cargo.toml index b6064c5f..46dc16f4 100644 --- a/neothesia-iced-widgets/Cargo.toml +++ b/neothesia-iced-widgets/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" edition = "2021" [dependencies] -iced_style.workspace = true iced_graphics.workspace = true iced_core.workspace = true iced_wgpu.workspace = true diff --git a/neothesia-iced-widgets/src/lib.rs b/neothesia-iced-widgets/src/lib.rs index ae80fff5..03d309b7 100644 --- a/neothesia-iced-widgets/src/lib.rs +++ b/neothesia-iced-widgets/src/lib.rs @@ -17,4 +17,4 @@ pub use track_card::TrackCard; pub use wrap::Wrap; type Renderer = iced_wgpu::Renderer; -pub type Element<'a, M> = iced_core::Element<'a, M, iced_style::Theme, iced_wgpu::Renderer>; +pub type Element<'a, M> = iced_core::Element<'a, M, iced_core::Theme, iced_wgpu::Renderer>; diff --git a/neothesia-iced-widgets/src/neo_btn.rs b/neothesia-iced-widgets/src/neo_btn.rs index f08ce466..3dcbd525 100644 --- a/neothesia-iced-widgets/src/neo_btn.rs +++ b/neothesia-iced-widgets/src/neo_btn.rs @@ -6,10 +6,8 @@ use iced_core::{ renderer::Style, widget::{tree, Tree}, Background, Border, Clipboard, Color, Element, Event, Layout, Length, Padding, Rectangle, - Shell, Size, Widget, + Shell, Size, Theme, Widget, }; -use iced_graphics::Primitive; -use iced_style::Theme; use iced_widget::text; pub struct NeoBtn<'a, Message> { @@ -25,7 +23,7 @@ pub struct NeoBtn<'a, Message> { } impl<'a, Message: Clone> NeoBtn<'a, Message> { - pub fn new_with_label(label: &str) -> Self { + pub fn new_with_label(label: &'a str) -> Self { Self::new( text(label) .size(30) @@ -201,7 +199,7 @@ impl<'a, Message: Clone> Widget for NeoBtn<'a, Message &self, tree: &Tree, renderer: &mut Renderer, - theme: &iced_style::Theme, + theme: &Theme, _style: &Style, layout: Layout<'_>, cursor: mouse::Cursor, @@ -226,42 +224,44 @@ impl<'a, Message: Clone> Widget for NeoBtn<'a, Message ) }; - let bg = Primitive::Quad { - bounds: Rectangle { - y: bounds.y, - ..bounds - }, - background: Background::Color(colors.0), - border: Border { - radius: Radius::from(self.border_radius), - width: 0.0, - color: Color::TRANSPARENT, + use iced_core::renderer::Renderer; + renderer.fill_quad( + iced_core::renderer::Quad { + bounds: Rectangle { + y: bounds.y, + ..bounds + }, + border: Border { + radius: Radius::from(self.border_radius), + width: 0.0, + color: Color::TRANSPARENT, + }, + shadow: iced_core::Shadow::default(), }, - shadow: iced_core::Shadow::default(), - }; - renderer.draw_primitive(bg); + Background::Color(colors.0), + ); - let btn_bar = Primitive::Clip { - bounds: Rectangle { - y: bounds.y + bounds.height - self.border_radius, - height: self.border_radius, - ..bounds - }, - content: Box::new(Primitive::Quad { + renderer.start_layer(Rectangle { + y: bounds.y + bounds.height - self.border_radius, + height: self.border_radius, + ..bounds + }); + renderer.fill_quad( + iced_core::renderer::Quad { bounds: Rectangle { y: bounds.y, ..bounds }, - background: Background::Color(colors.1), border: Border { radius: Radius::from(self.border_radius), width: 0.0, color: Color::TRANSPARENT, }, shadow: iced_core::Shadow::default(), - }), - }; - renderer.draw_primitive(btn_bar); + }, + Background::Color(colors.1), + ); + renderer.end_layer(); if is_mouse_over { mouse::Interaction::Pointer diff --git a/neothesia-iced-widgets/src/piano_range.rs b/neothesia-iced-widgets/src/piano_range.rs index f07d91d3..08af1cd5 100644 --- a/neothesia-iced-widgets/src/piano_range.rs +++ b/neothesia-iced-widgets/src/piano_range.rs @@ -1,9 +1,8 @@ use iced_core::{ border::{Border, Radius}, renderer::Quad, - Background, Color, Length, Rectangle, Size, Vector, Widget, + Background, Color, Length, Rectangle, Size, Theme, Vector, Widget, }; -use iced_style::Theme; use super::Element; diff --git a/neothesia-iced-widgets/src/preferences_group/mod.rs b/neothesia-iced-widgets/src/preferences_group/mod.rs index 541f5aa7..e5e2ea3b 100644 --- a/neothesia-iced-widgets/src/preferences_group/mod.rs +++ b/neothesia-iced-widgets/src/preferences_group/mod.rs @@ -1,5 +1,4 @@ -use iced_core::{Font, Length}; -use iced_style::Theme; +use iced_core::{Font, Length, Theme}; use iced_widget::{column, container, row, text}; use super::{Element, Renderer}; @@ -76,7 +75,7 @@ fn group_body<'a, M: 'a>(items: Vec>) -> Element<'a, M> { let separator = container(row![]) .width(Length::Fill) .height(1) - .style(theme::separator()); + .style(theme::separator); coll = coll.push(separator); } else { needs_sep = true; @@ -88,7 +87,7 @@ fn group_body<'a, M: 'a>(items: Vec>) -> Element<'a, M> { } } - container(coll).style(theme::card()).into() + container(coll).style(theme::card).into() } fn triple_split<'a, T: 'a>( @@ -116,7 +115,7 @@ fn group_header<'a, T: 'a>(data: PreferencesGroupHeader) -> Element<'a, T> { }); let subtitle = data .subtitle - .map(|title| text(title).style(theme::subtitle()).size(12.2)); + .map(|title| text(title).style(theme::subtitle).size(12.2)); let header = column![].push_maybe(title).push_maybe(subtitle); @@ -129,7 +128,7 @@ fn title<'a, T: 'a>( ) -> iced_widget::Column<'a, T, Theme, Renderer> { column![] .push_maybe(title.map(|title| text(title).size(14.6))) - .push_maybe(subtitle.map(|subtitle| text(subtitle).size(12.2).style(theme::subtitle()))) + .push_maybe(subtitle.map(|subtitle| text(subtitle).size(12.2).style(theme::subtitle))) } pub struct ActionRow<'a, MSG> { diff --git a/neothesia-iced-widgets/src/preferences_group/theme.rs b/neothesia-iced-widgets/src/preferences_group/theme.rs index b8458be8..b94f8d9c 100644 --- a/neothesia-iced-widgets/src/preferences_group/theme.rs +++ b/neothesia-iced-widgets/src/preferences_group/theme.rs @@ -1,47 +1,30 @@ use iced_core::border::{Border, Radius}; - -pub fn card() -> iced_style::theme::Container { - iced_style::theme::Container::Custom(Box::new(ContainerStyle)) -} - -struct ContainerStyle; - -impl iced_style::container::StyleSheet for ContainerStyle { - type Style = iced_style::Theme; - - fn appearance(&self, _style: &Self::Style) -> iced_style::container::Appearance { - iced_style::container::Appearance { - background: Some(iced_core::Background::from(iced_core::Color::from_rgba8( - 37, 35, 42, 1.0, - ))), - border: Border { - radius: Radius::from(12.0), - ..Default::default() - }, +use iced_widget::container; + +pub fn card(_theme: &T) -> container::Style { + container::Style { + background: Some(iced_core::Background::from(iced_core::Color::from_rgba8( + 37, 35, 42, 1.0, + ))), + border: Border { + radius: Radius::from(12.0), ..Default::default() - } + }, + ..Default::default() } } -pub fn separator() -> iced_style::theme::Container { - iced_style::theme::Container::Custom(Box::new(SeparatorContainerStyle)) -} - -struct SeparatorContainerStyle; - -impl iced_style::container::StyleSheet for SeparatorContainerStyle { - type Style = iced_style::Theme; - - fn appearance(&self, _style: &Self::Style) -> iced_style::container::Appearance { - iced_style::container::Appearance { - background: Some(iced_core::Background::from(iced_core::Color::from_rgba8( - 16, 16, 16, 1.0, - ))), - ..Default::default() - } +pub fn separator(_theme: &T) -> container::Style { + container::Style { + background: Some(iced_core::Background::from(iced_core::Color::from_rgba8( + 16, 16, 16, 1.0, + ))), + ..Default::default() } } -pub fn subtitle() -> iced_style::theme::Text { - iced_style::theme::Text::Color(iced_core::Color::from_rgba(1.0, 1.0, 1.0, 0.5)) +pub fn subtitle(_theme: &T) -> iced_widget::text::Style { + iced_widget::text::Style { + color: Some(iced_core::Color::from_rgba(1.0, 1.0, 1.0, 0.5)), + } } diff --git a/neothesia-iced-widgets/src/scroll_listener/mod.rs b/neothesia-iced-widgets/src/scroll_listener/mod.rs index 79bb2476..c359530e 100644 --- a/neothesia-iced-widgets/src/scroll_listener/mod.rs +++ b/neothesia-iced-widgets/src/scroll_listener/mod.rs @@ -1,5 +1,4 @@ -use iced_core::{mouse::ScrollDelta, Length, Size, Widget}; -use iced_style::Theme; +use iced_core::{mouse::ScrollDelta, Length, Size, Theme, Widget}; use super::Element; diff --git a/neothesia-iced-widgets/src/segment_button/mod.rs b/neothesia-iced-widgets/src/segment_button/mod.rs index 0c56056c..14094075 100644 --- a/neothesia-iced-widgets/src/segment_button/mod.rs +++ b/neothesia-iced-widgets/src/segment_button/mod.rs @@ -1,9 +1,8 @@ use super::{Element, Renderer}; use iced_core::{ alignment::{Horizontal, Vertical}, - Color, Length, + Color, Length, Theme, }; -use iced_style::Theme; mod theme; @@ -46,7 +45,7 @@ impl SegmentButton { fn segment<'a, MSG: 'a>(label: &str) -> iced_widget::Button<'a, MSG, Theme, Renderer> { iced_widget::button( - iced_widget::text(label) + iced_widget::text(label.to_string()) .horizontal_alignment(Horizontal::Center) .vertical_alignment(Vertical::Center) .width(Length::Fill) @@ -65,20 +64,36 @@ impl<'a, M: Clone + 'a> From> for Element<'a, M> { let first = btn.buttons.remove(0); let first = segment(&first.0) - .style(theme::segment_button( - theme::ButtonSegmentKind::Start, - btn.active == 0, - btn.active_color, - )) + .style({ + let active = btn.active == 0; + let active_color = btn.active_color; + move |theme, status| { + theme::segment_button( + theme::ButtonSegmentKind::Start, + active, + active_color, + theme, + status, + ) + } + }) .on_press(first.1); let last = btn.buttons.pop().unwrap(); let last = segment(&last.0) - .style(theme::segment_button( - theme::ButtonSegmentKind::End, - btn.active == last_id, - btn.active_color, - )) + .style({ + let active = btn.active == last_id; + let active_color = btn.active_color; + move |theme, status| { + theme::segment_button( + theme::ButtonSegmentKind::End, + active, + active_color, + theme, + status, + ) + } + }) .on_press(last.1); new.push(first); @@ -86,11 +101,19 @@ impl<'a, M: Clone + 'a> From> for Element<'a, M> { let id = id + 1; new.push( segment(&label) - .style(theme::segment_button( - theme::ButtonSegmentKind::Center, - btn.active == id, - btn.active_color, - )) + .style({ + let active = btn.active == id; + let active_color = btn.active_color; + move |theme, status| { + theme::segment_button( + theme::ButtonSegmentKind::Center, + active, + active_color, + theme, + status, + ) + } + }) .on_press(msg), ); } diff --git a/neothesia-iced-widgets/src/segment_button/theme.rs b/neothesia-iced-widgets/src/segment_button/theme.rs index e7f21c1d..7d6bf90c 100644 --- a/neothesia-iced-widgets/src/segment_button/theme.rs +++ b/neothesia-iced-widgets/src/segment_button/theme.rs @@ -2,7 +2,7 @@ use iced_core::{ border::{Border, Radius}, Color, }; -use iced_style::button; +use iced_widget::button; pub enum ButtonSegmentKind { Start, @@ -10,56 +10,57 @@ pub enum ButtonSegmentKind { End, } -pub fn segment_button( +pub fn segment_button( kind: ButtonSegmentKind, active: bool, active_color: Color, -) -> iced_style::theme::Button { - iced_style::theme::Button::Custom(Box::new(SegmentButtonStyle(kind, active, active_color))) -} - -struct SegmentButtonStyle(ButtonSegmentKind, bool, Color); - -impl iced_style::button::StyleSheet for SegmentButtonStyle { - type Style = iced_style::Theme; - - fn active(&self, _style: &Self::Style) -> button::Appearance { - let border_radius = match self.0 { - ButtonSegmentKind::Start => Radius::from([255.0, 0.0, 0.0, 255.0]), - ButtonSegmentKind::Center => Radius::from(0.0), - ButtonSegmentKind::End => Radius::from([0.0, 255.0, 255.0, 0.0]), - }; - let active = self.1; + theme: &T, + status: iced_widget::button::Status, +) -> button::Style { + match status { + button::Status::Active => { + let border_radius = match kind { + ButtonSegmentKind::Start => Radius::from([255.0, 0.0, 0.0, 255.0]), + ButtonSegmentKind::Center => Radius::from(0.0), + ButtonSegmentKind::End => Radius::from([0.0, 255.0, 255.0, 0.0]), + }; - let background = if active { - Some(iced_core::Background::from(self.2)) - } else { - Some(iced_core::Background::from(iced_core::Color::from_rgba8( - 74, 68, 88, 1.0, - ))) - }; + let background = if active { + Some(iced_core::Background::from(active_color)) + } else { + Some(iced_core::Background::from(iced_core::Color::from_rgba8( + 74, 68, 88, 1.0, + ))) + }; - button::Appearance { - text_color: Color::WHITE, - border: Border { - color: Color::TRANSPARENT, - width: 0.0, - radius: border_radius, - }, - background, - ..Default::default() + button::Style { + text_color: Color::WHITE, + border: Border { + color: Color::TRANSPARENT, + width: 0.0, + radius: border_radius, + }, + background, + ..Default::default() + } } - } + iced_widget::button::Status::Hovered => { + let mut active = + segment_button(kind, active, active_color, theme, button::Status::Active); - fn hovered(&self, style: &Self::Style) -> button::Appearance { - let mut active = self.active(style); + if let Some(iced_core::Background::Color(ref mut color)) = active.background { + color.r = (color.r + 0.05).min(1.0); + color.g = (color.g + 0.05).min(1.0); + color.b = (color.b + 0.05).min(1.0); + } - if let Some(iced_core::Background::Color(ref mut color)) = active.background { - color.r = (color.r + 0.05).min(1.0); - color.g = (color.g + 0.05).min(1.0); - color.b = (color.b + 0.05).min(1.0); + active + } + iced_widget::button::Status::Pressed => { + segment_button(kind, active, active_color, theme, button::Status::Active) + } + iced_widget::button::Status::Disabled => { + segment_button(kind, active, active_color, theme, button::Status::Active) } - - active } } diff --git a/neothesia-iced-widgets/src/track_card/mod.rs b/neothesia-iced-widgets/src/track_card/mod.rs index 369a5adf..08f841e4 100644 --- a/neothesia-iced-widgets/src/track_card/mod.rs +++ b/neothesia-iced-widgets/src/track_card/mod.rs @@ -61,7 +61,10 @@ impl<'a, M: Clone + 'a> From> for Element<'a, M> { iced_widget::button(iced_widget::text("")) .width(40) .height(40) - .style(theme::track_icon_button(card.track_color)) + .style({ + let color = card.track_color; + move |theme, status| theme::track_icon_button(color, theme, status) + }) .on_press_maybe(card.on_icon_press), iced_widget::column(vec![ iced_widget::text(card.title).size(16).into(), @@ -80,7 +83,7 @@ impl<'a, M: Clone + 'a> From> for Element<'a, M> { iced_widget::container(iced_widget::column(children).width(312).spacing(12)) .padding(16) - .style(theme::card()) + .style(theme::card) .into() } } diff --git a/neothesia-iced-widgets/src/track_card/theme.rs b/neothesia-iced-widgets/src/track_card/theme.rs index ac2ba3a7..a85fcd40 100644 --- a/neothesia-iced-widgets/src/track_card/theme.rs +++ b/neothesia-iced-widgets/src/track_card/theme.rs @@ -1,58 +1,45 @@ use iced_core::border::{Border, Radius}; - -pub fn card() -> iced_style::theme::Container { - iced_style::theme::Container::Custom(Box::new(ContainerStyle)) -} - -struct ContainerStyle; - -impl iced_style::container::StyleSheet for ContainerStyle { - type Style = iced_style::Theme; - - fn appearance(&self, _style: &Self::Style) -> iced_style::container::Appearance { - iced_style::container::Appearance { - background: Some(iced_core::Background::from(iced_core::Color::from_rgba8( - 37, 35, 42, 1.0, - ))), - border: Border { - radius: Radius::from(12.0), - ..Default::default() - }, +use iced_widget::{button, container}; + +pub fn card(_theme: &T) -> container::Style { + container::Style { + background: Some(iced_core::Background::from(iced_core::Color::from_rgba8( + 37, 35, 42, 1.0, + ))), + border: Border { + radius: Radius::from(12.0), ..Default::default() - } + }, + ..Default::default() } } -pub fn track_icon_button(color: iced_core::Color) -> iced_style::theme::Button { - iced_style::theme::Button::Custom(Box::new(TrackIconButtonStyle(color))) -} - -struct TrackIconButtonStyle(iced_core::Color); - -impl iced_style::button::StyleSheet for TrackIconButtonStyle { - type Style = iced_style::Theme; - - fn active(&self, _style: &Self::Style) -> iced_style::button::Appearance { - iced_style::button::Appearance { - background: Some(iced_core::Background::from(self.0)), +pub fn track_icon_button( + color: iced_core::Color, + theme: &T, + status: button::Status, +) -> button::Style { + match status { + button::Status::Active => button::Style { + background: Some(iced_core::Background::from(color)), border: Border { radius: Radius::from(255.0), ..Default::default() }, ..Default::default() - } - } + }, + button::Status::Hovered => { + let mut active = track_icon_button(color, theme, button::Status::Active); - /// Produces the hovered [`Appearance`] of a button. - fn hovered(&self, style: &Self::Style) -> iced_style::button::Appearance { - let mut active = self.active(style); + if let Some(iced_core::Background::Color(ref mut color)) = active.background { + color.r = (color.r + 0.05).min(1.0); + color.g = (color.g + 0.05).min(1.0); + color.b = (color.b + 0.05).min(1.0); + } - if let Some(iced_core::Background::Color(ref mut color)) = active.background { - color.r = (color.r + 0.05).min(1.0); - color.g = (color.g + 0.05).min(1.0); - color.b = (color.b + 0.05).min(1.0); + active } - - active + button::Status::Pressed => track_icon_button(color, theme, button::Status::Active), + button::Status::Disabled => track_icon_button(color, theme, button::Status::Active), } } diff --git a/neothesia-iced-widgets/src/wrap.rs b/neothesia-iced-widgets/src/wrap.rs index 4b659c3c..8f28b7f5 100644 --- a/neothesia-iced-widgets/src/wrap.rs +++ b/neothesia-iced-widgets/src/wrap.rs @@ -1,7 +1,6 @@ //! A widget that displays its children in multiple horizontal or vertical runs. //! //! *This API requires the following crate features to be activated: `wrap`* -use iced_style::Theme; use iced_widget::core::{ self, event, layout::{Limits, Node}, @@ -9,7 +8,7 @@ use iced_widget::core::{ renderer, widget::{Operation, Tree}, Alignment, Clipboard, Element, Event, Layout, Length, Padding, Point, Rectangle, Shell, Size, - Widget, + Theme, Widget, }; use core::Vector; diff --git a/neothesia/Cargo.toml b/neothesia/Cargo.toml index 12cab6b1..113368a7 100644 --- a/neothesia/Cargo.toml +++ b/neothesia/Cargo.toml @@ -25,12 +25,12 @@ piano-math.workspace = true midi-file.workspace = true midi-io.workspace = true -iced_style.workspace = true iced_graphics.workspace = true iced_core.workspace = true iced_runtime.workspace = true iced_wgpu.workspace = true iced_widget.workspace = true +iced_renderer = { workspace = true, features = ["wgpu"]} fps_ticker = "1" winit = { version = "0.30", features = ["rwh_05"] } diff --git a/neothesia/src/context.rs b/neothesia/src/context.rs index ff94d3e5..41fcf046 100644 --- a/neothesia/src/context.rs +++ b/neothesia/src/context.rs @@ -47,6 +47,7 @@ impl Context { let text_renderer = TextRenderer::new(&gpu); let iced_manager = IcedManager::new( + &gpu.adapter, &gpu.device, &gpu.queue, gpu.texture_format, diff --git a/neothesia/src/iced_utils/iced_conversion.rs b/neothesia/src/iced_utils/iced_conversion.rs index b11590a8..d57d87e9 100644 --- a/neothesia/src/iced_utils/iced_conversion.rs +++ b/neothesia/src/iced_utils/iced_conversion.rs @@ -247,6 +247,7 @@ pub fn mouse_interaction(interaction: mouse::Interaction) -> winit::window::Curs Interaction::ResizingVertically => winit::window::CursorIcon::NsResize, Interaction::NotAllowed => winit::window::CursorIcon::NotAllowed, Interaction::ZoomIn => winit::window::CursorIcon::ZoomIn, + Interaction::None => winit::window::CursorIcon::Default, } } diff --git a/neothesia/src/iced_utils/iced_manager.rs b/neothesia/src/iced_utils/iced_manager.rs index c69e10ce..f842776c 100644 --- a/neothesia/src/iced_utils/iced_manager.rs +++ b/neothesia/src/iced_utils/iced_manager.rs @@ -1,13 +1,13 @@ -use iced_core::text::Renderer; - pub struct IcedManager { pub renderer: iced_wgpu::Renderer, pub viewport: iced_wgpu::graphics::Viewport, pub debug: iced_runtime::Debug, + pub engine: iced_wgpu::Engine, } impl IcedManager { pub fn new( + adapter: &wgpu::Adapter, device: &wgpu::Device, queue: &wgpu::Queue, texture_format: wgpu::TextureFormat, @@ -16,16 +16,21 @@ impl IcedManager { ) -> Self { let debug = iced_runtime::Debug::new(); - let settings = iced_wgpu::Settings::default(); + let engine = iced_wgpu::Engine::new(adapter, device, queue, texture_format, None); - let mut renderer = iced_wgpu::Renderer::new( - iced_wgpu::Backend::new(device, queue, settings, texture_format), + let renderer = iced_wgpu::Renderer::new( + device, + &engine, iced_core::Font::default(), iced_core::Pixels(16.0), ); - renderer.load_font(std::borrow::Cow::Borrowed(include_bytes!( - "./bootstrap-icons.ttf" - ))); + + iced_graphics::text::font_system() + .write() + .expect("Write to font system") + .load_font(std::borrow::Cow::Borrowed(include_bytes!( + "./bootstrap-icons.ttf" + ))); let viewport = iced_wgpu::graphics::Viewport::with_physical_size( iced_core::Size::new(physical_size.0, physical_size.1), @@ -36,6 +41,7 @@ impl IcedManager { renderer, viewport, debug, + engine, } } diff --git a/neothesia/src/iced_utils/iced_state.rs b/neothesia/src/iced_utils/iced_state.rs index dbd1988c..c1f95f27 100644 --- a/neothesia/src/iced_utils/iced_state.rs +++ b/neothesia/src/iced_utils/iced_state.rs @@ -1,9 +1,7 @@ -use iced_core::mouse; -use iced_core::{Event, Size}; +use iced_core::{mouse, Event, Size, Theme}; use iced_graphics::core::Color; use iced_runtime::user_interface::{self, UserInterface}; use iced_runtime::Command; -use iced_style::Theme; use super::{iced_clipboard::DummyClipboard, iced_conversion}; use crate::context::Context; @@ -151,7 +149,7 @@ where if messages.is_empty() { self.mouse_interaction = user_interface.draw( &mut ctx.iced_manager.renderer, - &iced_style::Theme::Dark, + &Theme::Dark, &iced_core::renderer::Style { text_color: Color::WHITE, }, @@ -177,7 +175,7 @@ where self.mouse_interaction = user_interface.draw( &mut ctx.iced_manager.renderer, - &iced_style::Theme::Dark, + &Theme::Dark, &iced_core::renderer::Style { text_color: Color::WHITE, }, diff --git a/neothesia/src/main.rs b/neothesia/src/main.rs index 80d2f4bb..176be166 100644 --- a/neothesia/src/main.rs +++ b/neothesia/src/main.rs @@ -219,26 +219,24 @@ impl Neothesia { self.context.text_renderer.render(&mut rpass); } + self.context.iced_manager.renderer.present( + &mut self.context.iced_manager.engine, + &self.context.gpu.device, + &self.context.gpu.queue, + &mut self.context.gpu.encoder, + None, + self.context.gpu.texture_format, + view, + &self.context.iced_manager.viewport, + &self.context.iced_manager.debug.overlay(), + ); + + let encoder = self.context.gpu.take(); self.context .iced_manager - .renderer - .with_primitives(|backend, primitive| { - if !primitive.is_empty() { - backend.present( - &self.context.gpu.device, - &self.context.gpu.queue, - &mut self.context.gpu.encoder, - None, - self.context.gpu.texture_format, - view, - primitive, - &self.context.iced_manager.viewport, - &self.context.iced_manager.debug.overlay(), - ); - } - }); - - self.context.gpu.submit(); + .engine + .submit(&self.context.gpu.queue, encoder); + // self.context.gpu.submit(); frame.present(); self.context.text_renderer.atlas().trim(); diff --git a/neothesia/src/scene/menu_scene/iced_menu/exit.rs b/neothesia/src/scene/menu_scene/iced_menu/exit.rs index bed6f74e..4f3b0ed1 100644 --- a/neothesia/src/scene/menu_scene/iced_menu/exit.rs +++ b/neothesia/src/scene/menu_scene/iced_menu/exit.rs @@ -49,7 +49,7 @@ impl Page for ExitPage { .width(Length::Fixed(650.0)) .spacing(30); - center_x(controls).center_y().into() + center_x(controls).center_y(Length::Fill).into() } fn keyboard_input(event: &iced_runtime::keyboard::Event, _ctx: &Context) -> Option { diff --git a/neothesia/src/scene/menu_scene/iced_menu/main.rs b/neothesia/src/scene/menu_scene/iced_menu/main.rs index c0554a58..f9e717a1 100644 --- a/neothesia/src/scene/menu_scene/iced_menu/main.rs +++ b/neothesia/src/scene/menu_scene/iced_menu/main.rs @@ -109,7 +109,7 @@ impl Page for MainPage { layout = layout.bottom( BarLayout::new() .center( - text(&song.file.name) + text(song.file.name.to_string()) .width(Length::Fill) .vertical_alignment(Vertical::Center) .horizontal_alignment(Horizontal::Center), diff --git a/neothesia/src/scene/menu_scene/iced_menu/mod.rs b/neothesia/src/scene/menu_scene/iced_menu/mod.rs index 9b19c872..140272a2 100644 --- a/neothesia/src/scene/menu_scene/iced_menu/mod.rs +++ b/neothesia/src/scene/menu_scene/iced_menu/mod.rs @@ -6,10 +6,9 @@ use super::Renderer; use iced_core::{ alignment::{Horizontal, Vertical}, image::Handle as ImageHandle, - Alignment, Length, + Alignment, Length, Theme, }; use iced_runtime::Command; -use iced_style::Theme; use iced_widget::{column as col, container, image, text, vertical_space}; use crate::{ @@ -78,7 +77,7 @@ impl AppUi { is_loading: false, - logo_handle: ImageHandle::from_memory(include_bytes!("../img/banner.png").to_vec()), + logo_handle: ImageHandle::from_bytes(include_bytes!("../img/banner.png").to_vec()), }, } } @@ -256,7 +255,7 @@ fn loading(data: &Data) -> Element<'_, Message> { } fn centered_text<'a>(label: impl ToString) -> iced_widget::Text<'a, Theme, Renderer> { - text(label) + text(label.to_string()) .horizontal_alignment(Horizontal::Center) .vertical_alignment(Vertical::Center) } @@ -267,7 +266,7 @@ fn top_padded<'a, MSG: 'a>( let spacer = vertical_space().height(Length::FillPortion(1)); let content = container(content) .height(Length::FillPortion(4)) - .center_x() + .center_x(Length::Fill) .max_width(650); col![spacer, content] @@ -282,5 +281,5 @@ fn center_x<'a, MSG: 'a>( container(content) .width(Length::Fill) .height(Length::Fill) - .center_x() + .center_x(Length::Fill) } diff --git a/neothesia/src/scene/menu_scene/iced_menu/settings.rs b/neothesia/src/scene/menu_scene/iced_menu/settings.rs index a0c762e7..f992da5d 100644 --- a/neothesia/src/scene/menu_scene/iced_menu/settings.rs +++ b/neothesia/src/scene/menu_scene/iced_menu/settings.rs @@ -180,7 +180,7 @@ impl Page for SettingsPage { .width(Length::Fill) .align_items(Alignment::Center); - let column = iced_widget::scrollable(body).style(theme::scrollable()); + let column = iced_widget::scrollable(body).style(theme::scrollable); Layout::new() .body(column) @@ -212,7 +212,8 @@ fn output_group<'a>(data: &'a Data, ctx: &Context) -> Element<'a, Event> { data.selected_output.clone(), Event::SelectOutput, ) - .style(theme::pick_list()); + .style(theme::pick_list) + .menu_style(theme::pick_list_menu); ActionRow::new().title("Output").suffix(output_list) }; @@ -228,7 +229,7 @@ fn output_group<'a>(data: &'a Data, ctx: &Context) -> Element<'a, Event> { let mut row = ActionRow::new().title("SoundFont").suffix( iced_widget::button(centered_text("Select File")) - .style(theme::button()) + .style(theme::button) .on_press(Event::OpenSoundFontPicker), ); @@ -256,7 +257,8 @@ fn input_group<'a>(data: &'a Data, _ctx: &Context) -> Element<'a, Event> { let selected_input = data.selected_input.clone(); let input_list = pick_list(data.inputs.as_ref(), selected_input, Event::SelectInput) - .style(theme::pick_list()); + .style(theme::pick_list) + .menu_style(theme::pick_list_menu); PreferencesGroup::new() .title("Input") @@ -268,11 +270,11 @@ fn counter<'a>(value: impl ToString, msg: fn(RangeUpdateKind) -> Event) -> Eleme let label = centered_text(value); let sub = button(centered_text("-").width(30).height(30)) .padding(0) - .style(theme::round_button()) + .style(theme::round_button) .on_press(msg(RangeUpdateKind::Sub)); let add = button(centered_text("+").width(30).height(30)) .padding(0) - .style(theme::round_button()) + .style(theme::round_button) .on_press(msg(RangeUpdateKind::Add)); let row = row![label, sub, add] @@ -306,14 +308,14 @@ fn guidelines_group<'a>(_data: &'a Data, ctx: &Context) -> Element<'a, Event> { ctx.config.vertical_guidelines, Event::VerticalGuidelines, ) - .style(theme::toggler()); + .style(theme::toggler); let horizontal = toggler( None, ctx.config.horizontal_guidelines, Event::HorizontalGuidelines, ) - .style(theme::toggler()); + .style(theme::toggler); PreferencesGroup::new() .title("Render") diff --git a/neothesia/src/scene/menu_scene/iced_menu/theme.rs b/neothesia/src/scene/menu_scene/iced_menu/theme.rs index 1e3d5648..24098c3d 100644 --- a/neothesia/src/scene/menu_scene/iced_menu/theme.rs +++ b/neothesia/src/scene/menu_scene/iced_menu/theme.rs @@ -1,8 +1,8 @@ -use std::rc::Rc; - -use iced_core::border::{Border, Radius}; +use iced_core::{ + border::{Border, Radius}, + Theme, +}; use iced_graphics::core::Color; -use iced_style::{button, pick_list}; const SURFACE: Color = Color::from_rgb( 0x30 as f32 / 255.0, @@ -10,74 +10,57 @@ const SURFACE: Color = Color::from_rgb( 0x3B as f32 / 255.0, ); -pub fn pick_list() -> iced_style::theme::PickList { - iced_style::theme::PickList::Custom(Rc::new(PickListStyle), Rc::new(MenuStyle)) -} - -struct PickListStyle; - -impl iced_style::pick_list::StyleSheet for PickListStyle { - type Style = iced_style::Theme; - - fn active(&self, _style: &Self::Style) -> pick_list::Appearance { - pick_list::Appearance { +pub fn pick_list( + _theme: &Theme, + status: iced_widget::pick_list::Status, +) -> iced_widget::pick_list::Style { + match status { + iced_widget::pick_list::Status::Active => iced_widget::pick_list::Style { text_color: Color::WHITE, - background: iced_core::Background::Color(Color::from_rgba8(74, 68, 88, 1.0)), placeholder_color: Color::WHITE, + handle_color: Color::WHITE, + background: iced_core::Background::Color(Color::from_rgba8(74, 68, 88, 1.0)), border: Border { radius: Radius::from(5.0), width: 0.0, color: SURFACE, }, - handle_color: Color::WHITE, - } - } - - fn hovered(&self, style: &Self::Style) -> pick_list::Appearance { - let mut active = self.active(style); + }, + iced_widget::pick_list::Status::Hovered => { + let mut active = pick_list(_theme, iced_widget::pick_list::Status::Active); + + if let iced_core::Background::Color(ref mut color) = active.background { + color.r = (color.r + 0.05).min(1.0); + color.g = (color.g + 0.05).min(1.0); + color.b = (color.b + 0.05).min(1.0); + } - if let iced_core::Background::Color(ref mut color) = active.background { - color.r = (color.r + 0.05).min(1.0); - color.g = (color.g + 0.05).min(1.0); - color.b = (color.b + 0.05).min(1.0); + active } - - active - } -} - -struct MenuStyle; - -impl iced_style::menu::StyleSheet for MenuStyle { - type Style = iced_style::Theme; - - fn appearance(&self, _style: &Self::Style) -> iced_style::menu::Appearance { - let accent = Color::from_rgba8(160, 81, 255, 1.0); - iced_style::menu::Appearance { - text_color: Color::WHITE, - background: iced_core::Background::from(iced_core::Color::from_rgba8(27, 25, 32, 1.0)), - border: Border { - width: 0.0, - radius: Radius::from(5.0), - color: SURFACE, - }, - selected_text_color: Color::WHITE, - selected_background: iced_core::Background::Color(accent), + iced_widget::pick_list::Status::Opened => { + pick_list(_theme, iced_widget::pick_list::Status::Active) } } } -pub fn button() -> iced_style::theme::Button { - iced_style::theme::Button::Custom(Box::new(ButtonStyle)) +pub fn pick_list_menu(_theme: &Theme) -> iced_widget::overlay::menu::Style { + let accent = Color::from_rgba8(160, 81, 255, 1.0); + iced_widget::overlay::menu::Style { + text_color: Color::WHITE, + background: iced_core::Background::from(iced_core::Color::from_rgba8(27, 25, 32, 1.0)), + border: Border { + width: 0.0, + radius: Radius::from(5.0), + color: SURFACE, + }, + selected_text_color: Color::WHITE, + selected_background: iced_core::Background::Color(accent), + } } -struct ButtonStyle; - -impl iced_style::button::StyleSheet for ButtonStyle { - type Style = iced_style::Theme; - - fn active(&self, _style: &Self::Style) -> button::Appearance { - button::Appearance { +pub fn button(_theme: &Theme, status: iced_widget::button::Status) -> iced_widget::button::Style { + match status { + iced_widget::button::Status::Active => iced_widget::button::Style { text_color: Color::WHITE, border: Border { width: 0.0, @@ -88,179 +71,135 @@ impl iced_style::button::StyleSheet for ButtonStyle { 74, 68, 88, 1.0, ))), ..Default::default() - } - } - - fn hovered(&self, style: &Self::Style) -> button::Appearance { - let mut active = self.active(style); - - if let Some(iced_core::Background::Color(ref mut color)) = active.background { - color.r = (color.r + 0.05).min(1.0); - color.g = (color.g + 0.05).min(1.0); - color.b = (color.b + 0.05).min(1.0); - } - - active - } -} - -pub fn round_button() -> iced_style::theme::Button { - iced_style::theme::Button::Custom(Box::new(RoundButtonStyle)) -} - -struct RoundButtonStyle; - -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: Border { - radius: Radius::from(f32::MAX), - ..def.border - }, - ..def - } - } + }, + iced_widget::button::Status::Hovered => { + let mut active = button(_theme, iced_widget::button::Status::Active); + + if let Some(iced_core::Background::Color(ref mut color)) = active.background { + color.r = (color.r + 0.05).min(1.0); + color.g = (color.g + 0.05).min(1.0); + color.b = (color.b + 0.05).min(1.0); + } - fn hovered(&self, style: &Self::Style) -> button::Appearance { - let def = ButtonStyle::hovered(&ButtonStyle, style); - button::Appearance { - border: Border { - radius: Radius::from(f32::MAX), - ..def.border - }, - ..def + active } + _ => button(_theme, iced_widget::button::Status::Active), } } -pub fn _checkbox() -> iced_style::theme::Checkbox { - iced_style::theme::Checkbox::Custom(Box::new(CheckboxStyle)) -} - -#[allow(unused)] -struct CheckboxStyle; - -impl iced_style::checkbox::StyleSheet for CheckboxStyle { - type Style = iced_style::Theme; - - fn active(&self, _style: &Self::Style, is_checked: bool) -> iced_style::checkbox::Appearance { - let active = Color::from_rgba8(160, 81, 255, 1.0); - iced_style::checkbox::Appearance { - background: if is_checked { active } else { SURFACE }.into(), - text_color: Some(Color::WHITE), - border: Border { - radius: Radius::from(2.0), - width: 1.0, - color: active, - }, - icon_color: Color::WHITE, +pub fn round_button( + theme: &Theme, + status: iced_widget::button::Status, +) -> iced_widget::button::Style { + match status { + iced_widget::button::Status::Active => { + let def = button(theme, status); + iced_widget::button::Style { + border: Border { + radius: Radius::from(f32::MAX), + ..def.border + }, + ..def + } } - } - - fn hovered(&self, style: &Self::Style, is_checked: bool) -> iced_style::checkbox::Appearance { - let active = Color::from_rgba8(160, 81, 255, 1.0); - iced_style::checkbox::Appearance { - background: Color { - a: 0.8, - ..if is_checked { active } else { SURFACE } + iced_widget::button::Status::Hovered => { + let def = button(theme, status); + iced_widget::button::Style { + border: Border { + radius: Radius::from(f32::MAX), + ..def.border + }, + ..def } - .into(), - ..self.active(style, is_checked) } - } - - fn disabled(&self, style: &Self::Style, is_checked: bool) -> iced_style::checkbox::Appearance { - // TODO - self.active(style, is_checked) + _ => round_button(theme, iced_widget::button::Status::Active), } } -pub fn toggler() -> iced_style::theme::Toggler { - iced_style::theme::Toggler::Custom(Box::new(TogglerStyle)) -} - -struct TogglerStyle; - -impl iced_style::toggler::StyleSheet for TogglerStyle { - type Style = iced_style::Theme; - - fn active(&self, _style: &Self::Style, is_active: bool) -> iced_style::toggler::Appearance { - let default = ::active( - &iced_style::Theme::Dark, - &iced_style::theme::Toggler::Default, - is_active, - ); - - if is_active { - iced_style::toggler::Appearance { - background: Color::from_rgba8(160, 81, 255, 1.0), - ..default +pub fn toggler(theme: &Theme, status: iced_widget::toggler::Status) -> iced_widget::toggler::Style { + match status { + iced_widget::toggler::Status::Active { is_toggled } => { + let default = iced_widget::toggler::default(theme, status); + + if is_toggled { + iced_widget::toggler::Style { + background: Color::from_rgba8(160, 81, 255, 1.0), + ..default + } + } else { + default } - } else { - default } - } - - fn hovered(&self, _style: &Self::Style, is_active: bool) -> iced_style::toggler::Appearance { - if is_active { - let default = ::active( - &iced_style::Theme::Dark, - &iced_style::theme::Toggler::Default, - is_active, - ); - - iced_style::toggler::Appearance { - background: Color::from_rgba8(180, 101, 255, 1.0), - ..default + iced_widget::toggler::Status::Hovered { is_toggled } => { + if is_toggled { + let default = iced_widget::toggler::default(theme, status); + iced_widget::toggler::Style { + background: Color::from_rgba8(180, 101, 255, 1.0), + ..default + } + } else { + iced_widget::toggler::default(theme, status) } - } else { - ::hovered( - &iced_style::Theme::Dark, - &iced_style::theme::Toggler::Default, - is_active, - ) } } } -pub fn scrollable() -> iced_style::theme::Scrollable { - iced_style::theme::Scrollable::Custom(Box::new(ScrollableStyle)) -} - -struct ScrollableStyle; - -impl iced_style::scrollable::StyleSheet for ScrollableStyle { - type Style = iced_style::Theme; - - fn active(&self, style: &Self::Style) -> iced_style::scrollable::Appearance { - self.hovered(style, true) - } - - fn hovered( - &self, - _style: &Self::Style, - is_mouse_over_scrollbar: bool, - ) -> iced_style::scrollable::Appearance { - iced_style::scrollable::Appearance { - container: iced_style::container::Appearance::default(), - scrollbar: iced_style::scrollable::Scrollbar { +pub fn scrollable( + _theme: &Theme, + status: iced_widget::scrollable::Status, +) -> iced_widget::scrollable::Style { + match status { + iced_widget::scrollable::Status::Active => scrollable( + _theme, + iced_widget::scrollable::Status::Hovered { + is_horizontal_scrollbar_hovered: false, + is_vertical_scrollbar_hovered: false, + }, + ), + iced_widget::scrollable::Status::Hovered { + is_horizontal_scrollbar_hovered, + is_vertical_scrollbar_hovered, + } => iced_widget::scrollable::Style { + container: iced_widget::container::Style::default(), + vertical_scrollbar: iced_widget::scrollable::Scrollbar { background: Some(iced_core::Background::Color(Color::from_rgba8( 37, 35, 42, 1.0, ))), - border: Border::with_radius(10.0), - scroller: iced_style::scrollable::Scroller { - color: if is_mouse_over_scrollbar { + border: Border::rounded(10.0), + scroller: iced_widget::scrollable::Scroller { + color: if is_vertical_scrollbar_hovered { Color::from_rgba8(87, 81, 101, 1.0) } else { Color::from_rgba8(74, 68, 88, 1.0) }, - border: Border::with_radius(10.0), + border: Border::rounded(10.0), + }, + }, + horizontal_scrollbar: iced_widget::scrollable::Scrollbar { + background: Some(iced_core::Background::Color(Color::from_rgba8( + 37, 35, 42, 1.0, + ))), + border: Border::rounded(10.0), + scroller: iced_widget::scrollable::Scroller { + color: if is_horizontal_scrollbar_hovered { + Color::from_rgba8(87, 81, 101, 1.0) + } else { + Color::from_rgba8(74, 68, 88, 1.0) + }, + border: Border::rounded(10.0), }, }, gap: None, - } + }, + iced_widget::scrollable::Status::Dragged { + is_horizontal_scrollbar_dragged, + is_vertical_scrollbar_dragged, + } => scrollable( + _theme, + iced_widget::scrollable::Status::Hovered { + is_horizontal_scrollbar_hovered: is_horizontal_scrollbar_dragged, + is_vertical_scrollbar_hovered: is_vertical_scrollbar_dragged, + }, + ), } } diff --git a/neothesia/src/scene/menu_scene/iced_menu/tracks.rs b/neothesia/src/scene/menu_scene/iced_menu/tracks.rs index 8711a45e..b6c6932a 100644 --- a/neothesia/src/scene/menu_scene/iced_menu/tracks.rs +++ b/neothesia/src/scene/menu_scene/iced_menu/tracks.rs @@ -194,11 +194,11 @@ impl Page for TracksPage { let center = { let listen = button(centered_text("Listen Only")) .on_press(Event::AllTracksPlayer(PlayerConfig::Auto)) - .style(theme::button()); + .style(theme::button); let play_along = button(centered_text("Play Along")) .on_press(Event::AllTracksPlayer(PlayerConfig::Human)) - .style(theme::button()); + .style(theme::button); row![listen, play_along] .width(Length::Shrink) diff --git a/neothesia/src/scene/menu_scene/icons.rs b/neothesia/src/scene/menu_scene/icons.rs index a0bb5a89..d0f3591c 100644 --- a/neothesia/src/scene/menu_scene/icons.rs +++ b/neothesia/src/scene/menu_scene/icons.rs @@ -1,4 +1,4 @@ -use iced_style::Theme; +use iced_core::Theme; use super::Renderer; diff --git a/wgpu-jumpstart/src/gpu.rs b/wgpu-jumpstart/src/gpu.rs index 25d9d660..01d0d7a1 100644 --- a/wgpu-jumpstart/src/gpu.rs +++ b/wgpu-jumpstart/src/gpu.rs @@ -116,15 +116,18 @@ impl Gpu { }); } - pub fn submit(&mut self) { + pub fn take(&mut self) -> wgpu::CommandEncoder { let new_encoder = self .device .create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); // We swap the current decoder by a new one here, so we can finish the // current frame - let encoder = std::mem::replace(&mut self.encoder, new_encoder); + std::mem::replace(&mut self.encoder, new_encoder) + } + pub fn submit(&mut self) { + let encoder = self.take(); self.queue.submit(Some(encoder.finish())); } }