NSRect geometric properties - autolayout

I have some problems with NSRect : everything works great for my image until I open Full Screen. My image moves down accordingly NSRect positions and not of image's constraints. How can I fixe my constraints for this ImageView in NSRect?
let imgImage1 = NSImageView(frame: NSRect(x: 375, y: 430, width: 105, height: 79))

Related

How to set default minimum width scaling in Electron

Using React and Electron, resizing the browser window width below 980 pixels causes the page to be scaled down so that the content will always display 980 pixels wide and visible in the view port, no matter how tiny the viewport width gets.
In main.dev.js:
mainWindow = new BrowserWindow({
show: false,
width: 640,
height: 480
});
The browser window will open with 640px width, but the content will be scaled down so that 980px is visible. Where should this width setting be configured? I don't mind the feature for smaller viewports, but I'd prefer to use standard responsive styling to manage how the content will be displayed.
mainWindow = new BrowserWindow({
show: false,
width: 640,
height: 480,
minWidth: DesiredMinWidth,
minHeight: DesiredMinHeight,
});
This should work, if you want to configure a max height or width just replace min with max.

GeometryReader not generating correct screen height?

public var body: some View
{
ZStack{
GeometryReader { geometry in
RoundedRectangle(cornerRadius: 25, style: .continuous)
.frame(width: geometry.size.width*1.00, height: geometry.size.height*1.00)
.zIndex(0)
}
}
}
I'm using GeometryReader to draw a rounded rectangle to fill up the entire watch screen, this looks fine on a 38mm watch simulator, but as I increase the watch size to 40, 42, 44mm I noticed that the height is not filling up the whole screen. I have to adjust my multiple to say 1.1 for example to fill up more of the screen.
Can someone tell me if I am using GeometryReader incorrectly?
Unless you really need the full functionality of the geometry reader, to actually measure the size of the object of the screen, then I think you could achieve the effect you want by setting the frame's maxWidth and maxHeight to .infinity and by ignoring the safe area on the bottom.
var body: some View {
ZStack {
RoundedRectangle(cornerRadius: 25, style: .continuous)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.edgesIgnoringSafeArea(.bottom)
}
}
Note that when you use a ZStack the order of the items in it determine the order on the screen. The first item in the stack will be at the bottom, and then each item will be layered on top.

Issue with background color of an image inside a button SwiftUi

image inside the button appears blue. I cant figure out how to fix it.
Button(action: {self.count += 1}) {
Circle()
.fill(LinearGradient(gradient: Gradient(colors: [Color("linkAccount1"), Color("linkAccount2")]), startPoint: UnitPoint(x: 0, y: 0.2), endPoint: UnitPoint(x: 1, y: 1)))
.frame(width: 80, height: 80)
.shadow(color: Color("shadowColor1"), radius: 7, y: 7)
.overlay(
//issue with image backgroud or foregroundColor
Image("linkAccount")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 60, height: 60))
}
Solution:
Image("linkAcount").renderingMode(.original)
As per my comment above, the issue is caused by the rendering mode of the Image.
You can overcome the tinting problem by using the .renderingMode() modifier, and setting the mode to be .original. This tells the image to ignore the tint.
Image("linkAcount").renderingMode(.original)
Images and Text contained within a button get rendred in accent colour, which by default is blue, just apply:
.accentColor(.white)
to your Button to have the image drawn in white.

JafaFX radial gradient

I would like to reproduce the following screen with JavaFX and tried this (stripped) code:
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws Exception{
primaryStage.setTitle("Hello World");
primaryStage.setFullScreen(true);
primaryStage.setFullScreenExitHint("");
AnchorPane root = new AnchorPane();
root.setStyle("-fx-background-color: " +
"rgb(15,37,74), " +
"radial-gradient(center 50% 50%, radius 65%, rgb(97,156,188) 10%, rgb(22,51,93));");
Scene scene = new Scene(root, 600, 400);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
However I have the following problems to reproduce the original picture:
I am not able to generate a circular gradient, since the AnchorPane is a rectangle, the gradient is elliptic. As far I understand the documentation a circular gradient is not possible?
The gradient of the original picture is not a linear but has some circles (a bright circle in the middle and a medium circle outside). I tried to play around and was adding percentage to the stop colors, but when I do (eg. rgb(97,156,188) 30%, rgb(22,51,93)) I get a much brighter visualization of the ellipse which I don't understand. The start of the gradient is always brighter as it should be and I don't know why:
Can anyone explain me whats going on here?
Downloading the (800x600 pixel) image from the screen shot you are looking to duplicate, and using a color picker, I get the following (decimal r,g,b) values, traversing from the center (400, 300) to the left edge (0, 300):
(400, 300): (104, 163, 193)
(300, 300): (87, 145, 182)
(200, 300): (60, 113, 163)
(100, 300): (38, 85, 137)
(0, 300): (23, 56, 99)
That looks close enough to linear to me (there maybe some general fuzziness and jpeg compression will change the values a little).
So this seems a good approximation:
root.setStyle("-fx-background-color: radial-gradient(center 50% 50%, radius 50%, rgb(104, 163, 193) 0%, rgb(23, 56, 99) 100%);");
I don't see a way to make it circular using percentages: you would have to use actual lengths. If the size may change, then of course you need to respond to that; you can do this with a binding as follows:
root.styleProperty().bind(Bindings.createStringBinding(() ->
String.format("-fx-background-color: radial-gradient(center %dpx %dpx, radius %dpx, rgb(104, 163, 193) 0%%, rgb(23, 56, 99) 100%%);",
(int) (root.getWidth()/2), (int) (root.getHeight()/2), (int)(Math.max(root.getWidth(), root.getHeight())/2)),
root.widthProperty(), root.heightProperty()));
Be aware that this is not a high-performing way of doing this; inline styles are generally the slowest way to apply CSS to a node, and here you are changing the inline style on every small change in dimension of the node. However, it appears to work just fine on my system; just be aware it might not be a good way to apply a gradient to many nodes in the same view.

adding outline for image in qgraphicsitem with different image resolution

Im trying to paint a image with outline in a qgraphicsitem . this image will have different resolution (640x380, 1190* 780, 320 *410) and i have to draw a constant 4px outline irrespective to the image width and height . i tried to take the percent of the image geometry but for different size of image the outline is changing . for higher resolution it looks thin and for smaller value thin line .
QFont segoeFont("Segoe Regular");
segoeFont.setPointSize(10);
painter->setFont(segoeFont);
painter->setRenderHints(QPainter::TextAntialiasing);
painter->setBrush(QColor(69,69,69));
if(meIsSelected)
{
painter->setBrush(QColor(65, 167, 243));
QPen pen(QColor(65, 167, 243), 2);
pen.setCosmetic(true);
}
painter->drawRect (this->boundingRect ());
painter->drawImage (QPoint(0,0), mePixmap);
and my boundingRect()
return mePixmap.rect ().adjusted (-4, -4, 4, 4);
this item is shown in view with fitInview
void GraphicsView::resizeEvent(QResizeEvent *event)
{
QGraphicsView::resizeEvent(event);
fitInView(this->scene()->sceneRect (),Qt::KeepAspectRatio) ;
}
If you need a constant 4px outline and the screen resolution is changing, what you're seeing is correct.
A 4px outline will, naturally look smaller with a higher resolution. In theory, if the resolution were just 4 pixels wide, it would take up the whole width of the screen, but with an 8px wide resolution, the 4px line would cover just half the screen. In both cases, the outline is still 4px.
If your screen resolution is the same and it's just the image resolution that's changing, then you need to show your code of how you're trying to render the outline.

Resources