Skip to content

Commit

Permalink
potential fix for SecondHalfGames#149 - remove clipping clip rect whe…
Browse files Browse the repository at this point in the history
…n pushing new clip rect, more sophisticated example for dropdown to test SecondHalfGames#149
  • Loading branch information
msparkles committed Apr 17, 2024
1 parent f11f4f4 commit 23ea808
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 40 deletions.
2 changes: 1 addition & 1 deletion crates/yakui-core/src/input/input_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ fn hit_test(_dom: &Dom, layout: &LayoutDom, coords: Vec2, output: &mut Vec<Widge

let mut rect = layout_node.rect;
let mut node = layout_node;
while let Some(parent) = node.clipped_by {
if let Some(parent) = node.clipped_by {
node = layout.get(parent).unwrap();
rect = rect.constrain(node.rect);
}
Expand Down
6 changes: 1 addition & 5 deletions crates/yakui-core/src/paint/paint_dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,11 @@ impl PaintDom {

/// Use the given region as the clipping rect for all following paint calls.
fn push_clip(&mut self, region: Rect) {
let mut unscaled = Rect::from_pos_size(
let unscaled = Rect::from_pos_size(
region.pos() * self.scale_factor,
region.size() * self.scale_factor,
);

if let Some(previous) = self.clip_stack.last() {
unscaled = unscaled.constrain(*previous);
}

self.clip_stack.push(unscaled);
}

Expand Down
87 changes: 53 additions & 34 deletions crates/yakui/examples/dropdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,70 @@
#![allow(clippy::collapsible_if)]

use yakui::widgets::Layer;
use yakui::{align, button, column, reflow, use_state, widgets::Pad, Alignment, Dim2};
use yakui::widgets::{Layer, Scrollable};
use yakui::{button, column, reflow, use_state, widgets::Pad, Alignment, Dim2};
use yakui::{constrained, row, Constraints, Vec2};
use yakui_core::Pivot;

pub fn run() {
let open = use_state(|| false);
let options = ["Hello", "World", "Foobar"];
let options = ["Hello", "World", "Foobar", "Meow", "Woof"];
let selected = use_state(|| 0);

align(Alignment::TOP_LEFT, || {
column(|| {
if button("Upper Button").clicked {
println!("Upper button clicked");
}

column(|| {
if button(options[selected.get()]).clicked {
open.modify(|x| !x);
}

if open.get() {
Pad::ZERO.show(|| {
Layer::new().show(|| {
reflow(Alignment::BOTTOM_LEFT, Pivot::TOP_LEFT, Dim2::ZERO, || {
column(|| {
let current = selected.get();
for (i, option) in options.iter().enumerate() {
if i != current {
if button(*option).clicked {
selected.set(i);
open.set(false);
}
}
}
row(|| {
constrained(Constraints::loose(Vec2::new(f32::INFINITY, 50.0)), || {
Scrollable::vertical().show(|| {
column(|| {
if button("Upper Button").clicked {
println!("Upper button clicked");
}

column(|| {
if button(options[selected.get()]).clicked {
open.modify(|x| !x);
}

if open.get() {
Pad::ZERO.show(|| {
Layer::new().show(|| {
reflow(
Alignment::BOTTOM_LEFT,
Pivot::TOP_LEFT,
Dim2::ZERO,
|| {
constrained(
Constraints::loose(Vec2::new(f32::INFINITY, 80.0)),
|| {
Scrollable::vertical().show(|| {
column(|| {
let current = selected.get();
for (i, option) in
options.iter().enumerate()
{
if i != current {
if button(*option).clicked {
selected.set(i);
open.set(false);
}
}
}
});
});
},
);
},
);
});
});
});
}
});
}
});
});

if button("Lower Button").clicked {
println!("Lower button clicked");
}
});

if button("Side Button").clicked {
println!("Side button clicked");
}
});
}

Expand Down

0 comments on commit 23ea808

Please sign in to comment.