Comments (10)
Hi!
eventMouseClick is for release mouse buttons.
from spacevil.
Hi!
A mouse click is pressing and releasing a button on a widget without exiting it. If I exit the mouse cursor with the button pressed from the widget, and then release it, the click does not occur. How then to handle the release of the mouse button?
from spacevil.
Do you need to do something with the widget that you are leaving, or do something with another widget (which is on hover) when the mouse button is released?
from spacevil.
I am writing a slider that, by clicking on the moved part, remembers that it is pressed and depending on the movement of the mouse, it moves itself. I need to track the mouse release event to stop moving slider.
from spacevil.
Here some code to understand =)
https://pastebin.com/N9YbNQHe
from spacevil.
Yeah, wait a minute! I am writing an example for you))
from spacevil.
OK. Something like that. You need to implement InterfaceDraggable and InterfaceHLayout (for horizontal slider).
import java.awt.Color;
import com.spvessel.spacevil.*;
import com.spvessel.spacevil.Core.*;
import com.spvessel.spacevil.Decorations.Style;
import com.spvessel.spacevil.Flags.*;
// InterfaceDraggable to recieve mouse drag events
// InterfaceHLayout to disable auto position by X axis.
public class MyWidget extends Prototype implements InterfaceDraggable, InterfaceHLayout {
private Rectangle _handler = null;
public MyWidget() {
// appearance of MyWidget
setStyle(Style.getDefaultCommonStyle());
setWidthPolicy(SizePolicy.EXPAND);
setSize(100, 30);
setBackground(121, 223, 152);
// appearance of handler
_handler = new Rectangle();
_handler.setStyle(Style.getDefaultCommonStyle());
_handler.setHeightPolicy(SizePolicy.EXPAND);
_handler.setBackground(Color.BLACK);
_handler.setWidth(20);
}
@Override
public void initElements() {
// add handler
addItem(_handler);
//
eventMouseClick.add(this::onRelease);
eventMouseDrag.add(this::onDrag);
eventMousePress.add(this::onPress);
updateLayout();
}
// all overrides are necessary
@Override
public void setWidth(int width) {
super.setWidth(width);
updateLayout();
}
// InterfaceHLayout implementation
@Override
public void updateLayout() {
_handler.setX(valueToXPos(_percent));
}
float _percent = 0; // percent
private void onPress(InterfaceItem sender, MouseArgs args) {
System.out.println("Press");
_percent = 100.0f / (float) getWidth() * getActualXPos(args.position);
updateLayout();
}
private void onDrag(InterfaceItem sender, MouseArgs args) {
System.out.println("Drag");
_percent = 100.0f / (float) getWidth() * getActualXPos(args.position);
updateLayout();
}
private void onRelease(InterfaceItem sender, MouseArgs args) {
System.out.println("Release");
_percent = 100.0f / (float) getWidth() * getActualXPos(args.position);
updateLayout();
}
// limit our handler by width and position of MyWidget
private int getActualXPos(Position pos) {
int actualX = pos.getX() - _handler.getWidth() / 2;
if (actualX < getX())
actualX = getX();
if (actualX > getX() + getWidth() - _handler.getWidth())
actualX = getX() + getWidth() - _handler.getWidth();
return actualX;
}
private int valueToXPos(float value) {
return (int) ((float) getWidth() / 100.f * value);
}
}
from spacevil.
Updated: I replaced BlankItem (Prototype) with Rectangle (Primitive) so that _handler doesn't get focus.
from spacevil.
Hi!
It works! Thanks!
Do I understand correctly that these two empty interfaces do all the magic?
from spacevil.
You're right. InterfaceDraggable is completely empty and just defines the draggable element within the framework. InterfaceHLayout disables the basic horizontal (basic vertical layout is still working) layout and allows you to control the position of elements in the container. But you need to implement the "updateLayout ()" method and override "setWidth ()" and "setX ()".
Something like that.
I tried to write about it in article: https://www.codeproject.com/Articles/5257813/SpaceVIL-Framework-Cross-Platform-GUI-with-NET-JVM
In this article, you may encounter interfaces called IDraggable due to the .NET version of SpaceVIL. Just remember rule: IDraggable (.NET) <=> InterfaceDraggable (JVM), IHLayout (.NET) <=> InterfaceHLayout
from spacevil.
Related Issues (12)
- Source code of framework HOT 1
- System.AccessViolationException: Attempted to read or write protected memory. HOT 17
- Window doesn`t show, app fail with code -1073741819
- ButtonToggle_0 MouseRelease System.NullReferenceException: Object reference not set to an instance of an object.
- ComboBox example for C# HOT 31
- Impossible to run any example HOT 3
- Unable to find an entry point named 'glfwGetMonitorContentScale' in shared library 'glfw' HOT 7
- C# documentation is out of date HOT 5
- TextEdit.SetFontSize() not setting font size HOT 2
- Table View HOT 2
- Is there a show and wait window function in the framework? HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spacevil.