Skip to content

Fix styling of slider and progress bars (alignment with other widgets, baselines) #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions ipywidgets/static/widgets/js/widget_int.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ define([
* Called when view is rendered.
*/
this.$el
.addClass('ipy-widget widget-hbox widget-slider');
.addClass('ipy-widget widget-hbox widget-hslider');
this.$label = $('<div />')
.appendTo(this.$el)
.addClass('widget-label')
Expand All @@ -28,7 +28,7 @@ define([
.addClass('slider');
// Put the slider in a container
this.$slider_container = $('<div />')
.addClass('widget-hslider')
.addClass('slider-container')
.append(this.$slider);
this.$el.append(this.$slider_container);

Expand Down Expand Up @@ -63,12 +63,10 @@ define([
} else if (name.substring(0, 6) == 'border') {
this.$slider.find('a').css(name, value);
this.$slider_container.css(name, value);
} else if (name == 'width' || name == 'height' || name == 'background') {
} else if (name == 'background') {
this.$slider_container.css(name, value);
} else if (name == 'padding' || name == 'margin') {
this.$el.css(name, value);
} else {
this.$slider.css(name, value);
this.$el.css(name, value);
}
},

Expand Down Expand Up @@ -155,15 +153,15 @@ define([

// Use the right CSS classes for vertical & horizontal sliders
if (orientation=='vertical') {
this.$slider_container
this.$el
.removeClass('widget-hslider')
.addClass('widget-vslider');
this.$el
.removeClass('widget-hbox')
.addClass('widget-vbox');

} else {
this.$slider_container
this.$el
.removeClass('widget-vslider')
.addClass('widget-hslider');
this.$el
Expand Down Expand Up @@ -471,11 +469,12 @@ define([
/**
* Called when view is rendered.
*/
this.$el.addClass('ipy-widget widget-progress');
this.$el.addClass('ipy-widget widget-hprogress');
this.$label = $('<div />')
.appendTo(this.$el)
.addClass('widget-label')
.hide();

this.$progress = $('<div />')
.addClass('progress')
.css('position', 'relative')
Expand All @@ -491,7 +490,7 @@ define([
// Set defaults.
this.update();
this.updateDescription();

this.listenTo(this.model, 'change:bar_style', function(model, value) {
this.update_bar_style();
}, this);
Expand Down Expand Up @@ -528,8 +527,8 @@ define([
this.$el
.removeClass('widget-vbox')
.addClass('widget-hbox');
this.$progress.removeClass('widget-vprogress');
this.$progress.addClass('widget-hprogress');
this.$el.removeClass('widget-vprogress');
this.$el.addClass('widget-hprogress');
this.$bar.css({
'width': percent + '%',
'height': '100%',
Expand All @@ -538,8 +537,8 @@ define([
this.$el
.removeClass('widget-hbox')
.addClass('widget-vbox');
this.$progress.removeClass('widget-hprogress');
this.$progress.addClass('widget-vprogress');
this.$el.removeClass('widget-hprogress');
this.$el.addClass('widget-vprogress');
this.$bar.css({
'width': '100%',
'height': percent + '%',
Expand All @@ -562,17 +561,12 @@ define([
/**
* Set a css attr of the widget view.
*/
if (name.substring(0, 6) == 'border' || name == 'width' ||
name == 'height' || name == 'background' || name == 'margin' ||
name == 'padding') {

this.$progress.css(name, value);
} else if (name == 'color') {
if (name == 'color') {
this.$bar.css('background', value);
} else if (name == 'padding' || name == 'margin') {
this.$el.css(name, value);
} else if (name.substring(0, 6) == 'border' || name == 'background') {
this.$progress.css(name, value);
} else {
this.$bar.css(name, value);
this.$el.css(name, value);
}
},
});
Expand Down
172 changes: 98 additions & 74 deletions ipywidgets/static/widgets/less/widgets.less
Original file line number Diff line number Diff line change
Expand Up @@ -100,87 +100,96 @@
+------------------------------------------+
*/

/* Fix the padding of the slide track so the ui-slider is sized
correctly. */
padding-left : 8px;
padding-right : 2px;
overflow : visible;

/* Default size of the slider */
width : @widget-width;
height : 5px;
max-height : 5px;
margin-top : 15px;
margin-bottom: 12px;

/* Style the slider track */
.slide-track();

/* Make the div a flex box (makes FF behave correctly). */
.hbox();
.slider-container {
/* Fix the padding of the slide track so the ui-slider is sized
correctly. */
padding-left : 8px;
padding-right : 2px;
overflow : visible;

/* Default size of the slider */
flex-grow : 1;
height : 5px;
max-height : 5px;
margin-top : 15px;
margin-bottom: 12px;

/* Style the slider track */
.slide-track();

.ui-slider {
/* Inner, invisible slide div */
/* Make the div a flex box (makes FF behave correctly). */
.hbox();
.box-flex1();

border : 0px;
background : none;

.ui-slider-handle {
width: 12px;
height: 28px;
margin-top: -8px;
border-radius: @border-radius-base;
}

.ui-slider-range {
height : 12px;
margin-top : -4px;
.ui-slider {
/* Inner, invisible slide div */
.hbox();
.box-flex1();

border : 0px;
background : none;

.ui-slider-handle {
width: 12px;
height: 28px;
margin-top: -8px;
border-radius: @border-radius-base;
}

.ui-slider-range {
height : 12px;
margin-top : -4px;
}
}
}
}

.widget-vslider {
/* Vertical jQuery Slider */

/* Fix the padding of the slide track so the ui-slider is sized
correctly. */
padding-bottom : 5px;
overflow : visible;

/* Default size of the slider */
width : 5px;
max-width : 5px;
height : 250px;
margin-left : 14px;

/* Style the slider track */
.slide-track();
width: 50px;
height: 250px;

/* Make the div a flex box (makes FF behave correctly). */
.vbox();

.ui-slider {
/* Inner, invisible slide div */
.slider-container {
/* Fix the padding of the slide track so the ui-slider is sized
correctly. */
padding-bottom : 5px;
overflow : visible;
flex-grow: 1;

/* Default size of the slider */
width : 5px;
max-width : 5px;
margin-left : auto;
margin-right : auto;

/* Style the slider track */
.slide-track();

/* Make the div a flex box (makes FF behave correctly). */
.vbox();
.box-flex1();

border : 0px;
background : none;
margin-left : -4px;
margin-top : 5px;

.ui-slider-handle {
width : 28px;
height : 12px;
margin-left : -9px;
border-radius: @border-radius-base;
}

.ui-slider-range {
width : 12px;
margin-left : -1px;
.ui-slider {
/* Inner, invisible slide div */
.vbox();
.box-flex1();

border : 0px;
background : none;
margin-left : -4px;
margin-top : 5px;

.ui-slider-handle {
width : 28px;
height : 12px;
margin-left : -9px;
border-radius: @border-radius-base;
}

.ui-slider-range {
width : 12px;
margin-left : -1px;
}
}
}
}
Expand Down Expand Up @@ -281,6 +290,7 @@

.widget-combo-btn {
flex-grow: 1;
min-width: 10px;
}
}

Expand All @@ -291,8 +301,14 @@

.widget-hprogress {
/* Progress Bar */
margin-top: 8px;
min-width : @widget-width;
width : @widget-width;
height: 32px;

.progress {
flex-grow: 1;
margin-top: auto;
margin-bottom: auto;
}

.progress-bar {
/* Disable progress bar animation */
Expand All @@ -306,9 +322,16 @@

.widget-vprogress {
/* Progress Bar */
margin-top: 8px;
min-height : 250px;
width: 12px;
height: 250px;
width: 50px;

.progress {
flex-grow: 1;
width: 12px;
margin-left: auto;
margin-right: auto;
margin-bottom: 0;
}

.progress-bar {
/* Disable progress bar animation */
Expand Down Expand Up @@ -363,10 +386,11 @@
}

.widget-readout {
padding-left : 8px;
padding-left : 4px;
padding-top : 5px;
text-align : left;
text-align : center;
vertical-align : text-top;
min-width : 3.5em;
}
}

Expand Down