I'm currenly working on a UWP app using the map control. I'm doing this using mvvm (no framework).
In my viewmodel I do a calculation on how many meters you actually see (width). I do this by calculating how many meters a pixel represent, and then I multiply this by the width of the control. And there is where the problem is.
In WPF you had a mode OneWayToSource, which would set the source value and not change the target value. But this is missing in UWP.
If I use a binding, I must set the width in my viewmodel. And this is something I don't want. I just want to get the width of the map.
And that is not the only problem. I don't actually need the width ,because this gives NaN, what I need is the ActualWidth. But this is a backing field and you can't bind to this from xaml.
Is there a solution for this while still preserving the mvvm pattern?
ActualWidth and ActualHeight should never be the source or target of a binding. They simply don't work in that situation. You'll need to obtain the size of the element by listening to its SizeChanged event. There are 3 ways you can do this:
x:Bind the SizeChanged event to a method in your view model.
Create an attached property which syncs its value to the size of the element by listening to SizeChanged events. You can then TwoWay bind to this property.
Write a behavior which does basically the same thing as 2.
Related
As the document said, TreeView in GTK4 has been deprecated since 4.10. The recommended replacement for it is ColumnView. However, I can't find clear documentation or example about how to build a treeView-like widget in GTK4 by ColumnView.
I found maybe TreeExpander related to it but I still don't know how to deal with it.
A very brief outline of what I did:
Familiarize yourself with how the new dynamic list widgets (Gtk.GridView and Gtk.ColumnView) work for a flat model (GLib.ListStore). There is example code in the Demo app.
Create a Gtk.TreeListModelCreateModelFunc function that takes a model item as a parameter and, if that item has children (e.g. is a folder in a filesystem model), creates and returns a Gtk.ListStore to hold the children. If the child items are already available then they can also be appended to the child model here. This means the child items are preloaded whether or not the row is expanded. For startup performance reasons, you might want to arrange to load them when the row is actually expanded which is more difficult - in this case you have to add a dummy child to the model else the expander will not be displayed.
Create a Gtk.SignalListItemFactory.
In the setup handler, create a display widget as usual then instead of using your display widget as child of the Gtk.ListItem, you create a Gtk.TreeExpander, and make that the child the Gtk.ListItem and make the display widget a child of the expander.
In the bind handler, get the display widget and model item from the supplied object. A complication here is that the object may be a Gtk.TreeListRow whose item might be another Gtk.TreeListRow so getting to the model item is harder. Bind the widget to the model item as usual. Then get the Gtk.TreeListRow from the Gtk.ListItem position and set the expander's list-row property to it.
If you delayed loading the child items then you would need to detect when the row is first expanded. You can connect to the notify signal for the Gtk.TreeListRow.expanded property to do this.
Use a Gtk.TreeListModel with a GLib.ListStore as its root_store as the model of a Gtk.ColumnView (after wrapping in Gtk.SelectionModel as usual). You must set the passthrough property to false else no expanders appear. If you are loading child items on demand then autoexpand should also be false.
If you are using a Gtk.ColumnView with multiple columns, you only need add the expander to the first column. Otherwise the factory signal handlers or similar to the flat model except the bind handler needs to be adapted for Gtk.TreeListRow parameter.
Simplifications and performance improvements may well be possible or later versions of Gtk4 may introduce some conveniences to make it less fiddly.
I am working on a file browser implementation using the above strategy, currently at https://github.com/elementary/files/tree/gtk4-treelistmodel but this may be merged into other branches (or abandoned!). Note that this branch is under development and contains unresolved bugs but the display of items works.
I'm new to AnyLogic and trying to figure out how Agent-based models should be set there. There is a famous Epidemic model, which I'm trying to reproduce. Most tutorials on classical ABM deal with old GUI settings.
For example, in version 8.5+, which is actual now, the Environment object (that was used for positioning of layouts) has been deprecated.
Now I see that new object Canvas is used to put the layout with agents on the page. But the structure of source code file is a bit unclear for me and I've failed to find relevant description how Canvas can be set for the purpose. (Besides I'm not sure that this is recommended way of doing this task.)
Question: I would love to learn the right way to arbitrary position the area with agents on the page. Below you may see what I get by default.
After some playing around, the 'minimalistic' functionality is as follows.
One should create some population with arbitrary name Person (population name people adds automatically).
The following structure of the Project is to be reproduced (arbitrary names are marked with yellow).
Comment: after adding a Canvas called mapCanvas one adds the function setCanvasCellColor with following body:
mapCanvas.fillCircle(person.getX(), person.getY(), 3, color);
It is clear that former two arguments stand for coordinates of a given point, then its size (i.e. 3) and color. Do not forget to add two arguments used in the body, namely, person as Person and color as Color.
From Entry Action of the statechart named state call the just made function. I've put black color here just for the sake of demonstration; chartreuse constant gets used instead in the Epidemic example.
main.setCanvasCellColor(this, black);
Finally, you may run the model to get the following picture.
Note
If one is reluctant to bother with Canvas, use Main - Presentation - xxx_presentation and click Draw agent with offset to this position checkbox.
What would be the best approach to get started on creating something like this:
I could probably get the second & fourth rows created as horizontally scrolled lists, with the first & third rows as just a row with two cards; but how does one draw a line between or connecting two widgets?
The only way i could think of creating such a view is a little complicated (may be iam wrong)Please enlighten me if someone know any packages or simple widgets or some other way to do it .
The core feature of flutter is reusability of code but sadly until now no one has created a GraphView the way i think of doing this is ... Iam not going to implement it here I'll certainly wouldve give it a try soon.
Although I will Share the way i think of implementing it and the steps required to do so.
1) You have to build a container or any widget to hold whatever data
there is in the node.
2) You have to find the coordinates of each of this nodes using a
function say getOffset(). To do this I found a good youtube tutorial
Video to find position and size of a widget. Its actually quite
simple(after i saw the tutorial) you have to create a key for each
node and pass it as the key parameter to the node widget and use the
initstate funtion to create a function which uses the _newBox =
_theKeyYouCreated.currentContext.findRenderObject() to find that object
3) Then use _newBox.localToGlobal(Offset.zero) to get the location
of the object.
4)Now say you got all the location of the containers now just use this
locations to draw some line between these container.If you want some
more beautiful right angled straight line you can first go to through
the y axis then draw the x axis(of course some extra distance to
compensate for the width and heights of widgets is to be used)
5)Drawing lines between two co-ordinates is a pretty straight forward
thing with
canvas.drawLine(p1, p2, paint);
6)Now if you manage to do this for all pairs of nodes You are done.
Seems like a pretty lot of work.I think there are no packages that do this .But its certainly Time to make one. If you manage to to do this just make it in a reusable form and publish it .I'll certainly give a try to implement this after my current project.
I'm finishing a nice app with a relatively small text editor. During implementation of the syntax highlight I found myself in need to change foreground colour attribute of recognized tokens. I noticed that there is a property of NSTextStorage:
var fixesAttributesLazily: Bool { get }
The documentation, regarding it is:
A Boolean value indicating whether the text storage object fixes attributes lazily. (read-only)
Discussion
When subclassing, the default value of this property is NO, meaning that your subclass fixes attributes immediately when they are changed. The system’s concrete subclass overrides this property and sets it to YES.
I really don't know how to interpret this ... but this is what I did:
I'm changing the attributes of th recognised tokens inside textStorage(textStorage: NSTextStorage, didProcessEditing editedMask: NSTextStorageEditActions, range editedRange: NSRange, changeInLength delta: Int) (which is a delegate method of NSTextStorage). Here I'm checking the value of this property - it's FALSE.
I subclassed NSTextStorage exactly as Apple suggest (https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/TextStorageLayer/Tasks/Subclassing.html) and overrode the property. The text view started to behave very strange. Actually with small text it performs OK, but as soon as I open a 4 Mbytes file - it hangs and ... well ... bad things start to happen to my mac. Actually this behaviour doesn't depend on the value of the fixesAttributesLazily property. Maybe my implementation of NSTextStorage is bad or at least not sophisticated.
Any trick of applying attributes in background or lazily or ... something like this is welcomed.
In additional: I know that there are many ways to optimise a syntax highlighted. It may highlight partially, use some kind of logic, based on the changed range ... etc. What I'm looking for is a way to process attribute changes in background. For example currently when I paste 4 Mbyte file to the text view, it first highlights it (which takes 2-3 seconds) and then it visualises it. The effect I'm looking for is the text to appear right away and after time - the colors.
The project I'm working on is written in Swift.
Thanks to everyone in advance for the help. You may reach me via ivailon at gmail dot com for specifics, since I don't want to expose the app here ... at least not yet ;-)
I'm just picking up om.next and have run into a situation where I've got some form inputs realized as components which hold on to local state, e.g. validation state, actual input value, etc--this state is updated and accessed via om.next/update-state! and om.next/get-state. The trouble with this seems to be when I wrap the inputs in a form in a parent component I'm unsure how to get the state held by the input components. Is it better to pass along the parent component as a property of the input component? What about situations where there is no parent component?
It seems to me that there are 2 options for the use case you want to achieve:
pass the parent component as an argument as you said
have an entry in the global app-state that represents the current form being edited, which you can update via transact! irregardless of the component corresponding to the input. This way every component that represents an input knows where in the app-state to update itself (which key in the current form) — probably captured succintly in one mutation function.
1) is probably the easiest to implement given the code you have currently, but I always like to go for 2) because it doesn't deviate from the "single source of truth" opinion that Om Next recommends (and tries to enforce). Form data is in fact business data, which might not be desirable to have scattered in components. Testability is just one advantage that I immediately see from such approach.