Comments (4)
Thanks for the issue.
I'm afraid we can't avoid the clone here.
The model needs interior mutability because it is shared between the Slint engine and the application.
Types exposed to Slint are supposed to be fairly cheap to clone anyway.
So i'm going to close this issue since this is not possible.
from slint.
Hmm, in std
, you have RefCell
, which is simply documented as to be used in the correct manner, having to avoid the wrong overlaps of Ref
and RefMut
instances from a single RefCell
. Otherwise, you get panics. Why insist on this kind of atomic operations by cloning the data? As far as I can see, users could be provided short-lived helper types like Ref
/RefMut
, during which the Slint API must not be used in an overboarding way. To encourage not doing much else and drop the helper type early, you may be able to use the approach, "Let me run your closure for you that gives you brief access."
I must say, it's strange to have a MapModel
map closure that you just can't stop from cloning String
s, even though you'd simply need short access to the data.
Perhaps, it would, e.g., become a problem, if struct instances in a model contained another model, and accessing the inner model during a MapModel
map closure could cause a panic. But could this simply be handled with good documentation and advice to clone yourself and drop the helper type early, if need be? Of course, panic messages would also need to give you proper hints.
from slint.
That's why you should use SharedString instead of String so that cloning doesn't allocate.
We can't expose Ref because we don't know what is the exact underlying method used for interior mutability. Could be a Mutex or something else.
from slint.
I wasn't talking about exposing Ref
/RefMut
, but providing similar small helper types (like I talked about a MutTracker
in the other issue). An implementor of Model
wouldn't be forced to use RefCell
to provide this method:
// Lifetimes could be left out in practice, as far as I can see.
fn row_data<'a>(&'a self, row: usize) -> Option<ReadonlyHelperType<'a, Self::Data>>;
ReadonlyHelperType
(not the final name) could even be a generic type parameter on Model
that a Model
implementor would make concrete by specifiying either their own implementation of an associated helper type trait, or by using the Slint API's helper type trait implementation that's suited for usage with RefCell
.
SharedString
is not as sophisticated a type as String
and shouldn't grow rampant into the backend. If you have a String
in the backend from wherever and want to map it to a StandardListViewItem
, which includes a SharedString
, by surrounding the text with more text, you have to allocate a SharedString
; but MapModel
first gives you a clone of the original String
, which is not in the spirit of std
. The next owned instance created should be derived from a reference to the data.
from slint.
Related Issues (20)
- Smart inline debug info in VSCode slint editor HOT 4
- slint-viewer: image loading support via save-data/load-data HOT 4
- New drop-down button widget HOT 2
- `absolute-position` incorrectly documented? HOT 1
- SlintPad error message can't be copied HOT 1
- Should Math.mod only return positive numbers? HOT 1
- Made the Slint Language server crash by passing a '0' to a rowspan. HOT 1
- `assertion failed: !timer.being_activated` HOT 4
- Feature request: cast from the top-level window to a widget inheriting window
- live-preview: Do not list layout-related properties outside of layouts
- rustrover plugin error HOT 1
- Document precedence in case of conflicting layout constraints
- Adding `Math.sign()` HOT 1
- `SpinBox` should support `float`s
- Text rendering regression with femtovg renderer HOT 3
- Make Python loader map snake case to kebab case
- Numbers in text boxes should be right-aligned HOT 3
- Single touch taps not registering as clicks with winit + x11 HOT 5
- slint js: Panics when there is an exception inside callbacks HOT 1
- Slint software renderer doesn't show gradients on rectangle with border (not the rounded case) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slint.