Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into workaround-window…
Browse files Browse the repository at this point in the history
…s-issue-pt2
  • Loading branch information
dtzxporter committed Feb 12, 2024
2 parents c73d9a3 + 891f29e commit 38f5777
Show file tree
Hide file tree
Showing 15 changed files with 638 additions and 166 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `hovered` styling for `Svg` widget. [#2163](https://github.com/iced-rs/iced/pull/2163)
- `height` method for `TextEditor`. [#2221](https://github.com/iced-rs/iced/pull/2221)
- Customizable style for `TextEditor`. [#2159](https://github.com/iced-rs/iced/pull/2159)
- Customizable style for `QRCode`. [#2229](https://github.com/iced-rs/iced/pull/2229)
- Border width styling for `Toggler`. [#2219](https://github.com/iced-rs/iced/pull/2219)
- `RawText` variant for `Primitive` in `iced_graphics`. [#2158](https://github.com/iced-rs/iced/pull/2158)
- `Stream` support for `Command`. [#2150](https://github.com/iced-rs/iced/pull/2150)
Expand All @@ -38,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Custom` variant to `command::Action`. [#2146](https://github.com/iced-rs/iced/pull/2146)
- Mouse movement events for `MouseArea`. [#2147](https://github.com/iced-rs/iced/pull/2147)
- Dracula, Nord, Solarized, and Gruvbox variants for `Theme`. [#2170](https://github.com/iced-rs/iced/pull/2170)
- Catppuccin, Tokyo Night, Kanagawa, Moonfly, Nightfly and Oxocarbon variants for `Theme`. [#2233](https://github.com/iced-rs/iced/pull/2233)

- `From<T> where T: Into<PathBuf>` for `svg::Handle`. [#2235](https://github.com/iced-rs/iced/pull/2235)
- `on_open` and `on_close` handlers for `PickList`. [#2174](https://github.com/iced-rs/iced/pull/2174)
- Support for generic `Element` in `Tooltip`. [#2228](https://github.com/iced-rs/iced/pull/2228)
Expand Down Expand Up @@ -102,6 +105,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Subscription::map` using unreliable function pointer hash to identify mappers. [#2237](https://github.com/iced-rs/iced/pull/2237)
- Missing feature flag docs for `time::every`. [#2188](https://github.com/iced-rs/iced/pull/2188)
- Event loop not being resumed on Windows while resizing. [#2214](https://github.com/iced-rs/iced/pull/2214)
- Alpha mode misconfiguration in `iced_wgpu`. [#2231](https://github.com/iced-rs/iced/pull/2231)
- Outdated documentation leading to a dead link. [#2232](https://github.com/iced-rs/iced/pull/2232)

Many thanks to...

Expand All @@ -116,6 +121,7 @@ Many thanks to...
- @Calastrophe
- @casperstorm
- @cfrenette
- @clarkmoody
- @Davidster
- @Decodetalkers
- @derezzedex
Expand All @@ -132,6 +138,8 @@ Many thanks to...
- @jim-ec
- @joshuamegnauth54
- @jpttrssn
- @julianbraha
- @Koranir
- @lufte
- @matze
- @MichalLebeda
Expand Down
5 changes: 4 additions & 1 deletion examples/gradient/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ edition = "2021"
publish = false

[dependencies]
iced = { path = "../.." }
iced.workspace = true
iced.features = ["debug"]

tracing-subscriber = "0.3"
55 changes: 50 additions & 5 deletions examples/gradient/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
use iced::gradient;
use iced::widget::{column, container, horizontal_space, row, slider, text};
use iced::application;
use iced::theme::{self, Theme};
use iced::widget::{
checkbox, column, container, horizontal_space, row, slider, text,
};
use iced::{gradient, window};
use iced::{
Alignment, Background, Color, Element, Length, Radians, Sandbox, Settings,
};

pub fn main() -> iced::Result {
Gradient::run(Settings::default())
tracing_subscriber::fmt::init();

Gradient::run(Settings {
window: window::Settings {
transparent: true,
..Default::default()
},
..Default::default()
})
}

#[derive(Debug, Clone, Copy)]
struct Gradient {
start: Color,
end: Color,
angle: Radians,
transparent: bool,
}

#[derive(Debug, Clone, Copy)]
enum Message {
StartChanged(Color),
EndChanged(Color),
AngleChanged(Radians),
TransparentToggled(bool),
}

impl Sandbox for Gradient {
Expand All @@ -30,6 +44,7 @@ impl Sandbox for Gradient {
start: Color::WHITE,
end: Color::new(0.0, 0.0, 1.0, 1.0),
angle: Radians(0.0),
transparent: false,
}
}

Expand All @@ -42,11 +57,19 @@ impl Sandbox for Gradient {
Message::StartChanged(color) => self.start = color,
Message::EndChanged(color) => self.end = color,
Message::AngleChanged(angle) => self.angle = angle,
Message::TransparentToggled(transparent) => {
self.transparent = transparent;
}
}
}

fn view(&self) -> Element<Message> {
let Self { start, end, angle } = *self;
let Self {
start,
end,
angle,
transparent,
} = *self;

let gradient_box = container(horizontal_space(Length::Fill))
.width(Length::Fill)
Expand All @@ -72,14 +95,34 @@ impl Sandbox for Gradient {
.padding(8)
.align_items(Alignment::Center);

let transparency_toggle = iced::widget::Container::new(
checkbox("Transparent window", transparent)
.on_toggle(Message::TransparentToggled),
)
.padding(8);

column![
color_picker("Start", self.start).map(Message::StartChanged),
color_picker("End", self.end).map(Message::EndChanged),
angle_picker,
gradient_box
transparency_toggle,
gradient_box,
]
.into()
}

fn style(&self) -> theme::Application {
if self.transparent {
theme::Application::custom(|theme: &Theme| {
application::Appearance {
background_color: Color::TRANSPARENT,
text_color: theme.palette().text,
}
})
} else {
theme::Application::Default
}
}
}

fn color_picker(label: &str, color: Color) -> Element<'_, Color> {
Expand All @@ -91,6 +134,8 @@ fn color_picker(label: &str, color: Color) -> Element<'_, Color> {
.step(0.01),
slider(0.0..=1.0, color.b, move |b| { Color { b, ..color } })
.step(0.01),
slider(0.0..=1.0, color.a, move |a| { Color { a, ..color } })
.step(0.01),
]
.spacing(8)
.padding(8)
Expand Down
34 changes: 26 additions & 8 deletions examples/qr_code/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use iced::widget::qr_code::{self, QRCode};
use iced::widget::{column, container, text, text_input};
use iced::{Alignment, Color, Element, Length, Sandbox, Settings};
use iced::widget::{column, container, pick_list, row, text, text_input};
use iced::{Alignment, Element, Length, Sandbox, Settings, Theme};

pub fn main() -> iced::Result {
QRGenerator::run(Settings::default())
Expand All @@ -9,12 +9,14 @@ pub fn main() -> iced::Result {
#[derive(Default)]
struct QRGenerator {
data: String,
qr_code: Option<qr_code::State>,
qr_code: Option<qr_code::Data>,
theme: Theme,
}

#[derive(Debug, Clone)]
enum Message {
DataChanged(String),
ThemeChanged(Theme),
}

impl Sandbox for QRGenerator {
Expand All @@ -36,26 +38,38 @@ impl Sandbox for QRGenerator {
self.qr_code = if data.is_empty() {
None
} else {
qr_code::State::new(&data).ok()
qr_code::Data::new(&data).ok()
};

self.data = data;
}
Message::ThemeChanged(theme) => {
self.theme = theme;
}
}
}

fn view(&self) -> Element<Message> {
let title = text("QR Code Generator")
.size(70)
.style(Color::from([0.5, 0.5, 0.5]));
let title = text("QR Code Generator").size(70);

let input =
text_input("Type the data of your QR code here...", &self.data)
.on_input(Message::DataChanged)
.size(30)
.padding(15);

let mut content = column![title, input]
let choose_theme = row![
text("Theme:"),
pick_list(
Theme::ALL,
Some(self.theme.clone()),
Message::ThemeChanged,
)
]
.spacing(10)
.align_items(Alignment::Center);

let mut content = column![title, input, choose_theme]
.width(700)
.spacing(20)
.align_items(Alignment::Center);
Expand All @@ -72,4 +86,8 @@ impl Sandbox for QRGenerator {
.center_y()
.into()
}

fn theme(&self) -> Theme {
self.theme.clone()
}
}
2 changes: 1 addition & 1 deletion examples/solar_system/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Application for SolarSystem {
}
}

theme::Application::from(dark_background as fn(&Theme) -> _)
theme::Application::custom(dark_background)
}

fn subscription(&self) -> Subscription<Message> {
Expand Down
2 changes: 1 addition & 1 deletion examples/websocket/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ once_cell.workspace = true
warp = "0.3"

[dependencies.async-tungstenite]
version = "0.24"
version = "0.25"
features = ["tokio-rustls-webpki-roots"]

[dependencies.tokio]
Expand Down
7 changes: 1 addition & 6 deletions graphics/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,7 @@ pub fn measure(buffer: &cosmic_text::Buffer) -> Size {
(run.line_w.max(width), total_lines + 1)
});

let (max_width, max_height) = buffer.size();

Size::new(
width.min(max_width),
(total_lines as f32 * buffer.metrics().line_height).min(max_height),
)
Size::new(width, total_lines as f32 * buffer.metrics().line_height)
}

/// Returns the attributes of the given [`Font`].
Expand Down
1 change: 1 addition & 0 deletions style/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub mod menu;
pub mod pane_grid;
pub mod pick_list;
pub mod progress_bar;
pub mod qr_code;
pub mod radio;
pub mod rule;
pub mod scrollable;
Expand Down
20 changes: 20 additions & 0 deletions style/src/qr_code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! Change the appearance of a QR code.
use crate::core::Color;

/// The appearance of a QR code.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Appearance {
/// The color of the QR code data cells
pub cell: Color,
/// The color of the QR code background
pub background: Color,
}

/// A set of rules that dictate the style of a QR code.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;

/// Produces the style of a QR code.
fn appearance(&self, style: &Self::Style) -> Appearance;
}
Loading

0 comments on commit 38f5777

Please sign in to comment.