Add ThemeChanged variant to Event in iced_sentinel
This commit is contained in:
parent
7f7c5ea337
commit
c856d2b513
13 changed files with 69 additions and 4 deletions
|
|
@ -23,6 +23,10 @@ xxhash-rust.workspace = true
|
|||
palette.workspace = true
|
||||
palette.optional = true
|
||||
|
||||
serde.workspace = true
|
||||
serde.optional = true
|
||||
serde.features = ["derive"]
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
raw-window-handle.workspace = true
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ use palette::rgb::{Srgb, Srgba};
|
|||
|
||||
/// A color in the `sRGB` color space.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct Color {
|
||||
/// Red component, 0.0 - 1.0
|
||||
pub r: f32,
|
||||
|
|
|
|||
|
|
@ -9,11 +9,12 @@
|
|||
#![doc(
|
||||
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
|
||||
)]
|
||||
#![forbid(unsafe_code, rust_2018_idioms)]
|
||||
#![forbid(unsafe_code)]
|
||||
#![deny(
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
unused_results,
|
||||
rust_2018_idioms,
|
||||
rustdoc::broken_intra_doc_links
|
||||
)]
|
||||
pub mod alignment;
|
||||
|
|
|
|||
|
|
@ -11,10 +11,11 @@ categories.workspace = true
|
|||
keywords.workspace = true
|
||||
|
||||
[features]
|
||||
enable = ["iced_sentinel", "once_cell"]
|
||||
enable = ["dep:iced_sentinel", "dep:once_cell"]
|
||||
|
||||
[dependencies]
|
||||
iced_core.workspace = true
|
||||
iced_style.workspace = true
|
||||
|
||||
iced_sentinel.workspace = true
|
||||
iced_sentinel.optional = true
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
pub use iced_core as core;
|
||||
pub use iced_style as style;
|
||||
|
||||
use crate::style::theme;
|
||||
|
||||
pub use internal::Timer;
|
||||
|
||||
|
|
@ -6,6 +9,10 @@ pub fn open_axe() {}
|
|||
|
||||
pub fn log_message(_message: &impl std::fmt::Debug) {}
|
||||
|
||||
pub fn theme_changed(palette: theme::Palette) {
|
||||
internal::theme_changed(palette);
|
||||
}
|
||||
|
||||
pub fn boot_time() -> Timer {
|
||||
internal::boot_time()
|
||||
}
|
||||
|
|
@ -41,6 +48,7 @@ pub fn time(name: impl AsRef<str>) -> Timer {
|
|||
#[cfg(feature = "enable")]
|
||||
mod internal {
|
||||
use crate::core::time::Instant;
|
||||
use crate::style::theme;
|
||||
|
||||
use iced_sentinel::client::{self, Client};
|
||||
use iced_sentinel::timing::{self, Timing};
|
||||
|
|
@ -48,6 +56,10 @@ mod internal {
|
|||
use once_cell::sync::Lazy;
|
||||
use std::sync::{Mutex, MutexGuard};
|
||||
|
||||
pub fn theme_changed(palette: theme::Palette) {
|
||||
lock().sentinel.report_theme_change(palette);
|
||||
}
|
||||
|
||||
pub fn boot_time() -> Timer {
|
||||
timer(timing::Stage::Boot)
|
||||
}
|
||||
|
|
@ -120,6 +132,10 @@ mod internal {
|
|||
|
||||
#[cfg(not(feature = "enable"))]
|
||||
mod internal {
|
||||
use crate::style::theme;
|
||||
|
||||
pub fn theme_changed(_palette: theme::Palette) {}
|
||||
|
||||
pub fn boot_time() -> Timer {
|
||||
Timer
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,10 @@ keywords.workspace = true
|
|||
|
||||
[dependencies]
|
||||
iced_core.workspace = true
|
||||
|
||||
iced_style.workspace = true
|
||||
iced_style.features = ["serde"]
|
||||
|
||||
serde_json.workspace = true
|
||||
futures.workspace = true
|
||||
log.workspace = true
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use crate::style::theme;
|
||||
use crate::{Input, Timing, SOCKET_ADDRESS};
|
||||
|
||||
use tokio::io::{self, AsyncWriteExt};
|
||||
|
|
@ -11,6 +12,10 @@ pub struct Client {
|
|||
}
|
||||
|
||||
impl Client {
|
||||
pub fn report_theme_change(&mut self, palette: theme::Palette) {
|
||||
let _ = self.sender.try_send(Input::ThemeChanged(palette));
|
||||
}
|
||||
|
||||
pub fn report_timing(&mut self, timing: Timing) {
|
||||
let _ = self.sender.try_send(Input::TimingMeasured(timing));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
pub use iced_core as core;
|
||||
pub use iced_style as style;
|
||||
|
||||
pub mod client;
|
||||
pub mod timing;
|
||||
|
||||
use crate::style::theme;
|
||||
use crate::timing::Timing;
|
||||
|
||||
use futures::future;
|
||||
|
|
@ -18,6 +20,7 @@ pub const SOCKET_ADDRESS: &str = "127.0.0.1:9167";
|
|||
pub enum Input {
|
||||
Connected(Version),
|
||||
TimingMeasured(Timing),
|
||||
ThemeChanged(theme::Palette),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -25,6 +28,7 @@ pub enum Event {
|
|||
Connected(Version),
|
||||
Disconnected,
|
||||
TimingMeasured(Timing),
|
||||
ThemeChanged(theme::Palette),
|
||||
}
|
||||
|
||||
pub fn run() -> impl Stream<Item = Event> {
|
||||
|
|
@ -87,6 +91,9 @@ async fn receive(
|
|||
Input::TimingMeasured(timing) => {
|
||||
Event::TimingMeasured(timing)
|
||||
}
|
||||
Input::ThemeChanged(palette) => {
|
||||
Event::ThemeChanged(palette)
|
||||
}
|
||||
},
|
||||
))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,9 +10,16 @@ homepage.workspace = true
|
|||
categories.workspace = true
|
||||
keywords.workspace = true
|
||||
|
||||
[features]
|
||||
serde = ["dep:serde", "iced_core/serde"]
|
||||
|
||||
[dependencies]
|
||||
iced_core.workspace = true
|
||||
iced_core.features = ["palette"]
|
||||
|
||||
palette.workspace = true
|
||||
once_cell.workspace = true
|
||||
|
||||
serde.workspace = true
|
||||
serde.optional = true
|
||||
serde.features = ["derive"]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
//! Change the appearance of an application.
|
||||
use iced_core::Color;
|
||||
use crate::core::Color;
|
||||
use crate::theme;
|
||||
|
||||
/// A set of rules that dictate the style of an application.
|
||||
pub trait StyleSheet {
|
||||
|
|
@ -10,6 +11,17 @@ pub trait StyleSheet {
|
|||
///
|
||||
/// [`Style`]: Self::Style
|
||||
fn appearance(&self, style: &Self::Style) -> Appearance;
|
||||
|
||||
/// Returns the [`theme::Palette`] of the application, if any.
|
||||
///
|
||||
/// This may be used by other parts of the `iced` runtime to
|
||||
/// try to match the style of your application.
|
||||
///
|
||||
/// For instance, the Iced Axe uses this [`theme::Palette`] to
|
||||
/// automatically style itself using your application's colors.
|
||||
fn palette(&self) -> Option<theme::Palette> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// The appearance of an application.
|
||||
|
|
|
|||
|
|
@ -7,11 +7,12 @@
|
|||
#![doc(
|
||||
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
|
||||
)]
|
||||
#![forbid(unsafe_code, rust_2018_idioms)]
|
||||
#![forbid(unsafe_code)]
|
||||
#![deny(
|
||||
unused_results,
|
||||
missing_docs,
|
||||
unused_results,
|
||||
rust_2018_idioms,
|
||||
rustdoc::broken_intra_doc_links
|
||||
)]
|
||||
pub use iced_core as core;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use palette::{FromColor, Hsl, Mix};
|
|||
|
||||
/// A color palette.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct Palette {
|
||||
/// The background [`Color`] of the [`Palette`].
|
||||
pub background: Color,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use crate::application::{self, StyleSheet as _};
|
|||
use crate::conversion;
|
||||
use crate::core::mouse;
|
||||
use crate::core::{Color, Size};
|
||||
use crate::debug;
|
||||
use crate::graphics::Viewport;
|
||||
use crate::Application;
|
||||
|
||||
|
|
@ -37,6 +38,8 @@ where
|
|||
let theme = application.theme();
|
||||
let appearance = theme.appearance(&application.style());
|
||||
|
||||
let _ = theme.palette().map(debug::theme_changed);
|
||||
|
||||
let viewport = {
|
||||
let physical_size = window.inner_size();
|
||||
|
||||
|
|
@ -211,5 +214,7 @@ where
|
|||
// Update theme and appearance
|
||||
self.theme = application.theme();
|
||||
self.appearance = self.theme.appearance(&application.style());
|
||||
|
||||
let _ = self.theme.palette().map(debug::theme_changed);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue