Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Making art button obey w/h styles.

  • Loading branch information...
commit dcf5027e5e98be60f5adade9dcc68d6b4d6aaa0c 1 parent 1f2248f
@anutron authored
Showing with 31 additions and 3 deletions.
  1. +10 −1 Source/Widgets/ART.Button.js
  2. +21 −2 Tests/Widgets/Art.Button.html
View
11 Source/Widgets/ART.Button.js
@@ -110,7 +110,9 @@ var Button = ART.Button = new Class({
var fontChanged = !!(sheet.fontFamily || sheet.fontVariant || sheet.fontSize || sheet.text);
var boxChanged = !!(sheet.width || sheet.height || sheet.padding || sheet.borderRadius || fontChanged || sheet.pill);
+ var createdGlyph;
if (sheet.glyph || ((this.options.glyph || cs.glyph) && !this.glyphLayer)){
+ createdGlyph = true;
this.options.glyph = sheet.glyph || this.options.glyph || cs.glyph;
if (!this.glyphLayer) this.glyphLayer = new ART.Shape;
this.makeGlyph(this.options.glyph, true);
@@ -124,7 +126,10 @@ var Button = ART.Button = new Class({
}
if (fontChanged) this.setText(sheet.text || this.options.text, true);
}
-
+ if (!createdGlyph && (sheet.glyphWidth || sheet.glyphHeight) && this.glyphLayer){
+ var glyphBounds = this.glyphLayer.measure();
+ this.glyphLayer.scale(cs.glyphWidth / glyphBounds.width, cs.glyphHeight / glyphBounds.height);
+ }
if (boxChanged){
this.resize(cs.width, cs.height + 1);
this._drawBox(cs);
@@ -156,6 +161,10 @@ var Button = ART.Button = new Class({
var cs = this.currentSheet;
if (!this.glyphLayer) return;
this.glyphLayer.draw(glyph);
+ var glyphBounds = this.glyphLayer.measure();
+ if (cs.glyphWidth && cs.glyphHeight) {
+ this.glyphLayer.scale(cs.glyphWidth / glyphBounds.width, cs.glyphHeight / glyphBounds.height);
+ }
this.glyphBounds = this.glyphLayer.measure();
if (!cs.width) cs.width = (this.glyphBounds.right + cs.glyphLeft + cs.glyphRight).round();
if (!cs.height) cs.height = (this.glyphBounds.bottom + cs.glyphTop + cs.glyphBottom).round();
View
23 Tests/Widgets/Art.Button.html
@@ -31,8 +31,8 @@
'cornerRadius': 7,
'cursor': 'pointer',
'glyph-color': hsb(0, 0, 0, 0.6),
- 'glyph-height': 4,
- 'glyph-width': 4,
+ 'glyph-height': 12,
+ 'glyph-width': 12,
'glyph-top': 1,
'glyph-left': 1
});
@@ -41,6 +41,25 @@
window.gs = new ART.Button({text: 'Google Search', className: 'button art', id: 'GoogleSearch', tabIndex: 1});
gs.inject($('container'));
+
+ window.tri = new ART.Button({
+ glyph: ART.Glyphs.triangleLeft,
+ className: 'button art',
+ tabIndex: 1,
+ styles: {
+ width: 24,
+ height: 24,
+ 'glyph-width': 10,
+ 'glyph-height': 10,
+ 'glyph-top': 7,
+ 'glyph-left': 7
+ }
+ });
+
+ tri.inject($('container'));
+
+ gs.inject($('container'));
+
var x = 0;
gs.addEvent('press', function(){
Please sign in to comment.
Something went wrong with that request. Please try again.