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

Property minimum, maximum and default values #168

Merged
merged 6 commits into from
Dec 21, 2024
Merged

Conversation

jwharm
Copy link
Owner

@jwharm jwharm commented Dec 21, 2024

With this PR, it will become possible to specify minimum, maximum and default values for GObject properties declared in Java classes with the @Property annotation.

For example:

@Property(minimumValue = "1", maximumValue = "12", defaultValue = "1")
public void setMonth(int month) {
    this.month = month;
}

The @Property parameters minimumValue, maximumValue and defaultValue expect String values. They are transformed by Java-GI to the proper type using Boolean.parseBoolean(), Integer.parseInt() etcetera.

Using these three parameters, Java developers can set the minimum, maximum and default values on the GParamSpec of a property that they defined in Java.

  • The minimum and maximum values are not enforced by Java-GI, so on the Java side the benefits are negligible. In most cases it is advisable to implement minimum and maximum property values in Java itself.
  • The default value is returned by Java-GI for properties that have only a setter method in Java.

For properties with a getter and setter method, either both or neither methods must be annotated with @Property (or else they will not be recognized by Java-GI as a pair). The annotation parameters must be specified on the getter. They can be specified on the setter too, but only the parameters on the getter are actually used.

@jwharm jwharm merged commit bfa5d16 into main Dec 21, 2024
@jwharm jwharm deleted the property-min-max-def branch December 21, 2024 14:42
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

Successfully merging this pull request may close these issues.

1 participant