Skip to content

Commit

Permalink
Merge pull request #1378 from cogentcore/svg-pixels
Browse files Browse the repository at this point in the history
Misc fixes to svg usage of pixels which is now the wrong size
  • Loading branch information
kkoreilly authored Dec 16, 2024
2 parents 6e4b064 + 2077c89 commit e7d7703
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 20 deletions.
12 changes: 6 additions & 6 deletions core/layout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ func TestLayoutFramesAlignContent(t *testing.T) {
b := NewBody()
b.Styler(func(s *styles.Style) {
if dir == styles.Row {
s.Min.Y.Px(300)
s.Min.Y.Dp(300)
} else {
s.Min.X.Px(300)
s.Min.X.Dp(300)
}
s.Overflow.Set(styles.OverflowVisible)
s.Direction = dir
Expand Down Expand Up @@ -94,9 +94,9 @@ func TestLayoutFramesJustifyContent(t *testing.T) {
b := NewBody()
b.Styler(func(s *styles.Style) {
if dir == styles.Row {
s.Min.X.Px(dsz)
s.Min.X.Dp(dsz)
} else {
s.Min.Y.Px(dsz)
s.Min.Y.Dp(dsz)
}
s.Overflow.Set(styles.OverflowVisible)
s.Direction = dir
Expand Down Expand Up @@ -182,8 +182,8 @@ func plainFrames(parent Widget, grow math32.Vector2) {
for _, sz := range frameSizes {
fr := boxFrame(parent)
fr.Styler(func(s *styles.Style) {
s.Min.X.Px(sz.X)
s.Min.Y.Px(sz.Y)
s.Min.X.Dp(sz.X)
s.Min.Y.Dp(sz.Y)
s.Grow = grow
})
}
Expand Down
2 changes: 1 addition & 1 deletion docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func main() {
}
for _, sz := range frameSizes {
core.NewFrame(fr).Styler(func(s *styles.Style) {
s.Min.Set(units.Px(sz.X), units.Px(sz.Y))
s.Min.Set(units.Dp(sz.X), units.Dp(sz.Y))
s.Background = colors.Scheme.Primary.Base
})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ func makeStyles(ts *core.Tabs) {
}
for _, sz := range frameSizes {
core.NewFrame(fr).Styler(func(s *styles.Style) {
s.Min.Set(units.Px(sz.X), units.Px(sz.Y))
s.Min.Set(units.Dp(sz.X), units.Dp(sz.Y))
s.Background = colors.Scheme.Primary.Base
})
}
Expand Down
2 changes: 1 addition & 1 deletion icons/svg/git-hub.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion styles/paint.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ type Stroke struct {
func (ss *Stroke) Defaults() {
// stroking is off by default in svg
ss.Color = nil
ss.Width.Px(1)
ss.Width.Dp(1)
ss.MinWidth.Dot(.5)
ss.Cap = LineCapButt
ss.Join = LineJoinMiter // Miter not yet supported, but that is the default -- falls back on bevel
Expand Down
10 changes: 4 additions & 6 deletions styles/units/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"fmt"
"strings"

"log/slog"

"cogentcore.org/core/base/errors"
"cogentcore.org/core/base/reflectx"
"golang.org/x/image/math/fixed"
)
Expand Down Expand Up @@ -193,14 +192,13 @@ func (v *Value) SetAny(iface any, key string) error {
*v = val
case *Value:
*v = *val
default: // assume Px as an implicit default
default: // assume Dp as an implicit default
valflt, err := reflectx.ToFloat(iface)
if err == nil {
v.Set(float32(valflt), UnitPx)
v.Dp(float32(valflt))
} else {
err := fmt.Errorf("units.Value: could not set property %q from value: %v of type: %T: %w", key, val, val, err)
slog.Error(err.Error())
return err
return errors.Log(err)
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion svg/rect.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (g *Rect) Render(sv *SVG) {
bs.Style.Set(styles.BorderSolid)
bs.Width.Set(pc.StrokeStyle.Width)
bs.Color.Set(pc.StrokeStyle.Color)
bs.Radius.Set(units.Px(g.Radius.X))
bs.Radius.Set(units.Dp(g.Radius.X))
if g.Radius.X == 0 && g.Radius.Y == 0 {
pc.DrawRectangle(g.Pos.X, g.Pos.Y, g.Size.X, g.Size.Y)
} else {
Expand Down
4 changes: 2 additions & 2 deletions svg/svg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func TestViewBoxParse(t *testing.T) {

func TestCoreLogo(t *testing.T) {
sv := NewSVG(720, 720)
sv.PhysicalWidth.Px(256)
sv.PhysicalHeight.Px(256)
sv.PhysicalWidth.Dp(256)
sv.PhysicalHeight.Dp(256)
sv.Root.ViewBox.Size.Set(1, 1)

outer := colors.Scheme.Primary.Base // #005BC0
Expand Down
2 changes: 1 addition & 1 deletion xyz/text2d.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (txt *Text2D) Defaults() {
txt.Pose.Scale.SetScalar(.005)
txt.Styles.Defaults()
txt.Styles.Font.Size.Pt(36)
txt.Styles.Margin.Set(units.Px(2))
txt.Styles.Margin.Set(units.Dp(2))
txt.Material.Bright = 4 // this is key for making e.g., a white background show up as white..
}

Expand Down

0 comments on commit e7d7703

Please sign in to comment.