Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't clip elements of non-clipping div. #102

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/element.toit
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,15 @@ class Div extends Element:
if change-tracker and x and y and w and h:
change-tracker.child-invalidated x y w h

child-invalidated x/int y/int w/int h/int --clip/bool=false -> none:
if clip:
super x y w h
else:
if change-tracker:
x2 := x_ + x
y2 := y_ + y
change-tracker.child-invalidated x2 y2 w h
floitsch marked this conversation as resolved.
Show resolved Hide resolved

w -> int?: return w_
h -> int?: return h_

Expand Down Expand Up @@ -599,6 +608,9 @@ class ClippingDiv_ extends Div:
extent --x=x --y=y --w=w --h=h: | outer-x outer-y outer-w outer-h |
change-tracker.child-invalidated outer-x outer-y outer-w outer-h

child-invalidated x/int y/int w/int h/int -> none:
super x y w h --clip

static is-all-transparent opacity -> bool:
if opacity is not ByteArray: return false
return opacity.size == 1 and opacity[0] == 0
Expand Down
37 changes: 37 additions & 0 deletions tests/div-visualized.toit
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (C) 2023 Toitware ApS.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the TESTS_LICENSE file.

// Tests some simple vertical sliders where there is a movable boundary between
// two different backgrounds.

import expect show *
import font show *
import pixel-display show *
import .png-visualizer

main args:
if args.size != 1:
print "Usage: script.toit png-basename"
exit 1
WIDTH ::= 220
HEIGHT ::= 140
driver := TrueColorPngVisualizer WIDTH HEIGHT args[0] --outline=0x4040ff
display := PixelDisplay.true-color driver
display.background = 0x808080

sans10 := Font.get "sans10"
label := Label --x=0 --y=0 --text="foo" --font=sans10
div := Div --x=30 --y=30 --w=(WIDTH - 60) --h=(HEIGHT - 60) [
// Since this isn't a clipping div, the label is drawn, even though it is
// outside the div.
label
]
display.add div

display.draw

label.text = "bar"
display.draw

driver.write-png
Binary file added tests/gold/div-visualized.toit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading