Skip to content

Commit

Permalink
remove the PNG Widget (#13)
Browse files Browse the repository at this point in the history
It is replaced by the more competent Image widget.
  • Loading branch information
matslina authored Oct 27, 2020
1 parent c915305 commit dbd1fcd
Show file tree
Hide file tree
Showing 19 changed files with 35 additions and 249 deletions.
Binary file modified doc/img/widget_Animation_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/img/widget_Box_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/img/widget_Circle_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/img/widget_Column_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/img/widget_Column_1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/img/widget_Marquee_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/img/widget_Row_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/img/widget_Row_1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/img/widget_Stack_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/img/widget_Text_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/img/widget_WrappedText_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 3 additions & 17 deletions doc/widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,11 @@ render.Column(

## Image
Image renders the binary image data passed via `src`. Supported
formats include PNG, and presumably a few others.
formats include PNG, JPEG and GIF.

If `width` or `height` are set, the image will be scaled
accordingly. Otherwise the image's original dimensions are used.
accordingly, with nearest neighbor interpolation. Otherwise the
image's original dimensions are used.

#### Attributes
| Name | Type | Description | Required |
Expand Down Expand Up @@ -190,21 +191,6 @@ render.Marquee(
![](img/widget_Marquee_0.gif)


## PNG
PNG is a widget for rendering a pre-existing PNG.

WARNING: This widget will likely be removed in the near future. Use
Image instead.

#### Attributes
| Name | Type | Description | Required |
| --- | --- | --- | --- |
| `src` | `str` | | **Y** |
| `width` | `int` | | N |
| `height` | `int` | | N |



## Padding
Padding places padding around its child.

Expand Down
10 changes: 5 additions & 5 deletions encode/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ p = render.Padding(pad=3, child=render.Box(width=1, height=2))
p2 = render.Padding(pad=(1,2,3,4), child=render.Box(width=1, height=2))
p3 = render.Padding(pad=1, child=render.Box(width=1, height=2), expanded=True)
# PNG tests
# Image tests
png_src = base64.decode("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX/AAAZ4gk3AAAACklEQVR4nGNiAAAABgADNjd8qAAAAABJRU5ErkJggg==")
png = render.PNG(src = png_src)
assert(png.src == png_src)
assert(0 < png.size()[0])
assert(0 < png.size()[1])
img = render.Image(src = png_src)
assert(img.src == png_src)
assert(0 < img.size()[0])
assert(0 < img.size()[1])
# Row and Column
r1 = render.Row(
Expand Down
5 changes: 3 additions & 2 deletions render/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import (
)

// Image renders the binary image data passed via `src`. Supported
// formats include PNG, and presumably a few others.
// formats include PNG, JPEG and GIF.
//
// If `width` or `height` are set, the image will be scaled
// accordingly. Otherwise the image's original dimensions are used.
// accordingly, with nearest neighbor interpolation. Otherwise the
// image's original dimensions are used.
//
// DOC(Src): Binary image data
// DOC(Width): Scale image to this width
Expand Down
24 changes: 13 additions & 11 deletions render/png_test.go → render/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
// plus sign on a transparent background.
const testPNG = "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAMCAYAAABbayygAAAAOUlEQVQoU2P8z8Dwn4EIwAhSyMjAwIhPLVgNukKYDciaaawQl6dATkCxmmiFMF8PgGeICnAiYpABACrQO/WD80OVAAAAAElFTkSuQmCC"

func TestPNG(t *testing.T) {
func TestImage(t *testing.T) {
raw, _ := base64.StdEncoding.DecodeString(testPNG)
png := &PNG{Src: string(raw)}
img := &Image{Src: string(raw)}

// Size of PNG is independent of bounds
im := png.Paint(image.Rect(0, 0, 0, 0), 0)
// Size of Image is independent of bounds
im := img.Paint(image.Rect(0, 0, 0, 0), 0)
assert.Equal(t, nil, checkImage([]string{
"rrrrrrrrrr",
"r........r",
Expand All @@ -32,11 +32,11 @@ func TestPNG(t *testing.T) {
"r........r",
"rrrrrrrrrr",
}, im))
w, h := png.Size()
w, h := img.Size()
assert.Equal(t, 10, w)
assert.Equal(t, 12, h)

im = png.Paint(image.Rect(0, 0, 100, 100), 0)
im = img.Paint(image.Rect(0, 0, 100, 100), 0)
assert.Equal(t, nil, checkImage([]string{
"rrrrrrrrrr",
"r........r",
Expand All @@ -51,19 +51,21 @@ func TestPNG(t *testing.T) {
"r........r",
"rrrrrrrrrr",
}, im))
w, h = png.Size()
w, h = img.Size()
assert.Equal(t, 10, w)
assert.Equal(t, 12, h)
}

// Check that scaled image is scaled, but don't bother checking
// individual pixels.
func TestPNGScale(t *testing.T) {
func TestImageScale(t *testing.T) {
raw, _ := base64.StdEncoding.DecodeString(testPNG)
png := &PNG{Src: string(raw), Width: 5, Height: 6}
img := &Image{Src: string(raw), Width: 5, Height: 6}

w, h := png.Size()
w, h := img.Size()
assert.Equal(t, 5, w)
assert.Equal(t, 6, h)
png.Paint(image.Rect(0, 0, 0, 0), 0)
im := img.Paint(image.Rect(0, 0, 0, 0), 0)
assert.Equal(t, 5, im.Bounds().Dx())
assert.Equal(t, 6, im.Bounds().Dy())
}
73 changes: 0 additions & 73 deletions render/png.go

This file was deleted.

1 change: 0 additions & 1 deletion runtime/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const DocumentationDirectory = "../doc/"
var RenderWidgets = []render.Widget{
&render.Text{},
&render.Image{},
&render.PNG{},
render.Row{},
render.Column{},
render.Stack{},
Expand Down
129 changes: 0 additions & 129 deletions runtime/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit dbd1fcd

Please sign in to comment.