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

Create a setget attribute #18

Open
wyattjsmith1 opened this issue Mar 23, 2021 · 0 comments · May be fixed by #31
Open

Create a setget attribute #18

wyattjsmith1 opened this issue Mar 23, 2021 · 0 comments · May be fixed by #31
Labels
enhancement New feature or request

Comments

@wyattjsmith1
Copy link
Owner

Is your feature request related to a problem? Please describe.
GdScript defines a setget that can be placed on a property like so:

var my_var setget my_var_set, my_var_get


func my_var_set(new_value):
    my_var = new_value


func my_var_get():
    return my_var # Getter must return a value.

Describe the solution you'd like
An attribute can be added to support this behavior:

#[gdrust(extends = Node)]
struct HelloWorld {
    #[export_range(0.0, 10.0)]
    #[setget(my_getter, my_setter)]
    simple_range: f32,
}

impl HelloWorld {
    fn my_getter(&self, owner: TRef<Node>) -> f32 {
        ...
    }
    
    fn my_setter(&self, owner: TRef<Node>, value: f32) {
        ...
    }
}

If a setget is defined, we should remove the field from the struct.

Describe alternatives you've considered
No alternatives. This seems to be the best without question.

@wyattjsmith1 wyattjsmith1 added the enhancement New feature or request label Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant