[vlc-devel] [PATCH] macosx: Remove sliders from advanced prefs

Marvin Scholz epirat07 at gmail.com
Wed Sep 6 02:11:38 CEST 2017


The sliders in the advanced prefs for range values were very confusing
and most of the time not really helpful anyway.

Now all numeric fields have steppers, regardless if they have a range or
not and the steppers will respect that range or use the types range.
---
 modules/gui/macosx/prefs_widgets.h |  18 --
 modules/gui/macosx/prefs_widgets.m | 344 +++----------------------------------
 2 files changed, 28 insertions(+), 334 deletions(-)

diff --git a/modules/gui/macosx/prefs_widgets.h b/modules/gui/macosx/prefs_widgets.h
index 5ded29529a..1e4f289f7a 100644
--- a/modules/gui/macosx/prefs_widgets.h
+++ b/modules/gui/macosx/prefs_widgets.h
@@ -101,15 +101,6 @@ static NSMenu *o_keys_menu = nil;
 
 @end
 
- at interface RangedIntegerConfigControl : VLCConfigControl
-
-- (id)initWithItem:(module_config_t *)_p_item
-          withView:(NSView *)o_parent_view;
-
-- (IBAction)sliderChanged:(id)sender;
-
- at end
-
 @interface BoolConfigControl : VLCConfigControl
 
 - (id)initWithItem:(module_config_t *)_p_item
@@ -126,15 +117,6 @@ static NSMenu *o_keys_menu = nil;
 
 @end
 
- at interface RangedFloatConfigControl : VLCConfigControl
-
-- (id)initWithItem:(module_config_t *)_p_item
-          withView:(NSView *)o_parent_view;
-
-- (IBAction)sliderChanged:(id)sender;
-
- at end
-
 @interface KeyConfigControl : VLCConfigControl
 
 - (id)initWithItem:(module_config_t *)_p_item
diff --git a/modules/gui/macosx/prefs_widgets.m b/modules/gui/macosx/prefs_widgets.m
index 8d137af46b..4cd2fdc330 100644
--- a/modules/gui/macosx/prefs_widgets.m
+++ b/modules/gui/macosx/prefs_widgets.m
@@ -41,7 +41,6 @@
 #include "prefs_widgets.h"
 
 #define CONFIG_ITEM_STRING_LIST (CONFIG_ITEM_STRING + 10)
-#define CONFIG_ITEM_RANGED_INTEGER (CONFIG_ITEM_INTEGER + 10)
 
 #define LEFTMARGIN  18
 #define RIGHTMARGIN 18
@@ -353,21 +352,6 @@
         NSLeftMouseDraggedMask];                                            \
 }
 
-#define ADD_SLIDER(o_slider, superFrame, x_offset, my_y_offset, my_width,   \
-    tooltip, lower, higher)                                                 \
-{                                                                           \
-    NSRect s_rc = superFrame;                                               \
-    s_rc.origin.x = x_offset;                                               \
-    s_rc.origin.y = my_y_offset;                                            \
-    s_rc.size.height = 21;                                                  \
-    s_rc.size.width = my_width;                                             \
-    o_slider = [[NSSlider alloc] initWithFrame: s_rc];                      \
-    [o_slider setFont:[NSFont systemFontOfSize:0]];                         \
-    [o_slider setToolTip: tooltip];                                         \
-    [o_slider setMaxValue: higher];                                         \
-    [o_slider setMinValue: lower];                                          \
-}
-
 #define ADD_CHECKBOX(o_checkbox, superFrame, x_offset, my_y_offset, label,  \
     tooltip, init_value, position)                                          \
 {                                                                           \
@@ -445,9 +429,6 @@ + (int)calcVerticalMargin:(int)i_curItem lastItem:(int)i_lastItem
                 case CONFIG_ITEM_INTEGER:
                     i_margin = 7;
                     break;
-                case CONFIG_ITEM_RANGED_INTEGER:
-                    i_margin = 5;
-                    break;
                 case CONFIG_ITEM_BOOL:
                     i_margin = 7;
                     break;
@@ -481,9 +462,6 @@ + (int)calcVerticalMargin:(int)i_curItem lastItem:(int)i_lastItem
                 case CONFIG_ITEM_INTEGER:
                     i_margin = 7;
                     break;
-                case CONFIG_ITEM_RANGED_INTEGER:
-                    i_margin = 5;
-                    break;
                 case CONFIG_ITEM_BOOL:
                     i_margin = 7;
                     break;
@@ -518,9 +496,6 @@ + (int)calcVerticalMargin:(int)i_curItem lastItem:(int)i_lastItem
                 case CONFIG_ITEM_INTEGER:
                     i_margin = 10;
                     break;
-                case CONFIG_ITEM_RANGED_INTEGER:
-                    i_margin = 8;
-                    break;
                 case CONFIG_ITEM_BOOL:
                     i_margin = 10;
                     break;
@@ -554,9 +529,6 @@ + (int)calcVerticalMargin:(int)i_curItem lastItem:(int)i_lastItem
                 case CONFIG_ITEM_INTEGER:
                     i_margin = 7;
                     break;
-                case CONFIG_ITEM_RANGED_INTEGER:
-                    i_margin = 6;
-                    break;
                 case CONFIG_ITEM_BOOL:
                     i_margin = 8;
                     break;
@@ -590,45 +562,6 @@ + (int)calcVerticalMargin:(int)i_curItem lastItem:(int)i_lastItem
                 case CONFIG_ITEM_INTEGER:
                     i_margin = 7;
                     break;
-                case CONFIG_ITEM_RANGED_INTEGER:
-                    i_margin = 5;
-                    break;
-                case CONFIG_ITEM_BOOL:
-                    i_margin = 7;
-                    break;
-                case CONFIG_ITEM_KEY:
-                    i_margin = 6;
-                    break;
-                case CONFIG_ITEM_MODULE_LIST:
-                    i_margin = 8;
-                    break;
-                default:
-                    i_margin = 20;
-                    break;
-            }
-            break;
-        case CONFIG_ITEM_RANGED_INTEGER:
-            switch(i_lastItem) {
-                case CONFIG_ITEM_STRING:
-                case CONFIG_ITEM_PASSWORD:
-                    i_margin = 8;
-                    break;
-                case CONFIG_ITEM_STRING_LIST:
-                    i_margin = 7;
-                    break;
-                case CONFIG_ITEM_LOADFILE:
-                case CONFIG_ITEM_SAVEFILE:
-                    i_margin = 8;
-                    break;
-                case CONFIG_ITEM_MODULE:
-                    i_margin = 4;
-                    break;
-                case CONFIG_ITEM_INTEGER:
-                    i_margin = 7;
-                    break;
-                case CONFIG_ITEM_RANGED_INTEGER:
-                    i_margin = 5;
-                    break;
                 case CONFIG_ITEM_BOOL:
                     i_margin = 7;
                     break;
@@ -662,9 +595,6 @@ + (int)calcVerticalMargin:(int)i_curItem lastItem:(int)i_lastItem
                 case CONFIG_ITEM_INTEGER:
                     i_margin = 9;
                     break;
-                case CONFIG_ITEM_RANGED_INTEGER:
-                    i_margin = 7;
-                    break;
                 case CONFIG_ITEM_BOOL:
                     i_margin = 7;
                     break;
@@ -698,9 +628,6 @@ + (int)calcVerticalMargin:(int)i_curItem lastItem:(int)i_lastItem
                 case CONFIG_ITEM_INTEGER:
                     i_margin = 7;
                     break;
-                case CONFIG_ITEM_RANGED_INTEGER:
-                    i_margin = 5;
-                    break;
                 case CONFIG_ITEM_BOOL:
                     i_margin = 7;
                     break;
@@ -734,9 +661,6 @@ + (int)calcVerticalMargin:(int)i_curItem lastItem:(int)i_lastItem
                 case CONFIG_ITEM_INTEGER:
                     i_margin = 9;
                     break;
-                case CONFIG_ITEM_RANGED_INTEGER:
-                    i_margin = 5;
-                    break;
                 case CONFIG_ITEM_BOOL:
                     i_margin = 7;
                     break;
@@ -796,8 +720,6 @@ + (VLCConfigControl *)newControl:(module_config_t *)_p_item
         case CONFIG_ITEM_INTEGER:
             if (_p_item->list_count)
                 control = [[IntegerListConfigControl alloc] initWithItem: _p_item withView: parentView];
-            else if (_p_item->min.i > INT32_MIN && _p_item->max.i < INT32_MAX)
-                control = [[RangedIntegerConfigControl alloc] initWithItem: _p_item withView: parentView];
             else
                 control = [[IntegerConfigControl alloc] initWithItem: _p_item withView: parentView];
             break;
@@ -806,9 +728,6 @@ + (VLCConfigControl *)newControl:(module_config_t *)_p_item
                                                      withView: parentView];
             break;
         case CONFIG_ITEM_FLOAT:
