This commit is contained in:
galister
2026-01-05 20:52:34 +09:00
parent fd9becc398
commit 164e9764eb
22 changed files with 115 additions and 68 deletions

View File

@@ -1,22 +1,25 @@
use std::{cell::RefCell, rc::{Rc, Weak}};
use std::{
cell::RefCell,
rc::{Rc, Weak},
};
use taffy::{
prelude::{length, percent},
AlignItems,
prelude::{length, percent},
};
use crate::{
animation::{Animation, AnimationEasing},
components::{radio_group::ComponentRadioGroup, Component, ComponentBase, ComponentTrait, RefreshData},
components::{Component, ComponentBase, ComponentTrait, RefreshData, radio_group::ComponentRadioGroup},
drawing::Color,
event::{CallbackDataCommon, EventListenerCollection, EventListenerID, EventListenerKind},
i18n::Translation,
layout::{self, WidgetID, WidgetPair},
renderer_vk::text::{FontWeight, TextStyle},
widget::{
ConstructEssentials, EventResult,
label::{WidgetLabel, WidgetLabelParams},
rectangle::{WidgetRectangle, WidgetRectangleParams},
util::WLength,
ConstructEssentials, EventResult,
},
};
@@ -54,7 +57,7 @@ struct State {
hovered: bool,
down: bool,
on_toggle: Option<CheckboxToggleCallback>,
self_ref: Weak<ComponentCheckbox>,
self_ref: Weak<ComponentCheckbox>,
}
#[allow(clippy::struct_field_names)]
@@ -128,7 +131,6 @@ impl ComponentCheckbox {
self.state.borrow_mut().checked = checked;
}
pub fn on_toggle(&self, func: CheckboxToggleCallback) {
self.state.borrow_mut().on_toggle = Some(func);
}
@@ -246,19 +248,27 @@ fn register_event_mouse_release(
if state.down {
state.down = false;
if let Some(self_ref) = state.self_ref.upgrade() && let Some(radio) = data.radio_group.as_ref().and_then(|r| r.upgrade()) {
if let Some(self_ref) = state.self_ref.upgrade()
&& let Some(radio) = data.radio_group.as_ref().and_then(|r| r.upgrade())
{
radio.set_selected_internal(common, &self_ref)?;
state.checked = true; // can't uncheck radiobox by clicking the checked box again
} else {
state.checked = !state.checked;
}
}
set_box_checked(&common.state.widgets, &data, state.checked);
if state.hovered
&& let Some(on_toggle) = &state.on_toggle
{
on_toggle(common, CheckboxToggleEvent { checked: state.checked, value: data.value.clone() })?;
on_toggle(
common,
CheckboxToggleEvent {
checked: state.checked,
value: data.value.clone(),
},
)?;
}
Ok(EventResult::Consumed)
} else {
@@ -292,12 +302,12 @@ pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Resul
};
//style.align_self = Some(taffy::AlignSelf::Start); // do not stretch self to the parent
style.gap = length(4.0);
let (round_5, round_8) = if params.radio_group.is_some() {
(WLength::Percent(1.0), WLength::Percent(1.0))
} else {
(WLength::Units(5.0), WLength::Units(8.0))
};
(WLength::Units(5.0), WLength::Units(8.0))
};
let globals = ess.layout.state.globals.clone();

View File

