fix logic bug in push_scissor_stack

This commit is contained in:
Aleksander 2026-02-16 20:33:43 +01:00
parent 2ddb419676
commit 124d817752
3 changed files with 29 additions and 12 deletions

View File

@ -44,7 +44,6 @@
flex_direction="row"
flex_wrap="wrap"
gap="4"
overflow_y="scroll"
/>
</elements>
</layout>

View File

@ -306,29 +306,33 @@ impl PushScissorStackResult {
}
}
/// Returns true if scissor has been pushed.
/// Returns Some() if scissor has been pushed.
pub fn push_scissor_stack(
transform_stack: &mut TransformStack,
scissor_stack: &mut ScissorStack,
scroll_shift: Vec2,
info: &Option<ScrollbarInfo>,
style: &taffy::Style,
) -> PushScissorStackResult {
) -> Option<PushScissorStackResult> {
let mut boundary_absolute = drawing::Boundary::construct_absolute(transform_stack);
boundary_absolute.pos += scroll_shift;
let do_clip = info.is_some() && has_overflow_clip(style);
if !do_clip {
return None; // Don't care
}
scissor_stack.push(ScissorBoundary(boundary_absolute));
if scissor_stack.is_out_of_bounds() {
return PushScissorStackResult::OutOfBounds;
return Some(PushScissorStackResult::OutOfBounds);
}
if do_clip {
PushScissorStackResult::VisibleAndClip
Some(PushScissorStackResult::VisibleAndClip)
} else {
PushScissorStackResult::VisibleDontClip
Some(PushScissorStackResult::VisibleDontClip)
}
}
@ -380,7 +384,9 @@ fn draw_widget(
let starting_scissor_set_count = internal.scissor_set_count;
let scissor_result = push_scissor_stack(state.transform_stack, state.scissor_stack, scroll_shift, &info, style);
if scissor_result == PushScissorStackResult::VisibleAndClip {
if let Some(scissor_result) = &scissor_result
&& *scissor_result == PushScissorStackResult::VisibleAndClip
{
if params.debug_draw {
let mut boundary_relative = drawing::Boundary::construct_relative(state.transform_stack);
boundary_relative.pos += scroll_shift;
@ -403,12 +409,17 @@ fn draw_widget(
style,
};
if scissor_result.should_display() {
if scissor_result
.as_ref()
.is_none_or(PushScissorStackResult::should_display)
{
widget_state.draw_all(state, &draw_params);
draw_children(params, state, node_id, internal, false);
}
state.scissor_stack.pop();
if scissor_result.is_some() {
state.scissor_stack.pop();
}
let current_scissor_set_count = internal.scissor_set_count;

View File

@ -8,7 +8,9 @@ use std::{
use crate::{
animation::Animations,
components::{self, Component, ComponentWeak, FocusChangeData, RefreshData},
drawing::{self, ANSI_BOLD_CODE, ANSI_RESET_CODE, Boundary, push_scissor_stack, push_transform_stack},
drawing::{
self, ANSI_BOLD_CODE, ANSI_RESET_CODE, Boundary, PushScissorStackResult, push_scissor_stack, push_transform_stack,
},
event::{self, CallbackDataCommon, EventAlterables},
globals::WguiGlobals,
sound::WguiSoundType,
@ -459,7 +461,10 @@ impl Layout {
style,
);
if scissor_result.should_display() {
if scissor_result
.as_ref()
.is_none_or(PushScissorStackResult::should_display)
{
// check children first
self.push_event_children(node_id, event, event_result, alterables, user_data)?;
@ -476,7 +481,9 @@ impl Layout {
}
}
alterables.scissor_stack.pop();
if scissor_result.is_some() {
alterables.scissor_stack.pop();
}
alterables.transform_stack.pop();
Ok(())