Skip to content

Commit c752f2a

Browse files
authored
Merge pull request #4281 from RKBoss6/layoutbtn
[Layout] Round buttons for consistency, use img scale when calculating btn size
2 parents e7d1d0d + 19fe9fb commit c752f2a

1 file changed

Lines changed: 12 additions & 21 deletions

File tree

modules/Layout.js

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -175,23 +175,12 @@ Layout.prototype.render = function (l) {
175175
}, "btn":function(l){"ram";
176176
var x = l.x+(0|l.pad), y = l.y+(0|l.pad),
177177
w = l.w-(l.pad<<1), h = l.h-(l.pad<<1);
178-
var poly = [
179-
x,y+4,
180-
x+4,y,
181-
x+w-5,y,
182-
x+w-1,y+4,
183-
x+w-1,y+h-5,
184-
x+w-5,y+h-1,
185-
x+4,y+h-1,
186-
x,y+h-5,
187-
x,y+4
188-
],
189-
btnborder = l.btnBorderCol!==undefined?l.btnBorderCol:gfx.theme.fg2,
178+
var btnborder = l.btnBorderCol!==undefined?l.btnBorderCol:gfx.theme.fg2,
190179
btnface = l.btnFaceCol!==undefined?l.btnFaceCol:gfx.theme.bg2;
191180
if(l.selected){
192181
btnface = gfx.theme.bgH; btnborder = gfx.theme.fgH;
193182
}
194-
gfx.setColor(btnface).fillPoly(poly).setColor(btnborder).drawPoly(poly);
183+
gfx.setColor(btnface).fillRect({x:x,y:y,w: w,h:h,r:10}).setColor(btnborder).drawRect({x:x,y:y,w: w,h:h,r:10});
195184
if (l.col!==undefined) gfx.setColor(l.col);
196185
if (l.src) gfx.setBgColor(btnface).drawImage(
197186
"function"==typeof l.src?l.src():l.src,
@@ -265,13 +254,15 @@ Layout.prototype.update = function() {
265254
var m = gfx.setFont(l.font).stringMetrics(l.label);
266255
l._w = m.width; l._h = m.height;
267256
}
268-
}, "btn": function(l) {"ram";
269-
if (l.font && l.font.endsWith("%"))
270-
l.font = "Vector"+rnd(gfx.getHeight()*l.font.slice(0,-1)/100);
271-
var m = l.src?gfx.imageMetrics("function"==typeof l.src?l.src():l.src):gfx.setFont(l.font||"6x8:2").stringMetrics(l.label);
272-
l._h = 16 + m.height;
273-
l._w = 20 + m.width;
274-
}, "img": function(l) {"ram";
257+
}, "btn": function(l) { "ram";
258+
if (l.font && l.font.endsWith("%"))
259+
l.font = "Vector"+rnd(gfx.getHeight()*l.font.slice(0,-1)/100);
260+
var s = l.scale || 1, m = l.src
261+
? gfx.imageMetrics("function"==typeof l.src ? l.src() : l.src)
262+
: gfx.setFont(l.font||"6x8:2").stringMetrics(l.label);
263+
l._h = 16 + Math.ceil(m.height * s);
264+
l._w = 20 + Math.ceil(m.width * s);
265+
}, "img": function(l) {"ram";
275266
var m = gfx.imageMetrics("function"==typeof l.src?l.src():l.src), s=l.scale||1; // get width and height out of image
276267
l._w = m.width*s;
277268
l._h = m.height*s;
@@ -364,4 +355,4 @@ Layout.prototype.clear = function(l) {
364355
g.clearRect(l.x,l.y,l.x+l.w-1,l.y+l.h-1);
365356
};
366357

367-
exports = Layout;
358+
exports = Layout;

0 commit comments

Comments
 (0)