I am trying to implement some GUI elements in my Urho project. I need some CheckBoxes, Buttons, and Sliders.
I've noticed that the further along the y-axis the element is, the more "off" the clickable area. What I mean is that if the button's position is close to 0,0 it is fine, but if the button's position is (0,300), you have to click significantly below the button (clicking on the button doesn't register).
The same is true for the slider knob. When near the top, it is fine, but as you slide it down you have to click significantly below the knob to grab it.
UIElement _uiRoot; Window _window; private CheckBox _checkBox; private Button _button; private Slider _slider; protected override void Start() { base.Start(); CreateScene(); SetupViewport(); _uiRoot = UI.Root; Input.SetMouseVisible(true, false); var cache = ResourceCache; XmlFile style = cache.GetXmlFile("UI/DefaultStyle.xml"); _uiRoot.SetDefaultStyle(style); InitWindow(); InitControls(); } void InitWindow() { // Create the Window and add it to the UI's root node _window = new Window(); _uiRoot.AddChild(_window); // Set Window size and layout settings _window.SetMinSize(400, 400); _window.SetLayout(LayoutMode.Free, 0, new IntRect(6, 6, 6, 6)); _window.SetAlignment(HorizontalAlignment.Left, VerticalAlignment.Top); _window.Name = "Window"; // Create the Window title Text var windowTitle = new Text(); windowTitle.Name = "WindowTitle"; windowTitle.Value = "Testing"; // Apply styles _window.SetStyleAuto(null); windowTitle.SetStyleAuto(null); } void InitControls() { // Create a CheckBox _checkBox = new CheckBox { Name = "CheckBox", Checked = true, Position = new IntVector2(0, 0) }; _checkBox.Toggled += _checkBox_Toggled; // Create a Button _button = new Button { Name = "Button", MinHeight = 24, MinWidth = 80, Position = new IntVector2(300, 350) }; _button.Pressed += _button_Pressed; _slider = new Slider { Name = "Slider", MinHeight = 300, MinWidth = 12, Range = 20, Position = new IntVector2(10, 50), Orientation = Orientation.Vertical }; _slider.SliderChanged += _slider_SliderChanged; // Add controls to Window window.AddChild(_checkBox); window.AddChild(_button); window.AddChild(_slider); // Apply previously set default style _checkBox.SetStyleAuto(null); _button.SetStyleAuto(null); _slider.SetStyleAuto(null); } private void _slider_SliderChanged(SliderChangedEventArgs obj) { Debug.WriteLine("Slider = " + _slider.Value); } private void _checkBox_Toggled(ToggledEventArgs obj) { Debug.WriteLine("Checkbox = " + _checkBox.Checked); } private void _button_Pressed(PressedEventArgs obj) { Debug.WriteLine("Button clicked"); }