Jump to content

Slider not scrolling with mousedrag when window is too small


klepto2
 Share

Go to solution Solved by Josh,

Recommended Posts

It seems there is a bug where you can't scroll the slider using mousedragging when the containing window is too small:

#include "UltraEngine.h"

using namespace UltraEngine;

bool RescaleUI(const Event& event, shared_ptr<Object> extra)
{
	float dpiscale = float(event.data) / 100.0f;
	auto ui = dynamic_pointer_cast<Interface>(extra);
	ui->SetScale(dpiscale);
	auto window = dynamic_pointer_cast<Window>(event.source);
	window->SetShape(event.position.x, event.position.y, event.size.x, event.size.y);
	return true;
}

int main(int argc, const char* argv[])
{
	//Get displays
	auto displays = GetDisplays();
	if (displays.empty()) return 1;
	float dpiscale = displays[0]->scale;

	//Create window
	auto mainwindow = CreateWindow("Ultra App Kit", 0, 0, 300 * dpiscale, 400 * dpiscale, displays[0], WINDOW_HIDDEN | WINDOW_CENTER | WINDOW_TITLEBAR | WINDOW_RESIZABLE);

	//Create user interface
	auto ui = CreateInterface(mainwindow);
	iVec2 sz = ui->root->ClientSize();
	auto label = CreateSlider(0, 0, 20, sz.y, ui->root, SLIDER_SCROLLBAR | SLIDER_VERTICAL);
	label->SetLayout(1, 0, 1, 1);
	label->SetRange(200,800);

	//Enable DPI scaling changes
	ui->SetScale(dpiscale);
	ListenEvent(EVENT_WINDOWDPICHANGED, mainwindow, RescaleUI, ui);
	
	//Show the window
	mainwindow->Show();
	mainwindow->Activate();

	while (true)
	{
		const Event event = WaitEvent();
		switch (event.id)
		{
		case EVENT_WIDGETSELECT:
			break;
		case EVENT_WIDGETACTION:
			break;
		case EVENT_WINDOWCLOSE:
			if (event.source == mainwindow) return 0;
			break;
		}
	}
	return 0;
}

When you start this, you can't scroll the slider, but if you resize the window to some extend the dragging starts working.

  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
Link to comment
Share on other sites

As a side node, the scrolling behaviour when dragging with a mouse is a bit uncomfortable. It seems to move with the slower than the actualmousespeed.  The common behaviour would be that  the knob is synchron with the actual mouseposition. Slider_bug.thumb.gif.a1b4598d0941212508574b00574eccf5.gif

  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
Link to comment
Share on other sites

If you have very high numbers, where there are more divisions than actual pixels, the slider is likely to have problems. I might be able to improve the behavior a little, but in general you should try to avoid this situation. It would be better to set the range to 2,8 instead of 200,800.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Well, while I agree that too high values might lead to problems I doubt that this is the case here. 

  1. it only occurs while using the knob dragging with the mouse, setting the value with the mousewheel or directly doesn't have the issue
  2. When I set the values to 2 and 8 I lose a precision of 100px in the case i want Pixel Perfect scrolling ( Imageviewer)

 

 

  • Intel® Core™ i7-8550U @ 1.80 Ghz 
  • 16GB RAM 
  • INTEL UHD Graphics 620
  • Windows 10 Pro 64-Bit-Version
Link to comment
Share on other sites

There are a few different things going on here, so I wanted to eliminate the DPI scaling setting and make a simpler example.

This code demonstrates a slight mismatch between the cursor position and the dragged position when you grab and move the slider knob:
 

#include "UltraEngine.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
	//Get displays
	auto displays = GetDisplays();
	if (displays.empty()) return 1;

	//Create window
	auto mainwindow = CreateWindow("Ultra App Kit", 0, 0, 300, 800, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR | WINDOW_RESIZABLE);

	//Create user interface
	auto ui = CreateInterface(mainwindow);
	iVec2 sz = ui->root->ClientSize();
	auto slider = CreateSlider(0, 0, 20, sz.y, ui->root, SLIDER_SCROLLBAR | SLIDER_VERTICAL);
	slider->SetLayout(1, 0, 1, 1);
	slider->SetRange(4, 200);

	while (true)
	{
		const Event event = WaitEvent();
		switch (event.id)
		{
		case EVENT_WIDGETSELECT:
			break;
		case EVENT_WIDGETACTION:
			break;
		case EVENT_WINDOWCLOSE:
			if (event.source == mainwindow) return 0;
			break;
		}
	}
	return 0;
}


 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

And then this code shows your original reported problem, that the slider cannot be dragged at all if the range exceeds the slider height (presumably):
 

#include "UltraEngine.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
	//Get displays
	auto displays = GetDisplays();
	if (displays.empty()) return 1;
	
	//Create window
	auto mainwindow = CreateWindow("Ultra App Kit", 0, 0, 300, 400, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR | WINDOW_RESIZABLE);

	//Create user interface
	auto ui = CreateInterface(mainwindow);
	iVec2 sz = ui->root->ClientSize();
	auto label = CreateSlider(0, 0, 20, sz.y, ui->root, SLIDER_SCROLLBAR | SLIDER_VERTICAL);
	label->SetLayout(1, 0, 1, 1);
	label->SetRange(200, 800);

	while (true)
	{
		const Event event = WaitEvent();
		switch (event.id)
		{
		case EVENT_WIDGETSELECT:
			break;
		case EVENT_WIDGETACTION:
			break;
		case EVENT_WINDOWCLOSE:
			if (event.source == mainwindow) return 0;
			break;
		}
	}
	return 0;
}

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Okay, I think I have the original problem resolved by leaving some values in floats during a certain calculation and then rounding the result.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • Josh locked this topic
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...