sciter-sdk / go-sciter

Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development
https://sciter.com
2.57k stars 268 forks source link

How add/remove one class? #118

Closed inkeliz closed 6 years ago

inkeliz commented 6 years ago

I take an look at this topic which mention about the state, but I don't know if have an similar function to remove/add one class.

Suppose:

els, _ := root.SelectFirst("body")

The user can switch between the "light" and "dark", the behavior is defined in CSS. How I can do something like:

els, _ := root.SelectFirst("body")
els.SetClass("light")
els.RemoveClass("dark")

In this way the body will be light and remove the dark. I only found the SetStyle but it need to set all the parameters, that is already defined in CSS.

pravic commented 6 years ago

Hi, Why don't you want to do such "low-level" UI things from script?

inkeliz commented 6 years ago

Well, if I use the script will mix both. The golang will be responsable for some stuff and the script another, I think is very confusing.

For instance, if one settings is to change the folder location, it need to be handled in the Golang. But, if you would like to use "night version" (with dark backgroud), it will handled by the script.

I think is better do everything in Go. I don't know if Sciter is supposed to be used in that way.

pravic commented 6 years ago

See, the main point is to set up areas of responsibility. Obviously, you don't want to do literally everything in Go (draw UI by lines or even dots, write your own TCP/IP stack, etc).

Unlike HTMLayout, Sciter offers its script to wrap all low level UI stuff (such as click here, mark there, change attribute somewhere) and native code would be responsible for high level logic (such as load resource, provide data to and take data from the UI, react on events nd so on).

So yes, your assumption is correcy: let script to handle UI (e.g change theme) and Go to interact with OS (e.g. change folder).

However you still can do everything in Go, DOM API is available for native code. el.Attr (), el.SetAttr (), el.ClearAttrs ().