-
-
Notifications
You must be signed in to change notification settings - Fork 194
gtk: Implementable implementation for AccessibleText #1789
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
Merged
bilelmoussaoui
merged 4 commits into
gtk-rs:main
from
felinira:wip/fina/accessible-text-impl
Oct 31, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4a34051
gtk/accessible_text_range: Convert to boxed object to make it usable …
felinira 7e48281
gtk: Implementable implementation for AccessibleText
felinira 19a71f9
examples: Add missing examples to README.md
felinira d86d9dd
examples: Add example for custom AccessibleText implementations
felinira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Implementing the Accessible Text Interface | ||
|
|
||
| This example creates a custom text editing widget that implements the Accessible Text Interface. This interface is used for providing screen reader accessibility to custom widgets. | ||
|
|
||
| To test this implementation, enable the screen reader (Orca is enabled via Super+Alt+S) and edit / navigate the text. | ||
|
|
||
| The widget mostly just delegates its implementation to the parent `TextView`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| mod text_view; | ||
|
|
||
| use gtk::{glib, prelude::*}; | ||
| use text_view::AccessibleTextView; | ||
|
|
||
| fn main() -> glib::ExitCode { | ||
| let application = gtk::Application::builder() | ||
| .application_id("com.github.gtk-rs.examples.accessible_text") | ||
| .build(); | ||
| application.connect_activate(build_ui); | ||
| application.run() | ||
| } | ||
|
|
||
| fn build_ui(application: >k::Application) { | ||
| let window = gtk::ApplicationWindow::new(application); | ||
|
|
||
| window.set_title(Some("Accessible Text Example")); | ||
| window.set_default_size(260, 140); | ||
|
|
||
| let text_view = glib::Object::new::<AccessibleTextView>(); | ||
| window.set_child(Some(&text_view)); | ||
|
|
||
| window.present(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| use gtk::glib; | ||
| use gtk::subclass::prelude::*; | ||
|
|
||
| mod imp { | ||
| use gtk::{graphene, ACCESSIBLE_ATTRIBUTE_OVERLINE, ACCESSIBLE_ATTRIBUTE_OVERLINE_SINGLE}; | ||
|
|
||
| use super::*; | ||
|
|
||
| #[derive(Default)] | ||
| pub struct AccessibleTextView {} | ||
|
|
||
| #[glib::object_subclass] | ||
| impl ObjectSubclass for AccessibleTextView { | ||
| const NAME: &'static str = "AccessibleTextView"; | ||
| type Type = super::AccessibleTextView; | ||
| type ParentType = gtk::TextView; | ||
| type Interfaces = (gtk::AccessibleText,); | ||
| } | ||
|
|
||
| impl ObjectImpl for AccessibleTextView {} | ||
| impl WidgetImpl for AccessibleTextView {} | ||
| impl AccessibleTextImpl for AccessibleTextView { | ||
| fn attributes( | ||
| &self, | ||
| offset: u32, | ||
| ) -> Vec<(gtk::AccessibleTextRange, glib::GString, glib::GString)> { | ||
| let attributes = self.parent_attributes(offset); | ||
| println!("attributes({offset}) -> {attributes:?}"); | ||
| attributes | ||
| } | ||
|
|
||
| fn caret_position(&self) -> u32 { | ||
| let pos = self.parent_caret_position(); | ||
| println!("caret_position() -> {pos}"); | ||
| pos | ||
| } | ||
|
|
||
| fn contents(&self, start: u32, end: u32) -> Option<glib::Bytes> { | ||
| let content = self.parent_contents(start, end); | ||
| println!( | ||
| "contents({start}, {end}) -> {:?}", | ||
| content | ||
| .as_ref() | ||
| .map(|c| std::str::from_utf8(c.as_ref()).unwrap()) | ||
| ); | ||
| content | ||
| } | ||
|
|
||
| fn contents_at( | ||
| &self, | ||
| offset: u32, | ||
| granularity: gtk::AccessibleTextGranularity, | ||
| ) -> Option<(u32, u32, glib::Bytes)> { | ||
| let contents = self.parent_contents_at(offset, granularity); | ||
| println!( | ||
| "contents_at offset({offset}, {granularity:?}) -> {:?}", | ||
| contents | ||
| .as_ref() | ||
| .map(|(s, e, c)| (s, e, std::str::from_utf8(c.as_ref()).unwrap())) | ||
| ); | ||
| contents | ||
| } | ||
|
|
||
| fn default_attributes(&self) -> Vec<(glib::GString, glib::GString)> { | ||
| let mut attrs = self.parent_default_attributes(); | ||
|
|
||
| // Attributes can be added and removed | ||
| attrs.push(( | ||
| ACCESSIBLE_ATTRIBUTE_OVERLINE.to_owned(), | ||
| ACCESSIBLE_ATTRIBUTE_OVERLINE_SINGLE.to_owned(), | ||
| )); | ||
| println!("default_attributes() -> {attrs:?}"); | ||
| attrs | ||
| } | ||
|
|
||
| fn selection(&self) -> Vec<gtk::AccessibleTextRange> { | ||
| let selection = self.parent_selection(); | ||
| println!("selection() -> {selection:?}"); | ||
| selection | ||
| } | ||
|
|
||
| fn extents(&self, start: u32, end: u32) -> Option<graphene::Rect> { | ||
| let extents = self.parent_extents(start, end); | ||
| println!("extents({start}, {end}) -> {extents:?}"); | ||
| extents | ||
| } | ||
|
|
||
| fn offset(&self, point: &graphene::Point) -> Option<u32> { | ||
| let offset = self.parent_offset(point); | ||
| println!("offset({:?}) -> {offset:?}", point); | ||
| offset | ||
| } | ||
| } | ||
|
|
||
| impl TextViewImpl for AccessibleTextView {} | ||
| } | ||
|
|
||
| glib::wrapper! { | ||
| pub struct AccessibleTextView(ObjectSubclass<imp::AccessibleTextView>) | ||
| @extends gtk::Widget, gtk::TextView, | ||
| @implements gtk::Accessible, gtk::AccessibleText, gtk::Buildable, gtk::ConstraintTarget, gtk::Scrollable; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.