GTK+ menu bar looks terrible - gtk

I'm writing a Gtk+ menu bar following the instruction here.
When packing the bar onto a VBox with
// "FALSE, TRUE" and "FALSE, FALSE" actually makes no difference
gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar,
TRUE, FALSE, 0);
the menu bar looks terrible, like this:
And when I changed to:
gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar,
TRUE, TRUE, 0);
it looks like:
So, how to make the toolbar get a smaller space allocated?

If I understand your question correctly, you want to:
Get rid of the light gray padding around the menu bar.
Do the above without expanding the menu bar to fill the available space.
Therefore, the packing mode of your other widget (namely the button bar below your menu bar) comes into play (for clarity, I'll refer to them as button_hbox and menu_bar, respectively, since both can qualify as "toolbars").
Understanding the boolean layout arguments passed to gtk_box_pack_start() is paramount here:
The first one, expand, is TRUE if the widget should consume the empty space left in its container after layout is computed. Widgets packed this way compete equally for the remaining space.
The second one, fill, is TRUE if the widget should fill the layout space it consumes instead of being centered within it (there comes the light gray padding).
The idea is that you have one (or more, but let's stick to one for now) main widget in main_vbox, and that widget is packed with both expand and fill set to TRUE. The satellite widgets around it are packed with expand set to FALSE and fill set to TRUE. For instance:
+-------------------------------------------+
| Menu bar: expand = FALSE, fill = TRUE |
+-------------------------------------------+
| Toolbar: expand = FALSE, fill = TRUE |
+-------------------------------------------+ ^
| | |
| | | The height of this widget
| Main widget: expand = TRUE, fill = TRUE | | varies depending on the
| | | height of its container.
| | |
+-------------------------------------------+ v
| Status bar: expand = FALSE, fill = TRUE |
+-------------------------------------------+
In your case, since you don't want menu_bar to fill the available space, button_hbox should do so:
// Menu bar: satellite widget, expand = FALSE, fill = TRUE
gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar, FALSE, TRUE, 0);
// Button bar: main widget, expand = TRUE, fill = TRUE
gtk_box_pack_start(GTK_BOX(main_vbox), button_hbox, TRUE, TRUE, 0);

Related

UIStackView distribution with intrinsic content size of one subview prioritised

stackView
+------------+ +
| topView | height: 50 |
+------------+ |
| | |
| | | total height: 300
| bottomView | height: 250 |
| | |
| | |
+------------+ +
I would like to layout two views (topView and bottomView) in a UIStackView (stackView) with these conditions:
stackView has a height (let’s say 300)
topView’s and bottomView’s intrinsic content height is the same (let’s say 50)
topView’s should be rendered with its intrinsic content height (up to stackView’s height) (so 50)
bottomView should take the remaining space (so 250)
if topView’s intrinsic content height changes (let’s say to 100) the distribution should be 100/200
None of the distribution modes of UIStackView can cover this.
Setting a constraint with a constant wouldn’t help here, as the intrinsic content height of topView might change.
So I need some Auto Layout features here. I tried setting different content compression resistance priorities and content hugging priorities. Without success, I still feel like they could be a solution (if I knew how to use them correctly).
It doesn’t seem like a complex problem, I can’t find the right Auto Layout API for this. Any hints?
You should set:
vertical content hugging priority of top view to be more than bottom view
alignment of stack view to fill
distribution of stack view to fill
You should add a width constraint as well, if the top and bottom views do not have intrinsic width.
Demo:

Swift: how to force UIabel to occupy remaining free space

I have a UIView containing:
UIButton: (contentMode = Aspect Fit)
UILabel:(numberOfLines = 0, lineBreakMode = byWordWrapping, contentMode = Aspect Fill)
UISwitch: ()
I would like the width and number of lines of the UILabel to adapt to the content of the localized text of UIButton and UILabel.
How should I proceed ?
Behavior expected:
____________________________________________________________________
| | | |
| UIButton | UILabel | UISwitch |
| | | | |
_________________________________v__________________________________
Fred
You will have to give it the required constraints in order to make it fit as you like. You need to provide more details, in order for me to tell you about the constraints you would want. With current information assuming that your button and switch have fixed widths, and are pinned at leading and trailing of superview end respectively. then go through a check of following constraints
(1) give leading constraint of your label equal to trailing constraint of button
(2) give trailing constraint of your label equal to leading constraint of switch
(3) give top and bottom constraint of your button equal to top and bottom constraint of label
(4) give top and bottom constraint of your switch equal to top and bottom constraint of label
Finally, provide a constraint for the y position of your label, and you are good to go.
Another potential solution is using a horizontal stack view, which will save a lot of these constraints.
Here is what I tried... but the size of my button is not as small as possible (I expext it to fit the text)
So, I have added these constraints
NSLayoutConstraint.activate([
resetButton.leadingAnchor.constraint(equalTo: bottomView.leadingAnchor),
resetButton.trailingAnchor.constraint(equalTo: rawLabel.leadingAnchor),
rawLabel.trailingAnchor.constraint(equalTo: directSwitch.leadingAnchor),
directSwitch.trailingAnchor.constraint(equalTo: bottomView.trailingAnchor),
resetButton.topAnchor.constraint(greaterThanOrEqualTo: bottomView.topAnchor),
rawLabel.topAnchor.constraint(equalTo: bottomView.topAnchor),
directSwitch.topAnchor.constraint(greaterThanOrEqualTo: bottomView.topAnchor),
resetButton.bottomAnchor.constraint(lessThanOrEqualTo: bottomView.bottomAnchor),
rawLabel.bottomAnchor.constraint(equalTo: bottomView.bottomAnchor),
directSwitch.bottomAnchor.constraint(lessThanOrEqualTo: bottomView.bottomAnchor),
resetButton.centerYAnchor.constraint(equalTo: bottomView.centerYAnchor),
rawLabel.centerYAnchor.constraint(equalTo: bottomView.centerYAnchor),
directSwitch.centerYAnchor.constraint(equalTo: bottomView.centerYAnchor)
])
and this viewWillAppear func
override func viewWillAppear(_ animated: Bool) {
resetButton.sizeToFit()
rawLabel.numberOfLines = 0
rawLabel.lineBreakMode = .byWordWrapping
rawLabel.preferredMaxLayoutWidth = bottomView.frame.width - resetButton.frame.width - directSwitch.frame.width
}

How can I make a GUI.Toggle font size and color to be bigger and in black like the example in the screenshot?

The script is EditorWindow type:
What I did inside OnGUI:
void OnGUI()
{
GUIStyle myToggleStyle = new GUIStyle(GUI.skin.toggle);
myToggleStyle.fontSize = 14;
Font myFont = (Font)Resources.Load("Fonts/comic", typeof(Font));
myToggleStyle.font = myFont;
myToggleStyle.normal.textColor = Color.black;
GUI.Toggle(new Rect(5, 10, 200, 60), false, "Select All", myToggleStyle);
}
The screenshot show the result of my toggle at the top the "Select All" and under it the toggle how I want my one to be the same. A bit bigger but same color and font. If the bottom toggle size is 11 or 12 then my one should be 13 or 14. But as long as I make my toggle font size bigger the color is not the same as the bottom one and both are black.
The bottom one is created by EditorGUILayout.BeginToggleGroup and EditorGUILayout.EndToggleGroup but I want to make a single one not a group.
The main goal is to make a single toggle just like the bottom one by size and color.
I think you just need to set the font style to bold:
myToggleStyle.fontStyle = FontStyle.Bold;

swift: TableViewCell doesn't update constraints until scrolling

i have a tableviewCell containing 2 labels.
The right one has a fixed width and fixed trailing space to superview and the left one a fixed leading space to superview and trailing to right label.
Sometimes i only need the the left label and in this case i want the left one to have a fixed trailing space to superview instead. So, i created a second inactive constraint and do this in my code:
if(entry.right.isEmpty) {
tableCell?.longConstraint.isActive = true
tableCell?.shortConstraint.isActive = false
tableCell?.rightLabel.isHidden = true
} else {
tableCell?.longConstraint.isActive = false
tableCell?.shortConstraint.isActive = true
tableCell?.rightLabel.isHidden = false
}
but when i load the table all displayed cells have the default constraint active and only after scolling out of view and in again, they are displayed correctly.
For an easy way you can embed them inside a horizontal UIStackview and set
self.rightlb.isHidden = true
and it will disappear with no width automatically , also in your current code make sure
tableCell?.layoutIfNeeded()
after you change the constraints
Try adding this code after adjusting constraints programmatically
tableCell?.setNeedsLayout()
tableCell?.layoutIfNeeded()
Hope this works

How to hide labels in ios-charts?

I need disable some elements from my chart.
I used the iOS-charts library in (Swift 2), however I can't understand how to disable the following:
Hide right and left numbers
Hide description color square
Hide all vertical lines
self.chartView.xAxis.drawGridLinesEnabled = false
self.chartView.leftAxis.drawLabelsEnabled = false
self.chartView.legend.enabled = false
will do the job
self.chartView.drawEntryLabelsEnabled = false
This will hide the label from PieChart and shows only value. Also shows legend with label texts.
For only hide the top one:
graphCell.lineChartView.leftAxis.drawTopYLabelEntryEnabled = false