Merge branch 'iced-rs:master' into viewer_content_fit

This commit is contained in:
Gigas002 2024-03-24 11:13:45 +09:00 committed by GitHub
commit 4334e63ba1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 96 additions and 18 deletions

View file

@ -18,7 +18,7 @@ all-features = true
maintenance = { status = "actively-developed" } maintenance = { status = "actively-developed" }
[features] [features]
default = ["wgpu", "fira-sans"] default = ["wgpu", "fira-sans", "auto-detect-theme"]
# Enable the `wgpu` GPU-accelerated renderer backend # Enable the `wgpu` GPU-accelerated renderer backend
wgpu = ["iced_renderer/wgpu", "iced_widget/wgpu"] wgpu = ["iced_renderer/wgpu", "iced_widget/wgpu"]
# Enables the `Image` widget # Enables the `Image` widget
@ -53,8 +53,11 @@ multi-window = ["iced_winit/multi-window"]
advanced = [] advanced = []
# Enables embedding Fira Sans as the default font on Wasm builds # Enables embedding Fira Sans as the default font on Wasm builds
fira-sans = ["iced_renderer/fira-sans"] fira-sans = ["iced_renderer/fira-sans"]
# Enables auto-detecting light/dark mode for the built-in theme
auto-detect-theme = ["iced_core/auto-detect-theme"]
[dependencies] [dependencies]
iced_core.workspace = true
iced_futures.workspace = true iced_futures.workspace = true
iced_renderer.workspace = true iced_renderer.workspace = true
iced_widget.workspace = true iced_widget.workspace = true
@ -121,6 +124,7 @@ async-std = "1.0"
bitflags = "2.0" bitflags = "2.0"
bytemuck = { version = "1.0", features = ["derive"] } bytemuck = { version = "1.0", features = ["derive"] }
cosmic-text = "0.10" cosmic-text = "0.10"
dark-light = "1.0"
futures = "0.3" futures = "0.3"
glam = "0.25" glam = "0.25"
glyphon = "0.5" glyphon = "0.5"
@ -158,4 +162,4 @@ web-time = "0.2"
wgpu = "0.19" wgpu = "0.19"
winapi = "0.3" winapi = "0.3"
window_clipboard = "0.4.1" window_clipboard = "0.4.1"
winit = { git = "https://github.com/iced-rs/winit.git", rev = "b91e39ece2c0d378c3b80da7f3ab50e17bb798a5" } winit = { git = "https://github.com/iced-rs/winit.git", rev = "592bd152f6d5786fae7d918532d7db752c0d164f" }

View file

@ -10,6 +10,9 @@ homepage.workspace = true
categories.workspace = true categories.workspace = true
keywords.workspace = true keywords.workspace = true
[features]
auto-detect-theme = ["dep:dark-light"]
[dependencies] [dependencies]
bitflags.workspace = true bitflags.workspace = true
glam.workspace = true glam.workspace = true
@ -22,6 +25,9 @@ thiserror.workspace = true
web-time.workspace = true web-time.workspace = true
xxhash-rust.workspace = true xxhash-rust.workspace = true
dark-light.workspace = true
dark-light.optional = true
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
raw-window-handle.workspace = true raw-window-handle.workspace = true

View file

