Vixen
02b45cc4
csharp
public abstract class RangeBase

Anything with a value between two bounds.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

A slider, a range slider and a progress bar are one arithmetic problem — where does a number sit between two others — and three ways of showing the answer. The problem is solved once here.

⚠ These controls draw themselves rather than being made of parts. Everything else in this set is elements the cascade positions, and a slider cannot be: a thumb at 37% needs a length no stylesheet was given and no flexbox rule produces. The alternative — writing the position through as an offset — settles a frame late on every resize, because the position depends on a width that only exists after layout has run. So the geometry is computed in OnDraw, where the width is known and the answer is used immediately.

The cost is that the parts cannot be selected on individually. It is paid back in custom properties: --track-color, --fill-color, --thumb-color and --thumb-size are read from the cascade, so a theme still decides how a slider looks and a :hover rule still changes it.

Fields and properties (13)

  • public float Minimum
  • public float Maximum
  • public float Step
  • public Orientation Orientation
  • protected bool IsVertical

    Whether it runs up the screen rather than across it.

  • protected float ThumbSize

    How wide a thumb is.

  • protected Color4 TrackColor

    The track's colour.

  • protected Color4 FillColor

    The filled part's colour.

  • protected Color4 ThumbColor

    A thumb's colour.

  • public static readonly UiPropertyKey MinimumProperty

    Identity for Minimum.

  • public static readonly UiPropertyKey MaximumProperty

    Identity for Maximum.

  • public static readonly UiPropertyKey StepProperty

    Identity for Step.

  • public static readonly UiPropertyKey OrientationProperty

    Identity for Orientation.

Methods (16)

  • protected override void OnCreated()

    Builds whatever this element is made of, once, as it joins a document.

  • protected float Fraction(float value)

    Where a value sits in the range, as zero to one.

  • protected float ValueAt(float fraction)

    The value a fraction of the way along the range, snapped to Step.

  • protected float Snap(float value)

    Brings a value inside the bounds and onto a step.

  • protected Rectangle Rail(Rectangle bounds)

    The strip the fill and the thumbs are drawn on.

  • protected float Extent(Rectangle rail)

    How long the rail is along the axis it runs on.

  • protected float Thickness(Rectangle rail)

    And how wide it is across that axis, which is what rounds its ends.

  • protected Rectangle Span(Rectangle rail, float from, float to)

    The part of the rail between two fractions, as a rectangle.

  • protected void DrawTrack(DrawContext context, Rectangle rail)

    Draws the unfilled strip.

  • protected void DrawThumb(DrawContext context, Rectangle rail, float fraction)

    Draws a thumb centred on a point of the rail.

  • protected float FractionAt(float x, float y)

    Where along the rail a document-space point falls, as zero to one.

  • protected virtual void OnBoundsChanged()

    Called when the bounds move, so a subclass can bring its value back inside them.

  • public void ClearMinimum()

    Unsets Minimum, so it takes its default or its ancestor's value again.

  • public void ClearMaximum()

    Unsets Maximum, so it takes its default or its ancestor's value again.

  • public void ClearStep()

    Unsets Step, so it takes its default or its ancestor's value again.

  • public void ClearOrientation()

    Unsets Orientation, so it takes its default or its ancestor's value again.

Used by (15)

  • ShellHelloUi
  • ColorPickerVixen.Ui.Controls.Advanced
  • ControlVisualTestsVixen.Ui.Controls.Tests
  • DataGridTestsVixen.Ui.Controls.Advanced.Tests
  • ProgressBarVixen.Ui.Controls
  • PropertyGridVixen.Ui.Controls.Advanced
  • RangeInteractionTestsVixen.Ui.Controls.Tests
  • RangeSliderVixen.Ui.Controls
  • SliderVixen.Ui.Controls
  • SurfaceTestsVixen.Ui.Controls.Tests
  • AudioMixerViewVixen.Editor.AssetEditors
  • AudioMixerViewTestsVixen.Editor.AssetEditors.Tests
  • EditorShellVixen.Editor.Ui
  • MarkupBindingTestsVixen.Editor.Inspector.Tests
  • NumberDrawerVixen.Editor.Inspector