diff --git a/src/element.toit b/src/element.toit index 270e589..fd6ec53 100644 --- a/src/element.toit +++ b/src/element.toit @@ -274,6 +274,14 @@ 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 + w -> int?: return w_ h -> int?: return h_ @@ -599,6 +607,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 diff --git a/tests/div-visualized.toit b/tests/div-visualized.toit new file mode 100644 index 0000000..90bd750 --- /dev/null +++ b/tests/div-visualized.toit @@ -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 diff --git a/tests/gold/div-visualized.toit.png b/tests/gold/div-visualized.toit.png new file mode 100644 index 0000000..5d4b53e Binary files /dev/null and b/tests/gold/div-visualized.toit.png differ