@@ -3,10 +3,10 @@ use std::{cell::RefCell, rc::Rc};
use taffy::Style;
use crate::{
components::{checkbox::ComponentCheckbox, Component, ComponentBase, ComponentTrait, RefreshData},
components::{Component, ComponentBase, ComponentTrait, RefreshData, checkbox::ComponentCheckbox},
event::CallbackDataCommon,
layout::WidgetPair,
widget::{div::WidgetDiv, ConstructEssentials},
widget::{ConstructEssentials, div::WidgetDiv},
};
pub struct RadioValueChangeEvent {

View File

@@ -10,8 +10,8 @@ use crate::{
globals::Globals,
layout::Widget,
renderer_vk::text::{
custom_glyph::{CustomGlyph, CustomGlyphData},
TextShadow,
custom_glyph::{CustomGlyph, CustomGlyphData},
},
stack::{self, ScissorBoundary, ScissorStack, TransformStack},
widget::{self, ScrollbarInfo, WidgetState},

View File

@@ -13,12 +13,12 @@ use vulkano::{
view::ImageView,
},
pipeline::{
graphics::{self, vertex_input::Vertex, viewport::Viewport},
Pipeline, PipelineBindPoint,
graphics::{self, vertex_input::Vertex, viewport::Viewport},
},
};
use super::{pipeline::WGfxPipeline, WGfx};
use super::{WGfx, pipeline::WGfxPipeline};
pub struct WGfxPass<V> {
pub command_buffer: Arc<SecondaryAutoCommandBuffer>,

View File

@@ -1,14 +1,14 @@
use std::{marker::PhantomData, ops::Range, sync::Arc};
use smallvec::{smallvec, SmallVec};
use smallvec::{SmallVec, smallvec};
use vulkano::{
buffer::{
allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo},
BufferContents, BufferUsage, Subbuffer,
allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo},
},
descriptor_set::{
layout::{DescriptorBindingFlags, DescriptorSetLayoutCreateFlags},
DescriptorSet, WriteDescriptorSet,
layout::{DescriptorBindingFlags, DescriptorSetLayoutCreateFlags},
},
format::Format,
image::{
@@ -17,8 +17,9 @@ use vulkano::{
},
memory::allocator::MemoryTypeFilter,
pipeline::{
DynamicState, GraphicsPipeline, Pipeline, PipelineLayout,
graphics::{
self,
self, GraphicsPipelineCreateInfo,
color_blend::{AttachmentBlend, ColorBlendAttachmentState, ColorBlendState},
input_assembly::{InputAssemblyState, PrimitiveTopology},
multisample::MultisampleState,
@@ -26,15 +27,13 @@ use vulkano::{
subpass::PipelineRenderingCreateInfo,
vertex_input::{Vertex, VertexDefinition, VertexInputState},
viewport::ViewportState,
GraphicsPipelineCreateInfo,
},
layout::PipelineDescriptorSetLayoutCreateInfo,
DynamicState, GraphicsPipeline, Pipeline, PipelineLayout,
},
shader::{EntryPoint, ShaderModule},
};
use super::{pass::WGfxPass, WGfx};
use super::{WGfx, pass::WGfxPass};
pub struct WGfxPipeline<V> {
pub graphics: Arc<WGfx>,

View File

@@ -1,9 +1,9 @@
use crate::{
components::{checkbox, radio_group::ComponentRadioGroup, Component},
components::{Component, checkbox, radio_group::ComponentRadioGroup},
i18n::Translation,
layout::WidgetID,
parser::{
parse_check_f32, parse_check_i32, process_component, style::parse_style, AttribPair, Fetchable, ParserContext,
AttribPair, Fetchable, ParserContext, parse_check_f32, parse_check_i32, process_component, style::parse_style,
},
};

View File

@@ -1,7 +1,7 @@
use crate::{
components::{radio_group, Component},
components::{Component, radio_group},
layout::WidgetID,
parser::{parse_children, process_component, style::parse_style, AttribPair, ParserContext, ParserFile},
parser::{AttribPair, ParserContext, ParserFile, parse_children, process_component, style::parse_style},
};
pub fn parse_component_radio_group<'a>(

View File

@@ -10,9 +10,24 @@ mod widget_rectangle;
mod widget_sprite;
use crate::{
assets::{normalize_path, AssetPath, AssetPathOwned}, components::{Component, ComponentWeak}, drawing::{self}, globals::WguiGlobals, layout::{Layout, LayoutParams, LayoutState, Widget, WidgetID, WidgetMap, WidgetPair}, log::LogErr, parser::{
component_button::parse_component_button, component_checkbox::{parse_component_checkbox, CheckboxKind}, component_radio_group::parse_component_radio_group, component_slider::parse_component_slider, widget_div::parse_widget_div, widget_image::parse_widget_image, widget_label::parse_widget_label, widget_rectangle::parse_widget_rectangle, widget_sprite::parse_widget_sprite
}, widget::ConstructEssentials
assets::{AssetPath, AssetPathOwned, normalize_path},
components::{Component, ComponentWeak},
drawing::{self},
globals::WguiGlobals,
layout::{Layout, LayoutParams, LayoutState, Widget, WidgetID, WidgetMap, WidgetPair},
log::LogErr,
parser::{
component_button::parse_component_button,
component_checkbox::{CheckboxKind, parse_component_checkbox},
component_radio_group::parse_component_radio_group,
component_slider::parse_component_slider,
widget_div::parse_widget_div,
widget_image::parse_widget_image,
widget_label::parse_widget_label,
widget_rectangle::parse_widget_rectangle,
widget_sprite::parse_widget_sprite,
},
widget::ConstructEssentials,
};
use anyhow::Context;
use ouroboros::self_referencing;
@@ -903,10 +918,20 @@ fn parse_child<'a>(
new_widget_id = Some(parse_component_slider(ctx, parent_id, &attribs)?);
}
"CheckBox" => {
new_widget_id = Some(parse_component_checkbox(ctx, parent_id, &attribs, CheckboxKind::CheckBox)?);
new_widget_id = Some(parse_component_checkbox(
ctx,
parent_id,
&attribs,
CheckboxKind::CheckBox,
)?);
}
"RadioBox" => {
new_widget_id = Some(parse_component_checkbox(ctx, parent_id, &attribs, CheckboxKind::RadioBox)?);
new_widget_id = Some(parse_component_checkbox(
ctx,
parent_id,
&attribs,
CheckboxKind::RadioBox,
)?);
}
"RadioGroup" => {
new_widget_id = Some(parse_component_radio_group(file, ctx, child_node, parent_id, &attribs)?);
@@ -1104,7 +1129,10 @@ fn get_doc_from_asset_path(
allow_dtd: true,
..Default::default()
};
roxmltree::Document::parse_with_options(xml, opt).context("Unable to parse XML").log_err_with(&asset_path).unwrap()
roxmltree::Document::parse_with_options(xml, opt)
.context("Unable to parse XML")
.log_err_with(&asset_path)
.unwrap()
}));
let root = document.borrow_doc().root();

