[Git][wxwidgets/wxwidgets][master] Place wxGTK wxSlider min/max labels the same way wxMSW does

1 view
Skip to first unread message

Vadim Zeitlin (@_VZ_)

unread,
Jun 1, 2025, 1:41:26 PMJun 1
to wx-commi...@googlegroups.com

Vadim Zeitlin pushed to branch master at wxWidgets / wxWidgets

Commits:

  • ea2beaaf
    by Paul Cornett at 2025-06-01T10:18:25-07:00
    Place wxGTK wxSlider min/max labels the same way wxMSW does
    
    The labels are in line with the slider, not adjacent to the ends.
    See #24106
    

1 changed file:

Changes:

  • src/gtk/slider.cpp
    ... ... @@ -312,32 +312,24 @@ bool wxSlider::Create(wxWindow *parent,
    312 312
             return false;
    
    313 313
         }
    
    314 314
     
    
    315
    -    const bool isVertical = (style & wxSL_VERTICAL) != 0;
    
    315
    +    const bool isVertical = (style & (wxSL_LEFT | wxSL_RIGHT | wxSL_VERTICAL)) != 0;
    
    316 316
         m_scale = gtk_scale_new(GtkOrientation(isVertical), nullptr);
    
    317 317
     
    
    318 318
         if (style & wxSL_MIN_MAX_LABELS)
    
    319 319
         {
    
    320 320
             gtk_widget_show( m_scale );
    
    321 321
     
    
    322
    -        m_widget = gtk_box_new(GtkOrientation(!isVertical), 0);
    
    323
    -        gtk_box_pack_start(GTK_BOX(m_widget), m_scale, true, true, 0);
    
    324
    -
    
    325
    -        GtkWidget* box = gtk_box_new(GtkOrientation(isVertical), 0);
    
    326
    -        gtk_widget_show(box);
    
    327
    -        gtk_box_pack_start(GTK_BOX(m_widget), box, true, true, 0);
    
    322
    +        m_widget = gtk_box_new(GtkOrientation(isVertical), 0);
    
    328 323
     
    
    329 324
             m_minLabel = gtk_label_new(nullptr);
    
    330 325
             gtk_widget_show( m_minLabel );
    
    331
    -        gtk_box_pack_start(GTK_BOX(box), m_minLabel, false, false, 0);
    
    332
    -
    
    333
    -        // expanding empty space between the min/max labels
    
    334
    -        GtkWidget *space = gtk_label_new(nullptr);
    
    335
    -        gtk_widget_show( space );
    
    336
    -        gtk_box_pack_start(GTK_BOX(box), space, true, false, 0);
    
    337 326
     
    
    338 327
             m_maxLabel = gtk_label_new(nullptr);
    
    339 328
             gtk_widget_show( m_maxLabel );
    
    340
    -        gtk_box_pack_end(GTK_BOX(box), m_maxLabel, false, false, 0);
    
    329
    +
    
    330
    +        gtk_box_pack_start(GTK_BOX(m_widget), m_minLabel, false, false, 0);
    
    331
    +        gtk_box_pack_start(GTK_BOX(m_widget), m_scale, true, true, 0);
    
    332
    +        gtk_box_pack_start(GTK_BOX(m_widget), m_maxLabel, false, false, 0);
    
    341 333
         }
    
    342 334
         else
    
    343 335
         {
    
    ... ... @@ -351,26 +343,51 @@ bool wxSlider::Create(wxWindow *parent,
    351 343
         gtk_scale_set_draw_value(GTK_SCALE (m_scale), showValueLabel );
    
    352 344
         if ( showValueLabel )
    
    353 345
         {
    
    346
    +        float xAlign = 0.5f;
    
    347
    +        float yAlign = 0.5f;
    
    348
    +
    
    354 349
             // Position the label appropriately: notice that wxSL_DIRECTION flags
    
    355 350
             // specify the position of the ticks, not label, and so the
    
    356 351
             // label is on the opposite side.
    
    357 352
             GtkPositionType posLabel;
    
    358
    -        if ( style & wxSL_VERTICAL )
    
    353
    +        if (isVertical)
    
    359 354
             {
    
    360 355
                 if ( style & wxSL_LEFT )
    
    356
    +            {
    
    361 357
                     posLabel = GTK_POS_RIGHT;
    
    358
    +                xAlign = 0.25f;
    
    359
    +            }
    
    362 360
                 else // if ( style & wxSL_RIGHT ) -- this is also the default
    
    361
    +            {
    
    363 362
                     posLabel = GTK_POS_LEFT;
    
    363
    +                xAlign = 0.75f;
    
    364
    +            }
    
    364 365
             }
    
    365 366
             else // horizontal slider
    
    366 367
             {
    
    367 368
                 if ( style & wxSL_TOP )
    
    369
    +            {
    
    368 370
                     posLabel = GTK_POS_BOTTOM;
    
    371
    +                yAlign = 0.25f;
    
    372
    +            }
    
    369 373
                 else // if ( style & wxSL_BOTTOM) -- this is again the default
    
    374
    +            {
    
    370 375
                     posLabel = GTK_POS_TOP;
    
    376
    +                yAlign = 0.75f;
    
    377
    +            }
    
    371 378
             }
    
    372 379
     
    
    373 380
             gtk_scale_set_value_pos( GTK_SCALE(m_scale), posLabel );
    
    381
    +
    
    382
    +        if (m_minLabel)
    
    383
    +        {
    
    384
    +            // The value label causes the slider to be somewhat off-center,
    
    385
    +            // try to keep the labels approximately aligned with it.
    
    386
    +            wxGCC_WARNING_SUPPRESS(deprecated-declarations)
    
    387
    +            gtk_misc_set_alignment(GTK_MISC(m_minLabel), xAlign, yAlign);
    
    388
    +            gtk_misc_set_alignment(GTK_MISC(m_maxLabel), xAlign, yAlign);
    
    389
    +            wxGCC_WARNING_RESTORE()
    
    390
    +        }
    
    374 391
         }
    
    375 392
     
    
    376 393
         // Keep full precision in position value
    


View it on GitLab.
You're receiving this email because of your account on gitlab.com. Manage all notifications · Help Notification message regarding https://gitlab.com/wxwidgets/wxwidgets/-/commit/ea2beaaf5b5e0846cc15e9c58e047d282c03d7bc at 1748799683

Reply all
Reply to author
Forward
0 new messages