-            if (_p_item->min.f > FLT_MIN && _p_item->max.f < FLT_MAX)
-                control = [[RangedFloatConfigControl alloc] initWithItem: _p_item withView: parentView];
-            else
                 control = [[FloatConfigControl alloc] initWithItem: _p_item withView: parentView];
             break;
             /* don't display keys in the advanced settings, since the current controls
@@ -1341,17 +1260,26 @@ - (id)initWithItem:(module_config_t *)p_item
         [self.label setAutoresizingMask:NSViewNotSizable ];
         [self addSubview: self.label];
 
-        /* build the stepper */
+        /* prepare textfield formatter */
+        NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
+        [formatter setNumberStyle:NSNumberFormatterNoStyle];
+
+        /* Min/Max */
         ADD_STEPPER(o_stepper, mainFrame, mainFrame.size.width - 19,
-                    0, toolTip, -100000, 100000)
-        [o_stepper setIntValue: p_item->value.i];
+                    0, toolTip, p_item->min.i, p_item->max.i);
+        [formatter setMinimum:@(p_item->min.i)];
+        [formatter setMaximum:@(p_item->max.i)];
+
+        [o_stepper setIntegerValue:p_item->value.i];
         [o_stepper setAutoresizingMask:NSViewMaxXMargin ];
         [self addSubview: o_stepper];
 
-        ADD_TEXTFIELD(o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
+        ADD_TEXTFIELD(o_textfield, mainFrame, mainFrame.size.width - 19 - 32,
                       1, 49, toolTip, @"")
-        [o_textfield setIntValue: p_item->value.i];
+        [o_textfield setIntegerValue:p_item->value.i];
         [o_textfield setDelegate: self];
+
+        [o_textfield setFormatter:formatter];
         [[NSNotificationCenter defaultCenter] addObserver: self
                                                  selector: @selector(textfieldChanged:)
                                                      name: NSControlTextDidChangeNotification
@@ -1380,12 +1308,12 @@ - (void) alignWithXPosition:(int)i_xPos
 
 - (IBAction)stepperChanged:(id)sender
 {
-    [o_textfield setIntValue: [o_stepper intValue]];
+    [o_textfield setIntegerValue: [o_stepper integerValue]];
 }
 
 - (void)textfieldChanged:(NSNotification *)o_notification
 {
-    [o_stepper setIntValue: [o_textfield intValue]];
+    [o_stepper setIntegerValue: [o_textfield integerValue]];
 }
 
 - (int)intValue
@@ -1395,7 +1323,7 @@ - (int)intValue
 
 -(void)resetValues
 {
-    [o_textfield setIntValue: config_GetInt(getIntf(), self.p_item->psz_name)];
+    [o_textfield setDoubleValue:config_GetInt(getIntf(), self.p_item->psz_name)];
     [super resetValues];
 }
 
@@ -1489,118 +1417,6 @@ -(void)resetValues
 }
 @end
 
- at interface RangedIntegerConfigControl() <NSTextFieldDelegate>
-{
-    NSSlider        *o_slider;
-    NSTextField     *o_textfield;
-    NSTextField     *o_textfield_min;
-    NSTextField     *o_textfield_max;
-}
- at end
-
- at implementation RangedIntegerConfigControl
-- (id)initWithItem:(module_config_t *)p_item
-          withView:(NSView *)parentView
-{
-    NSRect mainFrame = [parentView frame];
-    NSString *labelString, *toolTip;
-    mainFrame.size.height = 50;
-    mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
-    mainFrame.origin.x = LEFTMARGIN;
-    mainFrame.origin.y = 0;
-
-    if ([super initWithFrame: mainFrame item:p_item] != nil) {
-        self.viewType = CONFIG_ITEM_RANGED_INTEGER;
-
-        toolTip = [[VLCStringUtility sharedInstance] wrapString: _NS(p_item->psz_longtext) toWidth: PREFS_WRAP];
-
-        /* add the label */
-        labelString = _NS(p_item->psz_text);
-        ADD_LABEL(self.label, mainFrame, 0, -3, labelString, toolTip)
-        [self.label setAutoresizingMask:NSViewNotSizable ];
-        [self addSubview: self.label];
-
-        /* build the textfield */
-        ADD_TEXTFIELD(o_textfield, mainFrame, [self.label frame].size.width + 2,
-                      28, 49, toolTip, @"")
-        [o_textfield setIntValue: p_item->value.i];
-        [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
-        [o_textfield setDelegate: self];
-        [[NSNotificationCenter defaultCenter] addObserver: self
-                                                 selector: @selector(textfieldChanged:)
-                                                     name: NSControlTextDidChangeNotification
-                                                   object: o_textfield];
-        [self addSubview: o_textfield];
-
-        /* build the mintextfield */
-        ADD_LABEL(o_textfield_min, mainFrame, 12, -30, @"-8888", @"")
-        [o_textfield_min setIntValue: p_item->min.i];
-        [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
-        [o_textfield_min setAlignment:NSRightTextAlignment];
-        [self addSubview: o_textfield_min];
-
-        /* build the maxtextfield */
-        ADD_LABEL(o_textfield_max, mainFrame,
-                  mainFrame.size.width - 31, -30, @"8888", @"")
-        [o_textfield_max setIntValue: p_item->max.i];
-        [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
-        [self addSubview: o_textfield_max];
-
-        /* build the slider */
-        ADD_SLIDER(o_slider, mainFrame, [o_textfield_min frame].origin.x +
-                   [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
-                   [o_textfield_max frame].size.width -
-                   [o_textfield_max frame].size.width - 14 -
-                   [o_textfield_min frame].origin.x, toolTip,
-                   p_item->min.i, p_item->max.i)
-        [o_slider setIntValue: p_item->value.i];
-        [o_slider setAutoresizingMask:NSViewWidthSizable ];
-        [o_slider setTarget: self];
-        [o_slider setAction: @selector(sliderChanged:)];
-        [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
-         NSLeftMouseDraggedMask];
-        [self addSubview: o_slider];
-
-    }
-    return self;
-}
-
-- (void) alignWithXPosition:(int)i_xPos
-{
-    NSRect frame;
-    frame = [self.label frame];
-    frame.origin.x = i_xPos - frame.size.width - 3;
-    [self.label setFrame:frame];
-
-    frame = [o_textfield frame];
-    frame.origin.x = i_xPos + 2;
-    [o_textfield setFrame:frame];
-}
-
-- (IBAction)sliderChanged:(id)sender
-{
-    [o_textfield setIntValue: [o_slider intValue]];
-}
-
-- (void)textfieldChanged:(NSNotification *)o_notification
-{
-    [o_slider setIntValue: [o_textfield intValue]];
-}
-
-- (int)intValue
-{
-    return [o_slider intValue];
-}
-
-- (void)resetValues
-{
-    int value = config_GetInt(getIntf(), self.p_item->psz_name);
-    [o_textfield setIntValue:value];
-    [o_slider setIntValue:value];
-    [super resetValues];
-}
- at end
-
 @interface FloatConfigControl() <NSTextFieldDelegate>
 {
     NSTextField     *o_textfield;
@@ -1623,22 +1439,29 @@ - (id)initWithItem:(module_config_t *)p_item
         self.viewType = CONFIG_ITEM_INTEGER;
 
         toolTip = [[VLCStringUtility sharedInstance] wrapString: _NS(p_item->psz_longtext) toWidth: PREFS_WRAP];
-
         /* add the label */
         labelString = _NS(p_item->psz_text);
         ADD_LABEL(self.label, mainFrame, 0, -2, labelString, toolTip)
         [self.label setAutoresizingMask:NSViewNotSizable ];
         [self addSubview: self.label];
 
-        /* build the stepper */
+        /* prepare textfield formatter */
+        NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
+        [formatter setNumberStyle:NSNumberFormatterDecimalStyle];
+
+        /* Min/Max */
         ADD_STEPPER(o_stepper, mainFrame, mainFrame.size.width - 19,
-                    0, toolTip, -100000, 100000)
+                    0, toolTip, p_item->min.f, p_item->max.f);
+        [formatter setMinimum:@(p_item->min.f)];
+        [formatter setMaximum:@(p_item->max.f)];
+
         [o_stepper setFloatValue: p_item->value.f];
+        [o_stepper setIncrement:0.5];
         [o_stepper setAutoresizingMask:NSViewMaxXMargin ];
         [self addSubview: o_stepper];
 
         /* build the textfield */
-        ADD_TEXTFIELD(o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
+        ADD_TEXTFIELD(o_textfield, mainFrame, mainFrame.size.width - 19 - 32,
                       1, 49, toolTip, @"")
         [o_textfield setFloatValue: p_item->value.f];
         [o_textfield setDelegate: self];
@@ -1690,117 +1513,6 @@ - (void)resetValues
 }
 @end
 
- at interface RangedFloatConfigControl() <NSTextFieldDelegate>
-{
-    NSSlider        *o_slider;
-    NSTextField     *o_textfield;
-    NSTextField     *o_textfield_min;
-    NSTextField     *o_textfield_max;
-}
- at end
-
- at implementation RangedFloatConfigControl
-- (id)initWithItem:(module_config_t *)p_item
-          withView:(NSView *)parentView
-{
-    NSRect mainFrame = [parentView frame];
-    NSString *labelString, *toolTip;
-    mainFrame.size.height = 50;
-    mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
-    mainFrame.origin.x = LEFTMARGIN;
-    mainFrame.origin.y = 0;
-
-    if ([super initWithFrame:mainFrame item:p_item] != nil) {
-        self.viewType = CONFIG_ITEM_RANGED_INTEGER;
-
-        toolTip = [[VLCStringUtility sharedInstance] wrapString: _NS(p_item->psz_longtext) toWidth: PREFS_WRAP];
-
-        /* add the label */
-        labelString = _NS(p_item->psz_text);
-        ADD_LABEL(self.label, mainFrame, 0, -3, labelString, toolTip)
-        [self.label setAutoresizingMask:NSViewNotSizable ];
-        [self addSubview: self.label];
-
-        /* build the textfield */
-        ADD_TEXTFIELD(o_textfield, mainFrame, [self.label frame].size.width + 2,
-                      28, 49, toolTip, @"")
-        [o_textfield setFloatValue: p_item->value.f];
-        [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
-        [o_textfield setDelegate: self];
-        [[NSNotificationCenter defaultCenter] addObserver: self
-                                                 selector: @selector(textfieldChanged:)
-                                                     name: NSControlTextDidChangeNotification
-                                                   object: o_textfield];
-        [self addSubview: o_textfield];
-
-        /* build the mintextfield */
-        ADD_LABEL(o_textfield_min, mainFrame, 12, -30, @"-8888", @"")
-        [o_textfield_min setFloatValue: p_item->min.f];
-        [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
-        [o_textfield_min setAlignment:NSRightTextAlignment];
-        [self addSubview: o_textfield_min];
-
-        /* build the maxtextfield */
-        ADD_LABEL(o_textfield_max, mainFrame, mainFrame.size.width - 31,
-                  -30, @"8888", @"")
-        [o_textfield_max setFloatValue: p_item->max.f];
-        [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
-        [self addSubview: o_textfield_max];
-
-        /* build the slider */
-        ADD_SLIDER(o_slider, mainFrame, [o_textfield_min frame].origin.x +
-                   [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
-                   [o_textfield_max frame].size.width -
-                   [o_textfield_max frame].size.width - 14 -
-                   [o_textfield_min frame].origin.x, toolTip, p_item->min.f,
-                   p_item->max.f)
-        [o_slider setFloatValue: p_item->value.f];
-        [o_slider setAutoresizingMask:NSViewWidthSizable ];
-        [o_slider setTarget: self];
-        [o_slider setAction: @selector(sliderChanged:)];
-        [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
-         NSLeftMouseDraggedMask];
-        [self addSubview: o_slider];
-
-    }
-    return self;
-}
-
-- (void) alignWithXPosition:(int)i_xPos
-{
-    NSRect frame;
-    frame = [self.label frame];
-    frame.origin.x = i_xPos - frame.size.width - 3;
-    [self.label setFrame:frame];
-
-    frame = [o_textfield frame];
-    frame.origin.x = i_xPos + 2;
-    [o_textfield setFrame:frame];
-}
-
-- (IBAction)sliderChanged:(id)sender
-{
-    [o_textfield setFloatValue: [o_slider floatValue]];
-}
-
-- (void)textfieldChanged:(NSNotification *)o_notification
-{
-    [o_slider setFloatValue: [o_textfield floatValue]];
-}
-
-- (float)floatValue
-{
-    return [o_slider floatValue];
-}
-
-- (void)resetValues
-{
-    [o_textfield setFloatValue: config_GetFloat(getIntf(), self.p_item->psz_name)];
-    [o_slider setFloatValue: config_GetFloat(getIntf(), self.p_item->psz_name)];
-    [super resetValues];
-}
- at end
-
 @interface BoolConfigControl()
 {
     NSButton        *o_checkbox;
-- 
2.11.0 (Apple Git-81)



More information about the vlc-devel mailing list