Skip to content

Commit

Permalink
Update to latest iced (1/2)
Browse files Browse the repository at this point in the history
  • Loading branch information
m00nwtchr committed Jul 23, 2024
1 parent d1e9ea0 commit b1ec180
Show file tree
Hide file tree
Showing 15 changed files with 1,888 additions and 1,355 deletions.
1,944 changes: 1,155 additions & 789 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ codegen-units = 1
inherits = "test"

[dependencies]
iced = "0.8"
iced_lazy = "0.5"
iced_native = "0.9"
iced = { version = "0.12", features = ["lazy", "advanced"] }
#iced_lazy = "0.6"
#iced_native = "0.10"

# iced_style = "0.5"
# iced = { git = "https://github.com/iced-rs/iced" }
# iced_lazy = { git = "https://github.com/iced-rs/iced" }
Expand Down
39 changes: 23 additions & 16 deletions src/component/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use iced::{
widget::{column, row, text, Column},
Alignment, Length,
};
use iced_lazy::Component;
use std::{cell::RefCell, rc::Rc};

use crate::widget::dots;
use crate::{
fl,
i18n::flt,
widget::dots::{Shape, SheetDots},
Element, H2_SIZE, TITLE_SPACING,
};
use cofd::{
character::{
modifier::ModifierTarget,
traits::{AttributeCategory, TraitCategory},
},
prelude::*,
};

