SetSizeHints to a frame loaded by wxXmlResource - wxwidgets

Right now I'm using wxWidgets msw 3.0.5 on Windows 7 and the xrc file was created with wxFormBuilder 3.10.1
Normally I use something like this to avoid my wxframe be resized smaller than my child controls:
MyFrame::MyFrame() : wxFrame( NULL, wxID_ANY, wxT("Sometitle") )
{
wxBoxSizer* frameSizer = new wxBoxSizer( wxVERTICAL );
wxPanel* panel = new wxPanel( this, wxID_ANY );
// ..
frameSizer->Add( panel, 1, wxEXPAND | wxALL, 0 );
SetSizerAndFit( frameSizer );
Centre();
}
But, when I'm use xrc file to load my frame I using like this:
MyFrame::MyFrame()
{
// used in App::OnInit()
// wxXmlResource::Get()->InitAllHandlers();
// wxXmlResource::Get()->Load( wxT("some.xrc" ) );
wxXmlResource::Get()->LoadFrame( this, NULL, wxT("MyFrame") );
// ...
Fit(); // this resize my frame to show my child controls as expected (like SetSizerAndFit does )
SetMinClientSize(GetSize()); // is this the right way?
Centre();
}
Fit() resize my frame same as SetSizerAndFit, but if don't use SetMinClientSize my frame can be horrible resize shriking and hiden my controls. So my questions are:
Is there a feature that I'm missing in wxFormBuilder to avoid resize less the frame child controls?
Using SetMinClientSize is the right way?
Is there are any other ways in xrc file to have the same effect like SetSizerAndFit?
Thanks.
Note: this happens also in my linux wxwidgets library

The names are unfortunately confusing, but SetSizerAndFit() calls SetSizer() and wxSizer::SetSizeHints(), and not wxWindow::Fit() as might be expected. So to have exactly the same behaviour as in the first case you need to call GetSizer()->SetSizeHints(this) in your frame code.
And, FWIW, wxSizer::SetSizeHints() does something sensibly equivalent to
wxSize size = GetBestClientSize();
SetMinClientSize(size);
SetClientSize(size);
i.e. it sets both the current and min sizes, which is what you presumably want.

Related

Programmatically update the signal for a multi-click in vega/vega-lite

Following the example on the website: https://vega.github.io/editor/#/examples/vega-lite/interactive_bar_select_highlight
I want to programmatically set the selections via signals. I realize that I could emulate a click by doing the following
VEGA_DEBUG.view.signal("select_tuple", {"unit":"","fields":[{"type":"E","field":"_vgsid_"}],"values":[1]})
However, I cannot proceed to select another, e.g., the shift select of the 2
VEGA_DEBUG.view.signal("select_tuple", {"unit":"","fields":[{"type":"E","field":"_vgsid_"}],"values":[2]})
This makes sense, since only shift-click accumulates the state.
I tried modifying the accumulated signal
VEGA_DEBUG.view.signal("select", {"_vgsid_":[1,2],"vlMulti":{"or":[{"_vgsid_":1},{"_vgsid_":2}]}})
However, this does not help. Is this not possible? I understand that a custom solution may be possible in hand-rolled vega, as opposed to that compiled from vega-lite.
Thanks.
Just need to set VEGA_DEBUG.view.signal("select_toggle", true) before adding the new select!!
After much research I made this example of how to change the vega-lite brush programmatically
https://observablehq.com/#john-guerra/update-vega-lite-brush-programmatically
Using #koaning example this stack overflow question I figured that you can change the brush by updating "brush_y" (assuming that your selection is called brush) or change the selection using "brush_tuple" (which doesn't seem to update the brush mark)
viewof chart = {
const brush = vl.selectInterval("brush").encodings("y");
const base = vl
.markBar()
.select(brush)
.encode(
vl.x().count(),
vl.y().fieldQ("Horsepower"),
vl.color().if(brush, vl.value("steelblue")).value("gray")
)
.height(maxY);
return base.data(data).render();
}
update = {
// From https://codepen.io/keckelt/pen/bGNQPYq?editors=1111
// brush_y -> brush_tuple -> brush
// Updates on pixels
chart.signal("brush_y", [by0, maxY / 2]);
await chart.runAsync();
}
Crossposting here in case it might be useful for anyone

Hide a view in Titanium so that it does not take physical space

In titanium it is possible to hide a view like so:
$.foo.hide()
or
$.foo.visible = false
However, in both cases the object still seems to take physical space. It is just invisible. In other words it is similar to the CSS property visibility: hidden.
I want it so that it disappears and take no physical space in terms of width or height, so it's similar to the CSS property display: none
How can I do this?
The best hacky solution I have is the following:
$.foo.width = 0;
$.foo.height = 0;
$.foo.left = 0;
$.foo.right = 0;
But that means when I want to make it visible again, I have to set all those properties back to their original values which is a pain and hard to maintain.
First of all, don't afraid of doing some hard coding ;)
Coming to your query, yes, this is true that hiding a view just hide it from UI, but physical-space is still there.
To do what you want, you will need to either remove view on hide & create it on show, or you can use absolute layout in some tricky way.
Other way could be to animate this view using transform property like this:
// on hide
$.foo.animate({
duration : 100,
transform : Ti.UI.create2DMatrix({scale:0})
}, function () {
$.foo.visible = false;
});
// on show
$.foo.visible = true; // we need to make it visible again before resetting its UI state since we hid it after completion of animation in above code
$.foo.animate({
duration : 100,
transform : Ti.UI.create2DMatrix() // passing empty matrix will reset the initial state of this view
});
OR
this could also work but never tried this:
// on hide
$.foo.transform = Ti.UI.create2DMatrix({scale:0});
$.foo.visible = false;
// on show
$.foo.visible = true;
$.foo.transform = Ti.UI.create2DMatrix();

Frame without borders and default controls. Sizers doesn't work

I try to write small GUI programm for windows using wx and wxFrame. I have this code in ctor:
MainFrame::MainFrame(wxPoint pos)
: wxFrame(NULL, wxID_ANY, wxT("Sample text"), pos,
wxDefaultSize, wxBORDER_NONE | wxFRAME_NOTASKBAR)
{
SetSize(wxSize(250, 100));
CreateLayout();
}
And CreateLayout function:
void MainFrame::CreateLayout()
{
wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(new wxStaticText(this, -1, "1000.56"), 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 5);
SetSizer(sizer);
}
As you can see, I want to align text to vertical center of the frame. But with this set of frame style flags sizers doesn't work! They work only if i set wxDEFAULT_FRAME_STYLE! But i need to have frame without borders and capture and close|minimize|maximize buttons, how can I get this work?
In the MainFrame constructor, move the call to SetSize() after the call to CreateLayout(). That's it.
Normally, the call to Show() after creating the frame should make the above unnecessary, but it looks like in this case it doesn't (see the details below). Anyway, I think it makes sense to first set up all the sizers and controls inside the window, and then change the size to trigger a Layout(), just to be on the safe side.
This also means an alternative solution is to leave the call to SetSize() where it is, and force a layout by adding a call to Layout() at the very end of your CreateLayout(). But... I like being efficient (read: lazy); I'd go with the first solution.
EDIT: I've found some information regarding why this happens.
For a wxFrame created with wxDEFAULT_FRAME_STYLE, the call to Show() ends up calling ::ShowWindow(), which triggers a WM_SIZE, which eventually triggers a Layout().
For a wxFrame created with wxBORDER_NONE, ::ShowWindow() doesn't seem to trigger a WM_SIZE, which is why the solutions above for forcing the call to Layout() are necessary.

How do I dynamically change the height of a TableViewRow?

Application Type: mobile
Titanium SDK: 3.1.0.GA
Platform & version: iOS 6.1
Device: iOS Simulator
Host Operating System: OSX 10.8.3
Titanium Studio: 3.1.0.201304151600
I'd like to conditionally show/hide a textfield in a TableViewRow. In order to do this I need to expand the height of the row. The following code doesn't work, though. The TableViewRow is actually an Alloy controller. I first tried animating it before I realized that it can't be animated. Now I'm just trying to change the height and that isn't even working. I've tried using the setHeight method along with just setting the height property directly to no avail.
Any ideas?
var notesVisible = false;
function notes_click() {
if(notesVisible == false) {
Ti.API.info('expanding');
$.row.height = 200;
// $.notes_container.setHeight(124);
notesVisible = true;
} else {
Ti.API.info('contracting');
$.row.height = 75;
$.notes_container.setHeight(0);
notesVisible = false;
}
};
There are two good ways of doing this, both should be done from the click event listener.
Method 1) One way is to directly change the "height" variable of the row
Method 2) The second is to create a new row and replace the current row with the new row
Method 1 is more straightforward but I found it to be glitchy depending on what version of the SDK you are using, but with 3.1.0 it should work. Both methods should be called from the 'click' eventListener as its easier to tell Titanium which row to act on based on the click
So here is an example
currentTableview.addEventListener('click',function(e)
{
// DO whatever your row is supposed to do when clicked
// Now lets change the height of the row to a new height, 200 in this example
e.row.height = 200
}
With Method two, it involves creating a new row and then replacing the current row with this call
currentTableview.updateRow(e.index,newlyCreatedUpdatedRow);
I know its an old question asked by some one but the solution provided will not work and i think best solution for this is by making a recursive function and changes the height of your row and need to play with the visibility of views inside that row hopefully will help someone :)

Change plain line to arrow line in infovis

How to change plain line to arrow line in infovis?
Currently there are some lines between blocks, I found some css files, but I cannot find which content describing the line behaviour such that I can change the plain line to arrow line.
Thanks.
Generally spoken: You can't (and shouldn't) change it via CSS. Define such properties during the setup.
Here's a brief explanation:
The Code that generates and Edge (which is a line in network visualizations) is generated by the Edge method/function which sits inside Options.Edge.js.
The function Edge is a property/module of the $jit object and works like this:
var viz = new $jit.Viz({
Edge: {
overridable: true,
type: 'line',
color: '#fff',
CanvasStyles: {
: '#ccc',
shadowBlur: 10
}
}
} );
It's important that you define overridable as true as you else can't override anything. The parameter that you're searching for is type. The allowed values are line, hyperline, arrow and I'm pretty sure that bezier will work as well - not sure if this is true for every type of graph. You can as well define custom graph Edge types - an example is missing in the documentation.
To change the Line/Edge style, there's another function that triggers before rendering. You just have to define it during the graph registration $jit.Viz( { /* add here */ } ); - code from the example/Spacetree here:
// This method is called right before plotting
// an edge. It's useful for changing an individual edge
// style properties before plotting it.
// Edge data proprties prefixed with a dollar sign will
// override the Edge global style properties.
onBeforePlotLine: function(adj){
if (adj.nodeFrom.selected && adj.nodeTo.selected) {
adj.data.$color = "#eed";
adj.data.$lineWidth = 3;
}
else {
delete adj.data.$color;
delete adj.data.$lineWidth;
}
}
The final step would now be to inspect what add.data can deliver and then either add the style you want or define a new one using a closure.
There might be another way to go on this: Example for a ForceDirected graph. Take a look at the documentation here.
$jit.ForceDirected.Plot.plotLine( adj, canvas, animating );
Maybe you could even use something like this:
var edge = viz.getEdge('Edge_ID');
edge.setData( property, value, type );
Disclaimer: I got no working copy of theJit/InfoViz library around, so I can't help more than that unless you add a JSFiddle example with your code.
Edit
As I just read that you only want to change to the default arrow type, just enter this type during the configuration of the graph.