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 to iced 0.12 #148

Merged
merged 1 commit into from
Feb 18, 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
42 changes: 26 additions & 16 deletions Cargo.lock

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

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="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"] }
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"] }

[[bin]]
name = "neothesia"
Expand Down
6 changes: 3 additions & 3 deletions neothesia/src/iced_utils/iced_clipboard.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use iced_core::Clipboard;
use iced_core::{clipboard::Kind, Clipboard};

pub struct DummyClipboard {}

impl Clipboard for DummyClipboard {
fn read(&self) -> Option<String> {
fn read(&self, _kind: Kind) -> Option<String> {
None
}

fn write(&mut self, _contents: String) {}
fn write(&mut self, _kind: Kind, _contents: String) {}
}
2 changes: 1 addition & 1 deletion neothesia/src/scene/menu_scene/iced_menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ fn centered_text<'a>(label: impl ToString) -> iced_widget::Text<'a, Theme, Rende
fn top_padded<'a, MSG: 'a>(
content: impl Into<Element<'a, MSG>>,
) -> iced_widget::Column<'a, MSG, Theme, Renderer> {
let spacer = vertical_space(Length::FillPortion(1));
let spacer = vertical_space().height(Length::FillPortion(1));
let content = container(content)
.height(Length::FillPortion(4))
.center_x()
Expand Down
15 changes: 9 additions & 6 deletions neothesia/src/scene/menu_scene/iced_menu/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
output_manager::OutputDescriptor,
scene::menu_scene::{
icons,
layout::{BarLayout, Layout, PushIf},
layout::{BarLayout, Layout},
neo_btn::NeoBtn,
preferences_group, scroll_listener,
},
Expand Down Expand Up @@ -115,7 +115,7 @@ pub(super) fn update(
fn output_group<'a>(data: &'a Data, target: &Target) -> Element<'a, SettingsMessage> {
let output_settings = {
let output_list = pick_list(
&data.outputs,
data.outputs.as_ref(),
data.selected_output.clone(),
SettingsMessage::SelectOutput,
)
Expand Down Expand Up @@ -153,16 +153,19 @@ fn output_group<'a>(data: &'a Data, target: &Target) -> Element<'a, SettingsMess
preferences_group::PreferencesGroup::new()
.title("Output")
.push(output_settings)
.push_if(synth_settings)
.push_maybe(synth_settings)
.build()
}

fn input_group<'a>(data: &'a Data, _target: &Target) -> Element<'a, SettingsMessage> {
let inputs = &data.inputs;
let selected_input = data.selected_input.clone();

let input_list =
pick_list(inputs, selected_input, SettingsMessage::SelectInput).style(theme::pick_list());
let input_list = pick_list(
data.inputs.as_ref(),
selected_input,
SettingsMessage::SelectInput,
)
.style(theme::pick_list());

preferences_group::PreferencesGroup::new()
.title("Input")
Expand Down
2 changes: 1 addition & 1 deletion neothesia/src/scene/menu_scene/iced_menu/tracks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub(super) fn view<'a>(_data: &'a Data, target: &Target) -> Element<'a, Message>
.padding(30.0)
.align_items(Alignment::Center);

let column = col![vertical_space(Length::Fixed(30.0)), column]
let column = col![vertical_space().height(Length::Fixed(30.0)), column]
.align_items(Alignment::Center)
.width(Length::Fill);

Expand Down
54 changes: 7 additions & 47 deletions neothesia/src/scene/menu_scene/layout.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::iced_utils::iced_state::Element;
use iced_core::{Alignment, Length, Renderer};
use iced_style::Theme;
use iced_core::{Alignment, Length};
use iced_widget::{column as col, row};

pub struct Layout<'a, Message> {
Expand Down Expand Up @@ -41,7 +40,7 @@ impl<'a, M: 'static> Layout<'a, M> {
}

pub fn build(self) -> Element<'a, M> {
let body = col![].push_if(self.body);
let body = col![].push_maybe(self.body);
let body = col![body]
.width(Length::Fill)
.height(Length::Fill)
Expand All @@ -57,9 +56,9 @@ impl<'a, M: 'static> Layout<'a, M> {
});

