Skip to content
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

Slider selection cursor in wrong position when .pos is set via code #26

Open
Bloodninj opened this issue Feb 15, 2022 · 0 comments
Open

Comments

@Bloodninj
Copy link

Expected Behavior

When the pos property of a <slider> within a <sidebar> is set via code, both the background blue graphic and the selection cursor on the slider should move (or expand/shrink in the background's case) to match the new value.

Current Behavior

The background of the slider changes to show the new value, but the selection cursor on the slider resets position to 0.

Steps to Reproduce (for bugs)

  1. Create a <slider> within a <sidebar> and add it to the state
  2. Set the onChange function of the slider to update a variable containing, for example, volume for music
  3. Set the pos property of the slider once the sidebar has been shown via .show()

Media

hl_01Ex5y5JnG.mp4

Test app / minimal test case

PlayState.hx:

package;

import flixel.FlxG;
import flixel.FlxState;
import haxe.ui.Toolkit;
import haxe.ui.containers.SideBar;

class PlayState extends FlxState
{
	var gameVolume = 0.5;
	var mainView:MainView;

	override public function create()
	{
		super.create();
		Toolkit.init();
		Toolkit.autoScale = false;
		mainView = new MainView();
		mainView.setPosition(0, 0);
		add(mainView);

		mainView.mySlider.onChange = (_) ->
		{
			gameVolume = mainView.mySlider.value / 100;
		}
	}

	override public function update(elapsed:Float)
	{
		super.update(elapsed);
		if (FlxG.keys.anyJustPressed([SPACE]))
		{
			if (mainView.hidden)
			{
				mainView.show();
				mainView.mySlider.pos = gameVolume * 100;
			}
			else
				mainView.hide();
		}
	}
}

@:build(haxe.ui.macros.ComponentMacros.build("assets/ui/sliderTest.xml"))
class MainView extends SideBar
{
	override public function new()
	{
		super();
		// mySlider.pos = 30;
	}
}

sliderTest.xml:

<?xml version="1.0" encoding="UTF-8"?>
<sidebar width="200px" height="100%">

    <vbox width="100%" height="100%">
        <slider id="mySlider" width="100px" step="10" majorTicks="20" minorTicks="10" />
    </vbox>

</sidebar>

Context

Trying to keep my game's music volume in a variable and set the slider to the right position when the sidebar menu is hidden and shown.

Your Environment

  • HaxeFlixel 4.11.0
  • Lime 7.9.0
  • OpenFL 9.1.0
  • haxeui-core [git]
  • haxeui-flixel [git]
  • Windows 10 21H2
  • HashLink 1.11, Windows MSVC, HTML5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant