How do I set a view's background to the gray'ish one in SwiftUI? - swiftui

I noticed that whenever I create a view it automatically gets a white background color. If you insert a list however, no matter the size, the entire view seems to get a sort of grey background, which looks better to me than a white background. I'm wondering how I can get my background to look like this (without using a list, or an invisible dummy list maybe)? I've already tried getting the color code but that just gives me a dark grey background. I tried adjusting the opacity but it just isn't the same as the native one.
edit: It appears the size of the list does matter, it seems to have something to do with NavigationViews and NavigationLinks

That is the default group table view background color (systemGroupedBackground) with the color code #F2F2F7. You can use it as a background color like this:
.background(Color(red: 0.949, green: 0.949, blue: 0.97, opacity: 1.0))
...or simply:
.background(Color(.systemGroupedBackground))
Keep in mind that with the latter solution, the color might change in later iOS versions if Apple decides to change the value of the constant.

Related

How Do I Change NavigationBar Color For WatchOS?

I am building watchOS app and I am trying to change navigationBar background color from black to transparent, but I am not able to find anything. I saw this question which was asked in 2015, according to which it is impossible to change navigationBar color in watchOS. I was wondering if now there is any API for that.
Thanks for any help.
This is about Color in the human-interface-guidelines from apple:
Make sure your app’s colors work well in both light and dark
appearance modes. With the exception of watchOS, which always uses a
pure black background, the platforms offer a dark alternative to the
default light appearance. Dark Mode uses a darker color palette for
all screens, views, menus, and controls, and can increase vibrancy — a
subtle effect that dynamically blends foreground and background colors
— to make foreground content stand out against darker backgrounds.
System colors automatically support both appearances; if you use a
custom color, you need to supply both light and dark variants. For
guidance, see Dark Mode.

fill a freehand drawing with opacity

I have a simple fuction which fills the drawn image if the user chooses to
canvas.on('mouse:up', function() {
if(main.mode == 'fill') {
var object = main.canvas.item(main.canvas.getObjects().length-1);
object.fill = main.pColor();
canvas.renderAll();
}
})
this works fine for solid(opacity 1) colors. When using a color with less opacity:
It seems the stoke and fill overlap yielding a darker line.
I experimented with globalCompositeOperation. I am thinking eliminate the stroke or set the stroke opacity to zero. I hope there is a better answer.
I tried a few approaches: setting stroke opacity to zero and trying to get rid of the stroke altogether.
what works best is adding
object.set('strokeWidth', 0);
to the handler above.
set ensures the canvas will be updated.
It is working well.

Using PencilKit in dark mode results in wrong color

When in dark mode, it seems that all the color set in PKInkingTool are reversed in brightness. If I choose a bright red I got a dark red, and vice versa.
For example, if I use UIColorPickerViewController to select a color:
PKInkingTool(.pencil, color:color, width:10)
The color that shows up in PKCanvasView is not the correct color. The only way that seems to work is not to support dark mode.
overrideUserInterfaceStyle = .light
Is there a way to get PencilKit to use the correct color rather than convert color automatically?
You can use 'colorUserInterfaceStyle' for 'PKToolPicker' but in that case if you want to save the drawn part you might have to concern.
colorUserInterfaceStyle = .light

Getting a background surface into the background only partially works

I'm trying to make a Famo.us game where I have a background Image ( an ImageSurface ) and then I put a bunch of other ImageSurfaces over the top and animate them. However the background surface doesn't stay in the background, for starters new ImageSurfaces are drawn underneath, then weirdly they start getting drawn on top. Exact same code generating the surfaces.
the background image has a Transform.behind applied to it.
The image below kind of shows the problem, some of the small squares are behind, and some are on top.
If it makes any difference, the surfaces are all in a HeaderFooterLayout
Any ideas whats going wrong? or how I could debug this?
check the zIndex value of the surfaces isn't the same as the zIndex of the white surface you're attempting to hide them behind. If they are the same (or unspecified) the browser hazards a guess, and you end up with z-fighting where the GPU can't actually decide what to render (the white surface or the tabs?) You could have your tabs resting on one zIndex value, and the white surface on the other.
(The following is written by Keith) For anyone else, what I did was add the following to the ImageSurface
properties: {
zIndex: -1000000
}
Oddly I tried with a zIndex of -10 etc, which didn't work, only once I made that zIndex huge did it seem to fall behind everything else.

swapping background colors in gtk text field (gtkmm C++)

Within my GUI (C++, GTKMM 3), i have a text field that is providing some status information. i'd like to change the background color of this field (along with the text, which i can easily do), based upon the status.
there's not a lot out there on how to do this with GTKMM 3.X. i know i need to use the CssProvider class, and have found some examples on how to load one into the program. but the examples show how to set the properties one time.
but what i haven't figured out is how i can use the CSS properties to change the color of the background, based upon a state (not a state as in 'hover' or anything like that. i want to be able to swap the background from red to green whenever i please). if the CSS is written in terms of using the name of the widget, or the type of widget, how do you handle a changing state with the widget to change its properties?
if anyone has any clues, or knows of any examples, i could really use some help. the purpose of this is to give the user some immediate feedback at a glance. in a rush, they won't have to read the status of the box (or from a distance). the color will allow them to gauge what is going on at a glance.
Adding code
this is what i have tried so far (condensed):
std::string style_sheet = ".red_bg {background: #FF0000; color: #000000; } ";
style_sheet += ".green_bg {background: #33FF33; color: #000000; }";
Glib::RefPtr<Gtk::StyleContext> stylecontext = my_text_field->get_style_context();
Glib::RefPtr<Gtk::CssProvider> cssprov = Gtk::CssProvider::create();
cssprov->load_from_data(style_sheet);
stylecontext->add_provider(cssprov, GTK_STYLE_PROVIDER_PRIORITY_USER);
stylecontext->add_class("red_bg");
stylecontext->context_save();
so that works. when the program fires up, i get a text entry with a red background.
but later on, if i do the following, nothing happens:
Glib::RefPtr<Gtk::StyleContext>stylecontext = my_text_field->get_style_context();
stylecontext->remove_class("red_bg");
stylecontext->context_save(); // probably not necessary
stylecontext->add_class("green_bg");
stylecontext->context_save();
at that point, the background stays red. no transition from red to green. i've seen suggestions to use the override_background_color function in the GtkWidget object, but that doesn't work. that only changes the color that is used when you highlight the text in the widget. i'd still like to see it done the CSS way.
You could do away with the CSS and just use override_background_color, a standard GTK widget method:
override_background_color (StateFlags state, RGBA color)
Sets the background color to use for a widget.
All other style values are left untouched.
Note:
This API is mostly meant as a quick way for applications to change a widget appearance. If you are developing a widgets library and intend this change to be themeable, it is better done by setting meaningful CSS classes and regions in your widget/container implementation through add_class and add_region.
This way, your widget library can install a CssProvider with the STYLE_PROVIDER_PRIORITY_FALLBACK priority in order to provide a default styling for those widgets that need so, and this theming may fully overridden by the user's theme.
Note:
Note that for complex widgets this may bring in undesired results (such as uniform background color everywhere), in these cases it is better to fully style such widgets through a CssProvider with the STYLE_PROVIDER_PRIORITY_APPLICATION priority.
Parameters:
StateFlags state the state for which to set the background color
RGBA color the color to assign, or null to undo the effect of previous calls to override_background_color