Skip to content
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
3 changes: 2 additions & 1 deletion Cargo.lock

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

3 changes: 2 additions & 1 deletion crates/twill-iced/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ categories = ["gui", "rendering"]
[dependencies]
twill-core = { path = "../twill-core", version = "0.3.0" }
twill-backend-common = { path = "../twill-backend-common", version = "0.3.0" }
iced = { version = "0.14", default-features = false, features = ["advanced", "image", "tokio", "canvas", "wgpu", "wayland", "x11"] }
iced_core = "0.14"
iced_widget = { version = "0.14", features = ["canvas", "wgpu"] }

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]
28 changes: 14 additions & 14 deletions crates/twill-iced/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ pub enum TextDirection {
RightToLeft,
}

pub fn to_color(color: Color) -> iced::Color {
pub fn to_color(color: Color) -> iced_core::Color {
super::widgets::to_color(color)
}

pub fn to_color_value(value: ColorValue) -> iced::Color {
pub fn to_color_value(value: ColorValue) -> iced_core::Color {
super::widgets::to_color_value(value)
}

pub fn to_padding(spacing: Spacing) -> iced::Padding {
pub fn to_padding(spacing: Spacing) -> iced_core::Padding {
super::widgets::to_padding(spacing)
}

Expand All @@ -37,19 +37,19 @@ pub fn to_aspect_ratio(ratio: AspectRatio) -> Option<f32> {
super::widgets::to_aspect_ratio(ratio)
}

pub fn to_content_fit(fit: ObjectFit) -> iced::ContentFit {
pub fn to_content_fit(fit: ObjectFit) -> iced_core::ContentFit {
super::widgets::to_content_fit(fit)
}

pub fn to_shadow_with_color(shadow: Shadow, color: ShadowColor) -> iced::Shadow {
pub fn to_shadow_with_color(shadow: Shadow, color: ShadowColor) -> iced_core::Shadow {
super::widgets::to_shadow_with_color(shadow, color)
}

pub fn to_shadow_layers_with_color(shadow: Shadow, color: ShadowColor) -> Vec<iced::Shadow> {
pub fn to_shadow_layers_with_color(shadow: Shadow, color: ShadowColor) -> Vec<iced_core::Shadow> {
super::widgets::to_shadow_layers_with_color(shadow, color)
}

pub fn to_shadow(shadow: Shadow, color: Color) -> iced::Shadow {
pub fn to_shadow(shadow: Shadow, color: Color) -> iced_core::Shadow {
super::widgets::to_shadow(shadow, color)
}

Expand All @@ -61,41 +61,41 @@ pub fn resolve_font_size(size: FontSize, custom_properties: &[(&str, f32)]) -> O
super::widgets::resolve_font_size(size, custom_properties)
}

pub fn to_font_weight(weight: FontWeight) -> iced::font::Weight {
pub fn to_font_weight(weight: FontWeight) -> iced_core::font::Weight {
super::widgets::to_font_weight(weight)
}

pub fn to_text_alignment(align: TextAlign) -> iced::widget::text::Alignment {
pub fn to_text_alignment(align: TextAlign) -> iced_core::widget::text::Alignment {
super::widgets::to_text_alignment(align)
}

pub fn to_text_alignment_with_direction(
align: TextAlign,
direction: TextDirection,
) -> iced::widget::text::Alignment {
) -> iced_core::widget::text::Alignment {
super::widgets::to_text_alignment_with_direction(align, direction)
}

pub fn to_semantic_color_with_theme<S: SemanticThemeSource + ?Sized>(
semantic: SemanticColor,
semantic_theme: &S,
variant: ThemeVariant,
) -> iced::Color {
) -> iced_core::Color {
super::widgets::to_semantic_color_with_theme(semantic, semantic_theme, variant)
}

pub fn to_semantic_color(semantic: SemanticColor, variant: ThemeVariant) -> iced::Color {
pub fn to_semantic_color(semantic: SemanticColor, variant: ThemeVariant) -> iced_core::Color {
super::widgets::to_semantic_color(semantic, variant)
}

pub fn to_duration(duration: TransitionDuration) -> std::time::Duration {
super::widgets::to_duration(duration)
}

pub fn to_easing(easing: Easing) -> iced::animation::Easing {
pub fn to_easing(easing: Easing) -> iced_core::animation::Easing {
super::widgets::to_easing(easing)
}

pub fn to_interaction(cursor: Cursor) -> iced::mouse::Interaction {
pub fn to_interaction(cursor: Cursor) -> iced_core::mouse::Interaction {
super::widgets::to_interaction(cursor)
}
18 changes: 9 additions & 9 deletions crates/twill-iced/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
mod convert;
mod widgets;

use iced::ContentFit;
use iced_core::ContentFit;
use twill_core::tokens::{
AspectRatio, Blur, BorderRadius, Color, ColorValue, Cursor, Easing, FontSize, FontWeight,
Shadow, Spacing, TextAlign, TransitionDuration,
Expand Down Expand Up @@ -50,7 +50,7 @@ pub trait ToIced: private::Sealed {

impl private::Sealed for Color {}
impl ToIced for Color {
type Output = iced::Color;
type Output = iced_core::Color;

fn to_iced(self) -> Self::Output {
to_color(self)
Expand All @@ -59,7 +59,7 @@ impl ToIced for Color {

impl private::Sealed for ColorValue {}
impl ToIced for ColorValue {
type Output = iced::Color;
type Output = iced_core::Color;

fn to_iced(self) -> Self::Output {
to_color_value(self)
Expand All @@ -68,7 +68,7 @@ impl ToIced for ColorValue {

impl private::Sealed for Spacing {}
impl ToIced for Spacing {
type Output = iced::Padding;
type Output = iced_core::Padding;

fn to_iced(self) -> Self::Output {
to_padding(self)
Expand Down Expand Up @@ -113,7 +113,7 @@ impl ToIced for ObjectFit {

impl private::Sealed for Shadow {}
impl ToIced for Shadow {
type Output = iced::Shadow;
type Output = iced_core::Shadow;

fn to_iced(self) -> Self::Output {
to_shadow_with_color(self, twill_backend_common::ShadowColor::Default)
Expand All @@ -131,7 +131,7 @@ impl ToIced for FontSize {

impl private::Sealed for FontWeight {}
impl ToIced for FontWeight {
type Output = iced::font::Weight;
type Output = iced_core::font::Weight;

fn to_iced(self) -> Self::Output {
to_font_weight(self)
Expand All @@ -140,7 +140,7 @@ impl ToIced for FontWeight {

impl private::Sealed for TextAlign {}
impl ToIced for TextAlign {
type Output = iced::widget::text::Alignment;
type Output = iced_core::widget::text::Alignment;

fn to_iced(self) -> Self::Output {
to_text_alignment(self)
Expand All @@ -158,7 +158,7 @@ impl ToIced for TransitionDuration {

impl private::Sealed for Easing {}
impl ToIced for Easing {
type Output = iced::animation::Easing;
type Output = iced_core::animation::Easing;

fn to_iced(self) -> Self::Output {
to_easing(self)
Expand All @@ -167,7 +167,7 @@ impl ToIced for Easing {

impl private::Sealed for Cursor {}
impl ToIced for Cursor {
type Output = iced::mouse::Interaction;
type Output = iced_core::mouse::Interaction;

fn to_iced(self) -> Self::Output {
to_interaction(self)
Expand Down
13 changes: 11 additions & 2 deletions crates/twill-iced/src/widgets/common.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
use iced::Size;
use iced_core::Size;
use twill_core::style::Style;
use twill_core::tokens::{ColorValue, Container, Spacing};
use twill_core::utilities::Columns;

pub(super) fn apply_opacity_to_color(mut color: iced::Color, opacity: f32) -> iced::Color {
/// A generic widget.
///
/// This is an alias of an `iced_native` element with a default `Renderer`.
pub(super) type Element<'a, Message, Theme = iced_core::Theme, Renderer = iced_widget::Renderer> =
iced_core::Element<'a, Message, Theme, Renderer>;

pub(super) fn apply_opacity_to_color(
mut color: iced_core::Color,
opacity: f32,
) -> iced_core::Color {
if opacity.is_finite() {
color.a *= opacity.clamp(0.0, 1.0);
}
Expand Down
42 changes: 21 additions & 21 deletions crates/twill-iced/src/widgets/container.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use iced::widget::{canvas, stack};
use iced::{Point, Rectangle, Renderer, Size, Theme, border, mouse};
use iced_core::{Point, Rectangle, Size, Theme, border, mouse};
use iced_widget::{Renderer, canvas, stack};
use twill_core::style::Style;
use twill_core::tokens::BorderStyle;

Expand All @@ -15,9 +15,9 @@ use twill_backend_common::ShadowColor;
use twill_core::tokens::{SemanticThemeVars, ThemeVariant};

pub fn styled_container<'a, Message: Clone + 'a>(
content: iced::Element<'a, Message>,
content: super::common::Element<'a, Message>,
style: &Style,
) -> iced::widget::Container<'a, Message> {
) -> iced_widget::Container<'a, Message> {
styled_container_with_custom_properties_and_semantic_theme(
content,
style,
Expand All @@ -32,11 +32,11 @@ pub fn styled_container_with_semantic_theme<
Message: Clone + 'a,
S: SemanticThemeSource + ?Sized,
>(
content: iced::Element<'a, Message>,
content: super::common::Element<'a, Message>,
style: &Style,
semantic_theme: &S,
variant: ThemeVariant,
) -> iced::widget::Container<'a, Message> {
) -> iced_widget::Container<'a, Message> {
styled_container_with_custom_properties_and_semantic_theme(
content,
style,
Expand All @@ -48,10 +48,10 @@ pub fn styled_container_with_semantic_theme<

/// Create a styled container with twill Style and explicit custom-property values.
pub fn styled_container_with_custom_properties<'a, Message: Clone + 'a>(
content: iced::Element<'a, Message>,
content: super::common::Element<'a, Message>,
style: &Style,
custom_properties: &[(&str, f32)],
) -> iced::widget::Container<'a, Message> {
) -> iced_widget::Container<'a, Message> {
styled_container_with_custom_properties_and_semantic_theme(
content,
style,
Expand All @@ -66,12 +66,12 @@ pub(super) fn styled_container_with_custom_properties_and_semantic_theme<
Message: Clone + 'a,
S: SemanticThemeSource + ?Sized,
>(
content: iced::Element<'a, Message>,
content: super::common::Element<'a, Message>,
style: &Style,
custom_properties: &[(&str, f32)],
semantic_theme: &S,
variant: ThemeVariant,
) -> iced::widget::Container<'a, Message> {
) -> iced_widget::Container<'a, Message> {
let opacity = resolved_opacity(style);
let padding = style
.padding_value()
Expand Down Expand Up @@ -107,7 +107,7 @@ pub(super) fn styled_container_with_custom_properties_and_semantic_theme<
})
.map(to_color_value)
.map(|color| apply_opacity_to_color(color, opacity))
.unwrap_or(iced::Color::TRANSPARENT);
.unwrap_or(iced_core::Color::TRANSPARENT);
let border_style = style.border_style_value().unwrap_or(BorderStyle::Solid);
let border_width = base_border_width;
let shadow_layers = style
Expand All @@ -125,13 +125,13 @@ pub(super) fn styled_container_with_custom_properties_and_semantic_theme<

match border_style {
BorderStyle::Solid => {
let mut container = iced::widget::container(content);
let mut container = iced_widget::container(content);
if let Some(p) = padding {
container = container.padding(p);
}
let base = container.style(move |_| iced::widget::container::Style {
background: bg_color.map(iced::Background::Color),
border: iced::Border {
let base = container.style(move |_| iced_widget::container::Style {
background: bg_color.map(iced_core::Background::Color),
border: iced_core::Border {
radius: border_radius.into(),
width: border_width,
color: border_color,
Expand All @@ -142,7 +142,7 @@ pub(super) fn styled_container_with_custom_properties_and_semantic_theme<
wrap_with_shadow_layers(base.into(), &shadow_layers, border_radius)
}
_ => {
let mut content_layer = iced::widget::container(content);
let mut content_layer = iced_widget::container(content);
if let Some(p) = padding {
content_layer = content_layer.padding(p);
}
Expand All @@ -154,10 +154,10 @@ pub(super) fn styled_container_with_custom_properties_and_semantic_theme<
border_color,
background: bg_color,
})
.width(iced::Length::Fill)
.height(iced::Length::Fill);
.width(iced_core::Length::Fill)
.height(iced_core::Length::Fill);

let base = iced::widget::container(stack![border_layer, content_layer]);
let base = iced_widget::container(stack![border_layer, content_layer]);
wrap_with_shadow_layers(base.into(), &shadow_layers, border_radius)
}
}
Expand All @@ -167,8 +167,8 @@ struct BorderCanvas {
border_style: BorderStyle,
border_width: f32,
border_radius: f32,
border_color: iced::Color,
background: Option<iced::Color>,
border_color: iced_core::Color,
background: Option<iced_core::Color>,
}

impl<Message> canvas::Program<Message> for BorderCanvas {
Expand Down
Loading
Loading