use crate::{
fl,
i18n::flt,
widget::dots::{Shape, SheetDots},
Element, H2_SIZE, TITLE_SPACING,
use iced::widget::{component, Component};
use iced::{
widget::{column, row, text, Column},
Alignment, Length,
};

pub struct AttributeBar<Message> {
Expand Down Expand Up @@ -50,7 +50,10 @@ impl<Message> AttributeBar<Message> {
}
}

fn mk_attr_col(&self, character: &Character, cat: TraitCategory) -> Element<Event> {
fn mk_attr_col<Theme>(&self, character: &Character, cat: TraitCategory) -> Element<Event, Theme>
where
Theme: text::StyleSheet + dots::StyleSheet + 'static,
{
let mut col1 = Column::new().spacing(3);
let mut col2 = Column::new()
.spacing(5)
Expand Down Expand Up @@ -81,15 +84,18 @@ impl<Message> AttributeBar<Message> {
}
}

impl<Message> Component<Message, iced::Renderer> for AttributeBar<Message> {
impl<Message, Theme> Component<Message, Theme> for AttributeBar<Message>
where
Theme: text::StyleSheet + dots::StyleSheet + 'static,
{
type State = ();
type Event = Event;

fn update(&mut self, _state: &mut Self::State, event: Self::Event) -> Option<Message> {
Some((self.on_change)(event.0, event.1))
}

fn view(&self, _state: &Self::State) -> Element<Self::Event> {
fn view(&self, _state: &Self::State) -> Element<Event, Theme> {
let character = self.character.borrow();

column![
Expand All @@ -116,11 +122,12 @@ impl<Message> Component<Message, iced::Renderer> for AttributeBar<Message> {
}
}

impl<'a, Message> From<AttributeBar<Message>> for Element<'a, Message>
impl<'a, Message, Theme> From<AttributeBar<Message>> for Element<'a, Message, Theme>
where
Message: 'a,
Theme: text::StyleSheet + dots::StyleSheet + 'static,
{
fn from(info_bar: AttributeBar<Message>) -> Self {
iced_lazy::component(info_bar)
component(info_bar)
}
}
159 changes: 104 additions & 55 deletions src/component/info.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use iced::widget::{component, container, scrollable, Component};
use iced::{
widget::{column, pick_list, row, text, text_input, Column},
Alignment, Length,
};
use iced_lazy::Component;
use std::{cell::RefCell, rc::Rc};

use cofd::{
character::InfoTrait,
prelude::*,
splat::{Splat, XSplat, YSplat, ZSplat},
};

use crate::{
fl,
i18n::{flt, Translated},
Element, INPUT_PADDING,
};
use cofd::{
character::InfoTrait,
prelude::*,
splat::{Splat, XSplat, YSplat, ZSplat},
};
use iced::overlay::menu;

pub struct InfoBar<Message> {
character: Rc<RefCell<Character>>,
Expand Down Expand Up @@ -46,7 +46,14 @@ impl<Message> InfoBar<Message> {
}
}

fn mk_info_col(&self, info: Vec<InfoTrait>, character: &Character) -> Element<Event> {
fn mk_info_col<Theme>(
&self,
info: Vec<InfoTrait>,
character: &Character,
) -> Element<Event, Theme>
where
Theme: text_input::StyleSheet + text::StyleSheet + 'static,
{
let mut col1 = Column::new().spacing(3);
let mut col2 = Column::new()
.spacing(3)
Expand Down Expand Up @@ -80,22 +87,30 @@ impl<Message> InfoBar<Message> {

col1 = col1.push(text(format!("{}:", flt(msg, attribute).unwrap())));
col2 = col2.push(
text_input("", character.info.get(_trait), move |val| {
Event::InfoTraitChanged(val, _trait)
})
.padding(INPUT_PADDING),
text_input("", character.info.get(_trait))
.on_input(move |val| Event::InfoTraitChanged(val, _trait))
.padding(INPUT_PADDING),
);
}

row![col1, col2].width(Length::Fill).spacing(5).into()
}
}

impl<Message> Component<Message, iced::Renderer> for InfoBar<Message> {
impl<Message, Theme> Component<Message, Theme> for InfoBar<Message>
where
Theme: text_input::StyleSheet + text::StyleSheet,
Theme: pick_list::StyleSheet
+ scrollable::StyleSheet
+ menu::StyleSheet
+ container::StyleSheet
+ 'static,
<Theme as menu::StyleSheet>::Style: From<<Theme as pick_list::StyleSheet>::Style>,
{
type State = ();
type Event = Event;

fn update(&mut self, _state: &mut Self::State, event: Self::Event) -> Option<Message> {
fn update(&mut self, _state: &mut Self::State, event: Event) -> Option<Message> {
let mut character = self.character.borrow_mut();

match event {
Expand Down Expand Up @@ -133,10 +148,10 @@ impl<Message> Component<Message, iced::Renderer> for InfoBar<Message> {
clippy::single_match_else,
clippy::too_many_lines
)]
fn view(&self, _state: &Self::State) -> Element<Self::Event> {
fn view(&self, _state: &Self::State) -> Element<Event, Theme> {
let character = self.character.borrow();

let col3: Element<Self::Event> = match character.splat {
let col3: Element<Event, Theme> = match character.splat {
Splat::Mortal => self.mk_info_col(
vec![InfoTrait::Age, InfoTrait::Faction, InfoTrait::GroupName],
&character,
Expand Down Expand Up @@ -167,53 +182,79 @@ impl<Message> Component<Message, iced::Renderer> for InfoBar<Message> {
let ysplat = character.splat.ysplat();
let zsplat = character.splat.zsplat();

let xsplat: Element<Self::Event> = if let Some(xsplat) = xsplat.clone() && xsplat.is_custom() {
text_input("", xsplat.name(), {
let xsplat = xsplat.clone();
move |val| {
let mut xsplat = xsplat.clone();
*xsplat.name_mut().unwrap() = val;
Event::XSplatChanged(xsplat)
}
}).padding(INPUT_PADDING)
.into()
let xsplat: Element<Event, Theme> = if let Some(xsplat) = xsplat.clone()
&& xsplat.is_custom()
{
text_input("", xsplat.name())
.on_input({
let xsplat = xsplat.clone();
move |val| {
let mut xsplat = xsplat.clone();
*xsplat.name_mut().unwrap() = val;
Event::XSplatChanged(xsplat)
}
})
.padding(INPUT_PADDING)
.into()
} else {
pick_list(xsplats, xsplat.map(Into::into), |val| Event::XSplatChanged(val.unwrap()))
pick_list(
xsplats,
xsplat.map(Into::<Translated<XSplat>>::into),
|val| Event::XSplatChanged(val.unwrap()),
)
.padding(INPUT_PADDING)
.width(Length::Fill).into()
.width(Length::Fill)
.into()
};

let ysplat: Element<Self::Event> = if let Some(ysplat) = ysplat.clone() && ysplat.is_custom() {
text_input("", ysplat.name(), {
let ysplat = ysplat.clone();
move |val| {
let mut ysplat = ysplat.clone();
*ysplat.name_mut().unwrap() = val;
Event::YSplatChanged(ysplat)
}
}).padding(INPUT_PADDING)
.into()
let ysplat: Element<Event, Theme> = if let Some(ysplat) = ysplat.clone()
&& ysplat.is_custom()
{
text_input("", ysplat.name())
.on_input({
let ysplat = ysplat.clone();
move |val| {
let mut ysplat = ysplat.clone();
*ysplat.name_mut().unwrap() = val;
Event::YSplatChanged(ysplat)
}
})
.padding(INPUT_PADDING)
.into()
} else {
pick_list(ysplats, ysplat.map(Into::into), |val| Event::YSplatChanged(val.unwrap()))
pick_list(
ysplats,
ysplat.map(Into::<Translated<YSplat>>::into),
|val| Event::YSplatChanged(val.unwrap()),
)
.padding(INPUT_PADDING)
.width(Length::Fill).into()
.width(Length::Fill)
.into()
};

let zsplat: Element<Self::Event> = if let Some(zsplat) = zsplat.clone() && zsplat.is_custom() {
text_input("", zsplat.name(), {
let zsplat = zsplat.clone();
move |val| {
let mut zsplat = zsplat.clone();
*zsplat.name_mut().unwrap() = val;
Event::ZSplatChanged(zsplat)
}
}).padding(INPUT_PADDING)
.into()
} else {
pick_list(zsplats, zsplat.map(Into::into), |val| Event::ZSplatChanged(val.unwrap()))
let zsplat: Element<Event, Theme> = if let Some(zsplat) = zsplat.clone()
&& zsplat.is_custom()
{
text_input("", zsplat.name())
.on_input({
let zsplat = zsplat.clone();
move |val| {
let mut zsplat = zsplat.clone();
*zsplat.name_mut().unwrap() = val;
Event::ZSplatChanged(zsplat)
}
})
.padding(INPUT_PADDING)
.width(Length::Fill)
.into()
} else {
pick_list(
zsplats,
zsplat.map(Into::<Translated<ZSplat>>::into),
|val| Event::ZSplatChanged(val.unwrap()),
)
.padding(INPUT_PADDING)
.width(Length::Fill)
.into()
};

row![
Expand Down Expand Up @@ -257,16 +298,24 @@ impl<Message> Component<Message, iced::Renderer> for InfoBar<Message> {
),
col3,
]
.width(Length::Fill)
.spacing(10)
.into()
}
}

impl<'a, Message> From<InfoBar<Message>> for Element<'a, Message>
impl<'a, Message, Theme> From<InfoBar<Message>> for Element<'a, Message, Theme>
where
Message: 'a,
Theme: text_input::StyleSheet + text::StyleSheet,
Theme: pick_list::StyleSheet
+ scrollable::StyleSheet
+ menu::StyleSheet
+ container::StyleSheet
+ 'static,
<Theme as menu::StyleSheet>::Style: From<<Theme as pick_list::StyleSheet>::Style>,
{
fn from(info_bar: InfoBar<Message>) -> Self {
iced_lazy::component(info_bar)
component(info_bar)
}
}
Loading

0 comments on commit b1ec180

Please sign in to comment.