@ -7,10 +7,9 @@ use std::fmt;
use std::sync::Arc; use std::sync::Arc;
/// A built-in theme. /// A built-in theme.
#[derive(Debug, Clone, PartialEq, Default)] #[derive(Debug, Clone, PartialEq)]
pub enum Theme { pub enum Theme {
/// The built-in light variant. /// The built-in light variant.
#[default]
Light, Light,
/// The built-in dark variant. /// The built-in dark variant.
Dark, Dark,
@ -161,6 +160,28 @@ impl Theme {
} }
} }
impl Default for Theme {
fn default() -> Self {
#[cfg(feature = "auto-detect-theme")]
{
use once_cell::sync::Lazy;
static DEFAULT: Lazy<Theme> =
Lazy::new(|| match dark_light::detect() {
dark_light::Mode::Dark => Theme::Dark,
dark_light::Mode::Light | dark_light::Mode::Default => {
Theme::Light
}
});
DEFAULT.clone()
}
#[cfg(not(feature = "auto-detect-theme"))]
Theme::Light
}
}
impl fmt::Display for Theme { impl fmt::Display for Theme {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {

View file

@ -1,11 +1,21 @@
//! Platform specific settings for WebAssembly. //! Platform specific settings for WebAssembly.
/// The platform specific window settings of an application. /// The platform specific window settings of an application.
#[derive(Debug, Clone, PartialEq, Eq, Default)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct PlatformSpecific { pub struct PlatformSpecific {
/// The identifier of a DOM element that will be replaced with the /// The identifier of a DOM element that will be replaced with the
/// application. /// application.
/// ///
/// If set to `None`, the application will be appended to the HTML body. /// If set to `None`, the application will be appended to the HTML body.
///
/// By default, it is set to `"iced"`.
pub target: Option<String>, pub target: Option<String>,
} }
impl Default for PlatformSpecific {
fn default() -> Self {
Self {
target: Some(String::from("iced")),
}
}
}

View file

@ -161,13 +161,21 @@ impl Data {
queue: &wgpu::Queue, queue: &wgpu::Queue,
instances: &[Instance], instances: &[Instance],
) { ) {
self.instance_count = instances.len();
if self.instance_count == 0 {
return;
}
let _ = self.instances.resize(device, instances.len()); let _ = self.instances.resize(device, instances.len());
let _ = self.instances.write(queue, 0, instances); let _ = self.instances.write(queue, 0, instances);
self.instance_count = instances.len();
} }
fn render<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) { fn render<'a>(&'a self, render_pass: &mut wgpu::RenderPass<'a>) {
if self.instance_count == 0 {
return;
}
render_pass.set_bind_group(0, &self.constants, &[]); render_pass.set_bind_group(0, &self.constants, &[]);
render_pass.set_vertex_buffer(0, self.instances.slice(..)); render_pass.set_vertex_buffer(0, self.instances.slice(..));

View file

@ -92,6 +92,10 @@ impl Compositor {
.contains(&wgpu::CompositeAlphaMode::PostMultiplied) .contains(&wgpu::CompositeAlphaMode::PostMultiplied)
{ {
wgpu::CompositeAlphaMode::PostMultiplied wgpu::CompositeAlphaMode::PostMultiplied
} else if alpha_modes
.contains(&wgpu::CompositeAlphaMode::PreMultiplied)
{
wgpu::CompositeAlphaMode::PreMultiplied
} else { } else {
wgpu::CompositeAlphaMode::Auto wgpu::CompositeAlphaMode::Auto
}; };

View file

@ -478,12 +478,14 @@ where
translation: Vector, translation: Vector,
) -> Option<overlay::Element<'b, Message, Theme, Renderer>> { ) -> Option<overlay::Element<'b, Message, Theme, Renderer>> {
self.rebuild_element_if_necessary(); self.rebuild_element_if_necessary();
let tree = tree let tree = tree
.state .state
.downcast_mut::<Rc<RefCell<Option<Tree>>>>() .downcast_mut::<Rc<RefCell<Option<Tree>>>>()
.borrow_mut() .borrow_mut()
.take() .take()
.unwrap(); .unwrap();
let overlay = Overlay(Some( let overlay = Overlay(Some(
InnerBuilder { InnerBuilder {
instance: self, instance: self,

View file

@ -308,10 +308,13 @@ where
content_layout_node.as_ref().unwrap(), content_layout_node.as_ref().unwrap(),
); );
element (
.as_widget_mut() element
.overlay(tree, content_layout, renderer, translation) .as_widget_mut()
.map(|overlay| RefCell::new(Nested::new(overlay))) .overlay(tree, content_layout, renderer, translation)
.map(|overlay| RefCell::new(Nested::new(overlay))),
content_layout_node,
)
}, },
} }
.build(); .build();
@ -341,7 +344,10 @@ struct Overlay<'a, 'b, Message, Theme, Renderer> {
#[borrows(mut content, mut tree)] #[borrows(mut content, mut tree)]
#[not_covariant] #[not_covariant]
overlay: Option<RefCell<Nested<'this, Message, Theme, Renderer>>>, overlay: (
Option<RefCell<Nested<'this, Message, Theme, Renderer>>>,
&'this mut Option<layout::Node>,
),
} }
impl<'a, 'b, Message, Theme, Renderer> impl<'a, 'b, Message, Theme, Renderer>
@ -351,7 +357,7 @@ impl<'a, 'b, Message, Theme, Renderer>
&self, &self,
f: impl FnOnce(&mut Nested<'_, Message, Theme, Renderer>) -> T, f: impl FnOnce(&mut Nested<'_, Message, Theme, Renderer>) -> T,
) -> Option<T> { ) -> Option<T> {
self.with_overlay(|overlay| { self.with_overlay(|(overlay, _layout)| {
overlay.as_ref().map(|nested| (f)(&mut nested.borrow_mut())) overlay.as_ref().map(|nested| (f)(&mut nested.borrow_mut()))
}) })
} }
@ -360,7 +366,7 @@ impl<'a, 'b, Message, Theme, Renderer>
&mut self, &mut self,
f: impl FnOnce(&mut Nested<'_, Message, Theme, Renderer>) -> T, f: impl FnOnce(&mut Nested<'_, Message, Theme, Renderer>) -> T,
) -> Option<T> { ) -> Option<T> {
self.with_overlay_mut(|overlay| { self.with_overlay_mut(|(overlay, _layout)| {
overlay.as_mut().map(|nested| (f)(nested.get_mut())) overlay.as_mut().map(|nested| (f)(nested.get_mut()))
}) })
} }
@ -412,10 +418,27 @@ where
clipboard: &mut dyn Clipboard, clipboard: &mut dyn Clipboard,
shell: &mut Shell<'_, Message>, shell: &mut Shell<'_, Message>,
) -> event::Status { ) -> event::Status {
self.with_overlay_mut_maybe(|overlay| { let mut is_layout_invalid = false;
overlay.on_event(event, layout, cursor, renderer, clipboard, shell)
}) let event_status = self
.unwrap_or(event::Status::Ignored) .with_overlay_mut_maybe(|overlay| {
let event_status = overlay.on_event(
event, layout, cursor, renderer, clipboard, shell,
);
is_layout_invalid = shell.is_layout_invalid();
event_status
})
.unwrap_or(event::Status::Ignored);
if is_layout_invalid {
self.with_overlay_mut(|(_overlay, layout)| {
**layout = None;
});
}
event_status
} }
fn is_over( fn is_over(