Repository navigation
Conversation
The default stays left and top, which keeps existing draw calls in place. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Owner
|
Sorry, I will not accept AI-generated PRs. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds horizontal and vertical alignment for
graphics::text::Text, which is the feature requested in #343.Text::set_alignment/Text::alignmentstore an alignment thatText::drawapplies on every call.Text::draw_alignedtakes the alignment as a parameter for a single call, which is the extra control the issue asks for. It does not change the stored alignment.HorizontalAlignment::LeftandVerticalAlignment::Top. That offset is zero, so existingdrawcalls stay where they are.Center,Right,MiddleandBottomplace the corresponding edge or centre of the glyph bounds on the draw position. The shift happens in local space, before scaling and rotation. The bounds are the same rectangle returned byText::get_bounds.Closes #343.
Tests
New tests in
src/graphics/text.rs:default_alignment_is_left_topleft_top_preserves_existing_layout_origincenter_places_horizontal_centre_on_the_originright_places_right_edge_on_the_originmiddle_places_vertical_centre_on_the_originbottom_places_bottom_edge_on_the_origincenter_and_middle_are_applied_togetherempty_text_is_not_movedquad_translation_preserves_glyph_sizeTextAlignmentalso has a doc test.Commands run locally on macOS (SDL 3.4.18 from Homebrew, Rust 1.99.1):
cargo test— 44 unit tests passed, 7 doc tests passedcargo build --example hello_world --example text— finished successfullycargo clippy --lib --tests --example text --example hello_world -- -D warnings— cleanThe
textexample draws one centered line withdraw_alignedso the new parameter is visible.Made with Cursor