Merge remote-tracking branch 'origin/main' into next-dash-interface

[skip ci]
This commit is contained in:
Aleksander
2025-12-23 19:24:08 +01:00
46 changed files with 1858 additions and 606 deletions

113
wgui/src/widget/image.rs Normal file
View File

@@ -0,0 +1,113 @@
use std::sync::atomic::{AtomicUsize, Ordering};
use slotmap::Key;
use crate::{
drawing::{self, ImagePrimitive, PrimitiveExtent},
event::CallbackDataCommon,
globals::Globals,
layout::WidgetID,
renderer_vk::text::custom_glyph::CustomGlyphData,
widget::{WidgetStateFlags, util::WLength},
};
use super::{WidgetObj, WidgetState};
static AUTO_INCREMENT: AtomicUsize = AtomicUsize::new(0);
#[derive(Debug, Default)]
pub struct WidgetImageParams {
pub glyph_data: Option<CustomGlyphData>,
pub border: f32,
pub border_color: drawing::Color,
pub round: WLength,
}
#[derive(Debug, Default)]
pub struct WidgetImage {
params: WidgetImageParams,
id: WidgetID,
content_key: usize,
}
impl WidgetImage {
pub fn create(params: WidgetImageParams) -> WidgetState {
WidgetState::new(
WidgetStateFlags::default(),
Box::new(Self {
params,
id: WidgetID::null(),
content_key: AUTO_INCREMENT.fetch_add(1, Ordering::Relaxed),
}),
)
}
pub fn set_content(&mut self, common: &mut CallbackDataCommon, content: Option<CustomGlyphData>) {
if self.params.glyph_data == content {
return;
}
self.params.glyph_data = content;
common.mark_widget_dirty(self.id);
}
pub fn get_content(&self) -> Option<CustomGlyphData> {
self.params.glyph_data.clone()
}
}
impl WidgetObj for WidgetImage {
fn draw(&mut self, state: &mut super::DrawState, _params: &super::DrawParams) {
let boundary = drawing::Boundary::construct_relative(state.transform_stack);
let Some(content) = self.params.glyph_data.clone() else {
return;
};
let round_units = match self.params.round {
WLength::Units(units) => units as u8,
WLength::Percent(percent) => (f32::min(boundary.size.x, boundary.size.y) * percent / 2.0) as u8,
};
state.primitives.push(drawing::RenderPrimitive::Image(
PrimitiveExtent {
boundary,
transform: state.transform_stack.get().transform,
},
ImagePrimitive {
content,
content_key: self.content_key,
border: self.params.border,
border_color: self.params.border_color,
round_units,
},
));
}
fn measure(
&mut self,
_globals: &Globals,
_known_dimensions: taffy::Size<Option<f32>>,
_available_space: taffy::Size<taffy::AvailableSpace>,
) -> taffy::Size<f32> {
taffy::Size::ZERO
}
fn get_id(&self) -> WidgetID {
self.id
}
fn set_id(&mut self, id: WidgetID) {
self.id = id;
}
fn get_type(&self) -> super::WidgetType {
super::WidgetType::Sprite
}
fn debug_print(&self) -> String {
String::default()
}
}

View File

@@ -17,6 +17,7 @@ use crate::{
};
pub mod div;
pub mod image;
pub mod label;
pub mod rectangle;
pub mod sprite;

View File

@@ -2,6 +2,7 @@ use slotmap::Key;
use crate::{
drawing::{self, GradientMode, PrimitiveExtent},
event::CallbackDataCommon,
layout::WidgetID,
widget::{WidgetStateFlags, util::WLength},
};
@@ -35,6 +36,10 @@ impl WidgetRectangle {
}),
)
}
pub fn set_color(&mut self, common: &mut CallbackDataCommon, color: drawing::Color) {
self.params.color = color;
common.mark_widget_dirty(self.id);
}
}
impl WidgetObj for WidgetRectangle {

View File

@@ -5,6 +5,7 @@ use slotmap::Key;
use crate::{
drawing::{self, PrimitiveExtent},
event::CallbackDataCommon,
globals::Globals,
layout::WidgetID,
renderer_vk::text::{
@@ -39,16 +40,22 @@ impl WidgetSprite {
)
}
pub const fn set_color(&mut self, color: drawing::Color) {
pub fn set_color(&mut self, common: &mut CallbackDataCommon, color: drawing::Color) {
self.params.color = Some(color);
common.mark_widget_dirty(self.id);
}
pub const fn get_color(&self) -> Option<drawing::Color> {
self.params.color
}
pub fn set_content(&mut self, content: Option<CustomGlyphData>) {
pub fn set_content(&mut self, common: &mut CallbackDataCommon, content: Option<CustomGlyphData>) {
if self.params.glyph_data == content {
return;
}
self.params.glyph_data = content;
common.mark_widget_dirty(self.id);
}
pub fn get_content(&self) -> Option<CustomGlyphData> {