col![]
.push_if(top)
.push_maybe(top)
.push(body)
.push_if(bottom)
.push_maybe(bottom)
.width(Length::Fill)
.height(Length::Fill)
.into()
Expand Down Expand Up @@ -110,9 +109,9 @@ impl<'a, M: 'static> BarLayout<'a, M> {
}

pub fn build(self) -> Element<'a, M> {
let left = row![].push_if(self.left).width(Length::Fill);
let center = row![].push_if(self.center).width(Length::Fill);
let right = row![].push_if(self.right).width(Length::Fill);
let left = row![].push_maybe(self.left).width(Length::Fill);
let center = row![].push_maybe(self.center).width(Length::Fill);
let right = row![].push_maybe(self.right).width(Length::Fill);

row![left, center, right]
.align_items(Alignment::Center)
Expand All @@ -125,42 +124,3 @@ impl<'a, M: 'static> From<BarLayout<'a, M>> for Element<'a, M> {
val.build()
}
}

pub trait PushIf<'a, M, R> {
fn push_if(self, item: Option<impl Into<iced_core::Element<'a, M, Theme, 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 {
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 {
self
}
}
}

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, Theme, super::Renderer>>>,
) -> Self {
if let Some(item) = item {
self.push(item)
} else {
self
}
}
}
24 changes: 16 additions & 8 deletions neothesia/src/scene/menu_scene/preferences_group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use iced_widget::{column, container, row, text};

use crate::iced_utils::iced_state::Element;

use super::{layout::PushIf, Renderer};
use super::Renderer;

mod theme;

Expand Down Expand Up @@ -43,11 +43,19 @@ impl<'a, MSG: 'a> PreferencesGroup<'a, MSG> {
self
}

pub fn push_maybe(self, child: Option<impl Into<Element<'a, MSG>>>) -> Self {
if let Some(child) = child {
self.push(child)
} else {
self
}
}

pub fn build(self) -> Element<'a, MSG> {
let header = self.header.map(|header| group_header(header));
let body = group_body(self.items);

column![].push_if(header).push(body).spacing(14).into()
column![].push_maybe(header).push(body).spacing(14).into()
}
}

Expand Down Expand Up @@ -86,9 +94,9 @@ fn tripple_split<'a, T: 'a>(
) -> iced_widget::Row<'a, T, Theme, Renderer> {
let mut row = row![];

row = row.push(row![].push_if(prefix).width(Length::Shrink));
row = row.push(row![].push_if(center).width(Length::Fill));
row = row.push(row![].push_if(suffix).width(Length::Shrink));
row = row.push(row![].push_maybe(prefix).width(Length::Shrink));
row = row.push(row![].push_maybe(center).width(Length::Fill));
row = row.push(row![].push_maybe(suffix).width(Length::Shrink));

row.align_items(iced_core::Alignment::Center).spacing(6)
}
Expand All @@ -106,7 +114,7 @@ fn group_header<'a, T: 'a>(data: PreferencesGroupHeader) -> Element<'a, T> {
.subtitle
.map(|title| text(title).style(theme::subtitle()).size(12.2));

let header = column![].push_if(title).push_if(subtitle);
let header = column![].push_maybe(title).push_maybe(subtitle);

tripple_split(None, Some(header.into()), None).into()
}
Expand All @@ -116,8 +124,8 @@ fn title<'a, T: 'a>(
subtitle: Option<String>,
) -> iced_widget::Column<'a, T, Theme, Renderer> {
column![]
.push_if(title.map(|title| text(title).size(14.6)))
.push_if(subtitle.map(|subtitle| text(subtitle).size(12.2).style(theme::subtitle())))
.push_maybe(title.map(|title| text(title).size(14.6)))
.push_maybe(subtitle.map(|subtitle| text(subtitle).size(12.2).style(theme::subtitle())))
}

pub struct ActionRow<'a, MSG> {
Expand Down
Loading