Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update iced to new styling API #180

Merged
merged 1 commit into from
Jun 21, 2024
Merged
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
102 changes: 41 additions & 61 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
] }
1 change: 0 additions & 1 deletion neothesia-iced-widgets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion neothesia-iced-widgets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
58 changes: 29 additions & 29 deletions neothesia-iced-widgets/src/neo_btn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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)
Expand Down Expand Up @@ -201,7 +199,7 @@ impl<'a, Message: Clone> Widget<Message, Theme, Renderer> for NeoBtn<'a, Message
&self,
tree: &Tree,
renderer: &mut Renderer,
theme: &iced_style::Theme,
theme: &Theme,
_style: &Style,
layout: Layout<'_>,
cursor: mouse::Cursor,
Expand All @@ -226,42 +224,44 @@ impl<'a, Message: Clone> Widget<Message, Theme, Renderer> 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
Expand Down
3 changes: 1 addition & 2 deletions neothesia-iced-widgets/src/piano_range.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Loading
Loading