Skip to content

Instantly share code, notes, and snippets.

@mtkennerly
Created March 19, 2024 03:45
Show Gist options
  • Save mtkennerly/993c3fbdd7ea770c0c28d268cf063664 to your computer and use it in GitHub Desktop.
Save mtkennerly/993c3fbdd7ea770c0c28d268cf063664 to your computer and use it in GitHub Desktop.
Iced: Container shadows are too big with `tiny-skia` and custom theme
[package]
name = "repro"
version = "0.1.0"
edition = "2021"
[dependencies]
iced = { version = "0.12.1", features = ["advanced"] }
use iced::{application, executor, Application, Border, Color, Shadow, Vector};
use iced::{Command, Element, Settings};
use iced::widget::{container, row, text};
pub fn main() -> iced::Result {
Repro::run(Settings::default())
}
struct Repro;
#[derive(Debug, Clone)]
enum Message {}
#[derive(Default)]
pub struct CustomTheme {}
#[derive(Clone, Default)]
pub struct ApplicationStyle;
impl application::StyleSheet for CustomTheme {
type Style = ApplicationStyle;
fn appearance(&self, _style: &Self::Style) -> iced::application::Appearance {
iced::application::Appearance {
background_color: Color::WHITE,
text_color: Color::BLACK,
}
}
}
#[derive(Clone, Default)]
pub struct ContainerStyle {}
impl container::StyleSheet for CustomTheme {
type Style = ContainerStyle;
fn appearance(&self, _style: &Self::Style) -> container::Appearance {
container::Appearance {
background: Some(Color::TRANSPARENT.into()),
border: Border {
color: Color::TRANSPARENT,
width: 0.0,
radius: 0.0.into(),
},
text_color: None,
shadow: Shadow {
color: Color::from_rgb8(255, 0, 0),
offset: Vector::ZERO,
blur_radius: 0.0,
},
}
}
}
#[derive(Clone, Default)]
pub struct TextStyle {}
impl text::StyleSheet for CustomTheme {
type Style = TextStyle;
fn appearance(&self, _style: Self::Style) -> text::Appearance {
text::Appearance {
color: None,
}
}
}
impl Application for Repro {
type Executor = executor::Default;
type Flags = ();
type Message = Message;
type Theme = CustomTheme;
fn new(_flags: ()) -> (Repro, Command<Self::Message>) {
(Repro, Command::none())
}
fn title(&self) -> String {
String::from("Repro")
}
fn update(&mut self, _message: Self::Message) -> Command<Self::Message> {
Command::none()
}
fn view(&self) -> Element<Self::Message, Self::Theme> {
container(row!["first", "second"].spacing(10)).into()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment