Disable FontSmoothing in Legend text objects - matlab

I am on Matlab R2018a. I want to disable FontSmoothing for text legend entries.
Setting the FontSmoothing property default vaue to 'off' for text objects doesn't seem to apply to text objects created by a legend ;
Using the old syntax [lgd,object_h]=legend(...) is horrible under recent releases : for some reason it leads to a drawnow inside the legend call, thus if I then want to edit the relevant properties of some of object_h (here to set their FontSmoothing to 'off'), there will be two draws, leading to a less responsive call and ugly behavior (two screen refreshes instead of just one). Although this behavior makes it unacceptable to me, I can though use these handles to then set their FontSmoothing property to 'off' and it works.
Not using the old syntax but only the new one lgd=legend(...) thus seems to be the only recourse. I seem to be able to find the text objects by accessing lgd.EntryContainer.NodeChildren(1).Label (1 for the first text object, 2 for the second one, etc). Problem is, property setting seems iffy at best :
set(lgd.EntryContainer.NodeChildren(1).Label,'FontSmoothing','off') doesn't change anything.
set(lgd.EntryContainer.NodeChildren(1).Label,'FontSize',somevalue) doesn't change anything either.
set(lgd.EntryContainer.NodeChildren(1).Label,'String','sometext') does work though.
Anyone have any idea how to proceed ?

Related

AnyLogic - make many edit boxes visible depending on variable

Here is a simplified example of my problem:
I want to make the edit box 1 or 2 visible, depending on whether a checkbox of box 1 or box 2 is checked. The variables "variableCheckbox1" and "variableCheckbox2" are connected to the respective ceckboxes.
I have written a function as shown in the picture. The function is called from the EditBox 1 ("Enabled"). This is a possible solution for ONE box each.
Does anyone have an idea if there is a more elegant way to do this for a very high number of checkboxes / edit boxes?
A possible solution would be to write a function with a switch case for each variable in my model, called from each box. A very inelegant solution would be to make a single function for each box, but I don't consider that a good way.
If you want this for a large number, turn the entire setup into its own agent type: Checkbox and editbox. Instantiate as needed, you can add a parameter to specify what this is about exactly...
This would be the most generic and powerful approach...
if this works for you, you can use replications for checkboxes and editboxes and associate them together through the index... and then just add the code in the visible field of the edit box... Of course you will have to determine their positions programatically

Adding a header to a listbox

I want to know if it's possible to make first two lines (Titles and horizontal line in the image below) always show on top and to be unclickable, to make them something like a header of the current listbox.
I think that your approach is not feasible since this is just not how listboxes work (i.e. it's not a spreadsheet where you fix the top rows). Having said that, you might be able to create something that looks like what you're suggesting, by creating two listboxes one below the other, making the top one read-only or non-interactable (or better yet, make the top one a static text label or a text area).
Another thing I'd like to comment about is the structure of your listbox. In terms of UX, it's uncommon for a user to choose two things at the same time. So even if this makes sense in your context, I would advise to split it into two lists, and have them change each other within callbacks.

MATLAB GUI - How do I remove the CreateFcn callback in my code?

I'm currently learning MATLAB's GUIDE gui programming. I notice that when I place some objects in a figure, a corresponding 'CreateFcn' callback function is creating in the associated .m file. MATLAB's comments state that this function is executed when the object is created (I would consider this a constructor for the object).
However, I've noticed that not all objects seem to have this 'CreateFcn' constructor. Static text objects do not appear to have this callback function. And as of currently, it seems like this function just makes the code more difficult to read. Thus I'm curious if I can delete.
By deleting it, I tend to get an error in my code stating that the function can't be found. So my question: is it possible to delete the 'CreateFcn' method to declutter my code?
Thanks,
Surely it is possible.
Double-click the object to open up the inspector window, locate the "CreateFcn" property and set its value to an empty string. Then go to the .m file and remove the code of CreateFcn. This way MATLAB wouldn't complain about the missing CreateFcn anymore.
CreateFcn is not really a constructor per se, since it happens after all properties of the object are already set. It is more like an optional post-constructor event that gives user an opportunity to further customize the object's initial behavior dynamically. For example, you can customize the object's color at creation depending on the background color on which the object appears. For most control objects, the default behavior is probably already good enough for you. So you can safely remove those CreateFcns until you find a good excuse to use one.
1) Goto the View --> Property Inspector
2) expand the Creation and deletion control, remove the text from CreateFcn and DeleteFcn 3) close the property inspector save the respective GUI (Don't forget to save)
4) remove the callbacks in m-script.

NSTextStorage easily / background attribute change

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 ;-)

How can I save specific window parameters in emacs

I use (current-window-configuration) to save the size, layout etc of windows, and (set-window-configuration ...) to restore them, so that I can toggle between several window setups. However (current-window-configuration) also saves the current point in buffers, and I would like to only save the window sizes and which buffers they hold. I have tried two different ways to make this happen:
According to the function help of current-window-configuration, the variable window-persistent-parameters controls whats get saved. So now I only need a list of the available window-parameters. But when I look at this variable it's value is ((clone-of . t)), and I can't find a list of the available window parameters online.
I also tried looking at the object returned by current-window-configuration. It is a window configuration object, and gets printed as #<window-configuration>. Is there a way to get into this object, see whats inside and change stuff?
The parameters for window-persistent-parameters may be found in this manual page, though it does not seem to help with your question. A different set of parameters may be found by running (window-state-get nil).
The functions that deal with objects returned by (current-window-configuration) are listed here, but it also mentions:
Other primitives to look inside of window configurations would make sense, but are not implemented because we did not need them. See the file winner.el for some more operations on windows configurations.
At any rate, all these look like really low level stuff, so you might be better off just using winner.el rather than a custom made solution.