View File

@@ -6,8 +6,8 @@ use taffy::{
use crate::{
drawing,
parser::{
is_percent, parse_color_hex, parse_f32, parse_percent, parse_size_unit, parse_val, print_invalid_attrib,
print_invalid_value, AttribPair,
AttribPair, is_percent, parse_color_hex, parse_f32, parse_percent, parse_size_unit, parse_val,
print_invalid_attrib, print_invalid_value,
},
renderer_vk::text::{FontWeight, HorizontalAlign, TextStyle},
widget::util::WLength,

View File

@@ -2,9 +2,8 @@ use crate::{
assets::AssetPath,
layout::WidgetID,
parser::{
parse_children, parse_widget_universal, print_invalid_attrib,
AttribPair, ParserContext, ParserFile, parse_children, parse_widget_universal, print_invalid_attrib,
style::{parse_color, parse_round, parse_style},
AttribPair, ParserContext, ParserFile,
},
renderer_vk::text::custom_glyph::CustomGlyphData,
widget::image::{WidgetImage, WidgetImageParams},

View File

@@ -2,9 +2,8 @@ use crate::{
drawing::GradientMode,
layout::WidgetID,
parser::{
parse_children, parse_widget_universal, print_invalid_attrib,
AttribPair, ParserContext, ParserFile, parse_children, parse_widget_universal, print_invalid_attrib,
style::{parse_color, parse_round, parse_style},
AttribPair, ParserContext, ParserFile,
},
widget::rectangle::{WidgetRectangle, WidgetRectangleParams},
};

View File

@@ -1,7 +1,7 @@
use crate::{
assets::AssetPath,
layout::WidgetID,
parser::{parse_children, parse_widget_universal, style::parse_style, AttribPair, ParserContext, ParserFile},
parser::{AttribPair, ParserContext, ParserFile, parse_children, parse_widget_universal, style::parse_style},
renderer_vk::text::custom_glyph::CustomGlyphData,
widget::sprite::{WidgetSprite, WidgetSpriteParams},
};

View File

@@ -14,10 +14,10 @@ use vulkano::{
use crate::{
drawing::{Boundary, ImagePrimitive},
gfx::{
BLEND_ALPHA, WGfx,
cmd::GfxCommandBuffer,
pass::WGfxPass,
pipeline::{WGfxPipeline, WPipelineCreateInfo},
WGfx, BLEND_ALPHA,
},
renderer_vk::{
model_buffer::ModelBuffer,

View File

@@ -10,10 +10,10 @@ use vulkano::{
use crate::{
drawing::{Boundary, Rectangle},
gfx::{
BLEND_ALPHA, WGfx,
cmd::GfxCommandBuffer,
pass::WGfxPass,
pipeline::{WGfxPipeline, WPipelineCreateInfo},
WGfx, BLEND_ALPHA,
},
renderer_vk::model_buffer::ModelBuffer,
};

View File

@@ -3,8 +3,8 @@ use std::{
f32,
hash::{DefaultHasher, Hasher},
sync::{
atomic::{AtomicUsize, Ordering},
Arc, Weak,
atomic::{AtomicUsize, Ordering},
},
};

View File

@@ -4,9 +4,9 @@ use crate::{
};
use super::{
ContentType, FontSystem, GlyphDetails, GpuCacheStatus, SwashCache, TextArea,
custom_glyph::{CustomGlyphCacheKey, RasterizeCustomGlyphRequest, RasterizedCustomGlyph},
text_atlas::{GlyphVertex, TextAtlas, TextPipeline},
ContentType, FontSystem, GlyphDetails, GpuCacheStatus, SwashCache, TextArea,
};
use cosmic_text::{Color, SubpixelBin, SwashContent};
use etagere::size2;