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

Fix bug with same gradient on two elements #95

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/gradient.toit
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class GradientBackground implements Background:
return hash_

draw canvas/Canvas x/int y/int w/int h/int --autoclipped/bool -> none:
if not rendering_: rendering_ = GradientRendering_.get w h this
if not rendering_ or rendering_.w_ != w or rendering_.h_ != h:
rendering_ = GradientRendering_.get w h this
rendering_.draw canvas x y --autoclipped=autoclipped

static normalize-angle_ angle/int -> int:
Expand Down
Binary file added tests/gold/sized-gradients-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.
39 changes: 39 additions & 0 deletions tests/sized-gradients-visualized.toit
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (C) 2024 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 that using the same gradient on two elements with different
// sizes works as expected. A new GradientRendering is used for the
// second element.

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

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

border := SolidBorder --color=0x000000 --width=3

gradient := GradientBackground --angle=30 --specifiers=[
GradientSpecifier --color=0xffff00 10,
GradientSpecifier --color=0xffc000 50,
GradientSpecifier --color=0x808000 90,
]
gradient-element := Div --x=10 --y=10 --w=50 --h=50 --background=gradient --border=border
display.add gradient-element

gradient-2-element := Div --x=70 --y=10 --w=100 --h=100 --background=gradient --border=border
display.add gradient-2-element

display.draw

driver.write-png