Skip to content

Float: add unlocalized float to string#12086

Open
Murmele wants to merge 12 commits into
slint-ui:masterfrom
Murmele:mm/fix-path-localized
Open

Float: add unlocalized float to string#12086
Murmele wants to merge 12 commits into
slint-ui:masterfrom
Murmele:mm/fix-path-localized

Conversation

@Murmele

@Murmele Murmele commented Jun 12, 2026

Copy link
Copy Markdown
Member

Add possibility to cast a float to a string unlocalized.

This is required for the Path::command property

The problem is that Path::command float values must not be casted localized to string because the final svg string shall contain only "." as decimal separator

property <float> value: 5.;
Path {
        width: 100px;
        height: 100px;
        commands: "M 0 0 L 0 " + value.to-string-unlocalized() + " A 1 1 0 0 0 100 100 L 100 0 Z"; 
        stroke: red;
        stroke-width: 1px;
    }
  • Rust
  • C++
  • Interpreter

@Murmele Murmele requested a review from ogoffart June 12, 2026 14:28
Comment thread internal/core/context.rs Outdated
@ogoffart

Copy link
Copy Markdown
Member

I don't think this is the right approach, because it misses things where path are first assigned to a string property or stuff like that.

I think the way out is to check if the string contains the decimal separator in there:

PathData::Commands(commands) => {

and do a string replacement to . if that's the case.

@Murmele

Murmele commented Jun 14, 2026

Copy link
Copy Markdown
Member Author

I don't think this is the right approach, because it misses things where path are first assigned to a string property or stuff like that.

I think the way out is to check if the string contains the decimal separator in there:

PathData::Commands(commands) => {

and do a string replacement to . if that's the case.

Yes this is true but for complex strings you have to iterate over all characters which would make it slow on embedded systems.

Approach Comments
Search and replace in the string Slow because iterating over the complete string
Ignore localization during creation Fast, but if the command is assigned first to a string and then assigning to the command, we don't catch it

Reason: Because otherwise the path parser is not able to parse it properly
@tronical

Copy link
Copy Markdown
Member

Yes this is true but for complex strings you have to iterate over all characters which would make it slow on embedded systems.

I don't think we need to be particularly concerned about dynamic path generation on MCU. And on MPU and higher I think that's just fine.

Murmele and others added 10 commits June 15, 2026 14:11
Reason: This does not work reliable, because if the svg command will be assigned to the path not in the init it will fail. The idea now is add an explicit localization function

This reverts commit dd74126.
#Conflicts:
#	internal/compiler/expression_tree.rs
#	internal/core/string.rs
#	tests/cases/translations/decimal_separator.slint
@ogoffart

Copy link
Copy Markdown
Member

(can you please update the PR title and description?)

@Murmele Murmele changed the title parse paths non localized Float: add unlocalized float to string Jun 16, 2026

@ogoffart ogoffart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good.

Just some notes regarding the documentation:

  • The documentation of conversion from float to string could reference this function
  • Not sure if we really need to mention it in the documentation of Path. @tronical what's your opinion?

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.

3 participants