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

egui_winit: Make the clipboard_text and allow_ime state public #3724

Merged
merged 6 commits into from Jan 23, 2024

Conversation

tosti007
Copy link
Contributor

@tosti007 tosti007 commented Dec 20, 2023

The egui_winit::State contains both the clipboard and allow_ime, but these are both private fields. In our implementation we use egui_winit to do most of the lifting, but it would come really in handy if we could access these values.

Instead of making the fields pub we opted for separate get/set functions, that way calling side can't freely replace any of the values fully and it's more in line with the style of the rest of the codebase.

@tosti007 tosti007 force-pushed the egui_winit_pub_fields branch 2 times, most recently from 0aee060 to cb0bfbf Compare December 20, 2023 12:45
Co-authored-by: Marijn Suijten <marijn@traverseresearch.nl>
@tedsteen
Copy link

tedsteen commented Dec 27, 2023

Instead of making the fields pub I opted for getter functions, such that the calling side is discouraged to freely alter the State's internal data.

but the return type is &mut allowing for mutation of the internal data?

@MarijnS95
Copy link
Contributor

allow_ime needs to be mut to be able to tell State that we've already called set_ime_enabled(). This wasn't/isn't conveyed in the original message but is what we need these changes for.

@tedsteen
Copy link

allow_ime needs to be mut to be able to tell State that we've already called set_ime_enabled(). This wasn't/isn't conveyed in the original message but is what we need these changes for.

It was a comment on the fact that the fields where private instead of public. I don't know what the convention is in this repo but I would personally make the fields public instead of writing methods that return a &mut

@MarijnS95
Copy link
Contributor

@tedsteen that comment was written with immutability in mind, but even after correcting that we need mutable access to this field, this matches the fn egui_input()/fn egui_input_mut() pattern. Those functions are already available on State.

@emilk
Copy link
Owner

emilk commented Dec 30, 2023

The difference is that egui_input_mut returns a mutable reference to a big struct. For a simple bool, a set_ function feels a lot more idiomatic imho.

@MarijnS95
Copy link
Contributor

MarijnS95 commented Jan 4, 2024

The difference is that egui_input_mut returns a mutable reference to a big struct. For a simple bool, a set_ function feels a lot more idiomatic imho.

Wasn't suggesting that a _mut() API is better than _set() for bools (though it allows us to get a mutable reference exactly once), just that the OP comment no longer holds (because we exactly need to freely alter the States internal data). We might also make both (allow_ime and egui_input) fields pub and do away with the API though.

@MarijnS95
Copy link
Contributor

Ouch, looks like this missed out on the 0.25 release

tosti007 and others added 2 commits January 9, 2024 10:19
@tosti007 tosti007 force-pushed the egui_winit_pub_fields branch 2 times, most recently from d595298 to e083d88 Compare January 9, 2024 09:25
Co-authored-by: Marijn Suijten <marijns95@gmail.com>
@tosti007
Copy link
Contributor Author

tosti007 commented Jan 9, 2024

The difference is that egui_input_mut returns a mutable reference to a big struct. For a simple bool, a set_ function feels a lot more idiomatic imho.

I opted to take the same approach regarding the clipboard in the last commit, by making a clipboard and set_clipboard function. This way the backing implementation is also free to change if needed in the future.

Ouch, looks like this missed out on the 0.25 release

Sorry, this had slipped my mind after the Christmas holiday D:

@@ -172,6 +172,26 @@ impl State {
self.egui_input.max_texture_side = Some(max_texture_side);
}

/// Fetches text from the clipboard and returns it.
pub fn clipboard_text(&mut self) -> Option<String> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we document why this is mutable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH it's something deep down inside arboard (not sure about smithay), and it isn't obviously documented there other than it being "and get operation" and doing any operation probably requiring mut access.

@MarijnS95
Copy link
Contributor

@emilk @tedsteen any further feedback here?

@tedsteen
Copy link

@emilk @tedsteen any further feedback here?

No

@emilk emilk added the egui-winit porblems related to winit label Jan 23, 2024
@emilk emilk merged commit 2c837d2 into emilk:master Jan 23, 2024
19 of 20 checks passed
@MarijnS95 MarijnS95 deleted the egui_winit_pub_fields branch January 23, 2024 13:13
@emilk emilk changed the title egui_winit: Allow getting the clipboard and allow_ime state egui_winit: Make the clipboard and allow_ime state public Feb 5, 2024
@emilk emilk changed the title egui_winit: Make the clipboard and allow_ime state public egui_winit: Make the clipboard_text and allow_ime state public Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
egui-winit porblems related to winit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants