From 652d4353a151813f55cfb427858e329ca92b3867 Mon Sep 17 00:00:00 2001 From: Florian Loitsch Date: Tue, 10 Dec 2024 13:07:16 +0100 Subject: [PATCH] Don't clip elements of non-clipping div. The default `Div` is non-clipping. However, when children changed we clipped them. This meant that the initial draw would happily draw elements outside the borders, but further updates would not. --- src/element.toit | 12 ++++++++++ tests/div-visualized.toit | 37 +++++++++++++++++++++++++++++ tests/gold/div-visualized.toit.png | Bin 0 -> 3000 bytes 3 files changed, 49 insertions(+) create mode 100644 tests/div-visualized.toit create mode 100644 tests/gold/div-visualized.toit.png diff --git a/src/element.toit b/src/element.toit index 270e589..b2c5e7b 100644 --- a/src/element.toit +++ b/src/element.toit @@ -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 + w -> int?: return w_ h -> int?: return h_ @@ -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 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 0000000000000000000000000000000000000000..5d4b53e2f75d508181854c9adc934ff29c125223 GIT binary patch literal 3000 zcmeAS@N?(olHy`uVBq!ia0y~yV3J^9V65O^0*cK1CEmcmz+La@;uumf=k1+~eIf2b zEEj&5*y;YSxgM30@_1wU%vCLC))t5GuT5){cG|A&^4$TXlQdxS{PgsC%X2Fxr?DPR z*?m85yXn2_bt^wUu}Sx+2-p@}BYv{-+=LGca+d$loAh~(;zP%qejj61o?AK}YTh*W z(Qc1(#ceI@sn$o!C(e1!!^wZDtn0m!<#|aVxhZc&?zK{`+r=&0hHA(rHh}`>7tkjuJlbl>*B zJJ&Bg=S$D8*`5zZGS=F;2o?}+PhbI2bE6I@SaaiC^QOE0(vz%y1bVR6PFH+c{CeJV zO-Oj|eCy0Kf5O{+WnGWYSZ0P9_-yRW{>SwvyPL{>*5iRZ?=!A;j>4PCFAzb(_d%4BAIgr93{+?9d z=ewSpn-VwO70*9em}3+%76a6Ehjv8AK%IC-Zj;K z9!{>W$?=ezo_6)+;pkt7)lav4*bS8a_v_lV_UWhP<3jH5+gK4XD|Gq!yPs`<7R;`f zn8a^x=|0IAON*ta{6hqE5&wwJ}PG{uMINDA#f zCjQ=@uLJVK%fq*S1Ff3?w(igAGCOskC;r{;|9@>h`?3QQ4wTY6fCnyWM{V9l$BZr-hQt?|(fi!!%`njxgN@xNA71dDZ literal 0 HcmV?d00001