Skip to content

Commit

Permalink
Issue #9: unneeded double quote purge in lib/, Layout
Browse files Browse the repository at this point in the history
  • Loading branch information
japhb committed Apr 4, 2024
1 parent 072a9a1 commit c63bc1a
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions lib/Terminal/Widgets/Layout.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,21 @@ class Style
$!set-h //= $!min-h if $!min-h.defined && $!max-h.defined && $!min-h == $!max-h;

# Prevent non-sensical styles
fail "Cannot configure a style width with min ($!min-w) and max ($!max-w) swapped"
fail 'Cannot configure a style width with min (' ~ $!min-w
~ ') and max (' ~ $!max-w ~ ') swapped'
if $!min-w.defined && $!max-w.defined && $!min-w > $!max-w;

fail "Cannot configure a style height with min ($!min-h) and max ($!max-h) swapped"
fail 'Cannot configure a style height with min (' ~ $!min-h
~ ') and max (' ~ $!max-h ~ ') swapped'
if $!min-h.defined && $!max-h.defined && $!min-h > $!max-h;

fail "Cannot set a style width ($!set-w) that is not between min ($!min-w) and max ($!max-w)"
fail 'Cannot set a style width (' ~ $!set-w
~ ') that is not between min (' ~ $!min-w ~ ') and max (' ~ $!max-w ~ ')'
if $!set-w.defined && $!min-w.defined && $!min-w > $!set-w
|| $!set-w.defined && $!max-w.defined && $!max-w < $!set-w;

fail "Cannot set a style height ($!set-h) that is not between min ($!min-h) and max ($!max-h)"
fail 'Cannot set a style height (' ~ $!set-h
~ ') that is not between min (' ~ $!min-h ~ ') and max (' ~ $!max-h ~ ')'
if $!set-h.defined && $!min-h.defined && $!min-h > $!set-h
|| $!set-h.defined && $!max-h.defined && $!max-h < $!set-h;
}
Expand All @@ -72,7 +76,9 @@ class Style
~ (' min' if $.minimize-w) ~ ') ' ~
'h:(' ~ ($.min-h, $.set-h, $.max-h).map({ $_ // '*'}).join(':')
~ (' min' if $.minimize-h) ~ ')'
~ (" $.sizing-box p:$padding b:$border m:$margin wc:$wc=$lc+$rc hc:$hc=$tc+$bc"
~ (' ' ~ $.sizing-box ~ ' p:' ~ $padding ~ ' b:' ~ $border ~
' m:' ~ $margin ~ ' wc:' ~ $wc ~ '=' ~ $lc ~ '+' ~ $rc ~
' hc:' ~ $hc ~ '=' ~ $tc ~ '+' ~ $bc
if $.has-framing)
}

Expand Down Expand Up @@ -171,10 +177,10 @@ class Leaf does Dynamic {

multi method gist(Leaf:D:) {
self.gist-name ~ '|' ~
"requested: [$.requested.gist()] " ~
"computed: [$.computed.gist()] " ~
"x:{$.x // '*'} y:{$.y // '*' }" ~
(" --- [$.widget.gist()]" if $.widget)
'requested: [' ~ $.requested.gist ~ '] ' ~
'computed: [' ~ $.computed.gist ~ '] ' ~
'x:' ~ ($.x // '*') ~ ' y:' ~ ($.y // '*') ~
(' --- [' ~ $.widget.gist ~ ']' if $.widget)
}

method all-set(Leaf:D:) { self.is-set }
Expand Down Expand Up @@ -207,11 +213,11 @@ class Node does Dynamic {
multi method gist(Node:D:) {
my @child-gists = @.children.map: *.gist.indent(4);
self.gist-name ~ '|' ~
"requested: [$.requested.gist()] " ~
"computed: [$.computed.gist()] " ~
"x:{$.x // '*'} y:{$.y // '*' }" ~
(" :vertical" if $.vertical) ~
(" --- [$.widget.gist()]" if $.widget) ~
'requested: [' ~ $.requested.gist ~ '] ' ~
'computed: [' ~ $.computed.gist ~ '] ' ~
'x:' ~ ($.x // '*') ~ ' y:' ~ ($.y // '*') ~
(' :vertical' if $.vertical) ~
(' --- [' ~ $.widget.gist ~ ']' if $.widget) ~
($?NL ~ @child-gists.join($?NL) if @.children)
}

Expand Down Expand Up @@ -274,12 +280,12 @@ class Node does Dynamic {
# Check whether min/max are equal (and thus force set to be the same)
# Note that minimums are always defined by this point (though may be 0)
if $max-w.defined && $min-w == $max-w {
fail "Width is set to $set-w, outside of min/max $min-w"
fail 'Width is set to ' ~ $set-w ~ ', outside of min/max ' ~ $min-w
if $set-w.defined && $set-w != $min-w;
$set-w = $min-w;
}
if $max-h.defined && $min-h == $max-h {
fail "Height is set to $set-h, outside of min/max $min-h"
fail 'Height is set to ' ~ $set-h ~ ', outside of min/max ' ~ $min-h
if $set-h.defined && $set-h != $min-h;
$set-h = $min-h;
}
Expand All @@ -293,7 +299,7 @@ class Node does Dynamic {
my $corrected-child-set-w = $child-set-w - $cwc;

if @.children == @child-set-w {
fail "Set width in parent ($set-w) does not match width of children ($child-set-w)"
fail 'Set width in parent (' ~ $set-w ~ ') does not match width of children (' ~ $child-set-w ~ ')'
if $set-w.defined && $set-w != $corrected-child-set-w;
$set-w = $corrected-child-set-w;
}
Expand Down Expand Up @@ -331,7 +337,7 @@ class Node does Dynamic {
my $corrected-child-set-h = $child-set-h - $chc;

if @.children == @child-set-h {
fail "Set height in parent ($set-h) does not match height of children ($child-set-h)"
fail 'Set height in parent (' ~ $set-h ~ ') does not match height of children (' ~ $child-set-h ~ ')'
if $set-h.defined && $set-h != $corrected-child-set-h;
$set-h = $corrected-child-set-h;
}
Expand Down Expand Up @@ -561,7 +567,7 @@ role WidgetBuilding {

#| Throw an exception if a widget with a given id is already known
method !ensure-new-id($id) {
die "This {self.gist-name} already contains a widget with id '$id'"
die 'This ' ~ self.gist-name ~ ' already contains a widget with id ' ~ $id.raku
if %.by-id{$id}:exists;
}

Expand Down

0 comments on commit c63bc1a

Please sign in to comment.