Coder Social home page Coder Social logo

Comments (6)

andlabs avatar andlabs commented on July 24, 2024 2

My stance on the matter is simple: you can build a declarative API on top of a non-declarative one, but not the other way around. libui itself likely won't come with one, but it won't stop you from writing one, and I could build a Go-specific one myself if I wanted.

from ui.

andlabs avatar andlabs commented on July 24, 2024

This is in my thoughts; it will be provided as a subpackage. (Keep open until implemented.)

from ui.

SaadHafiane avatar SaadHafiane commented on July 24, 2024

Wouldn't just providing JSON tags for the structs provide such a feature out of the box?

package main

import (
    "encoding/json"
    "fmt"
)

type Layout struct {
    Buttons []Button `json:"Buttons"`
}

type Button struct {
    Text string `json:"Text"`
    Type string `json:"Type"`
}

func main() {
    b := []byte(`{"Buttons": [{"Text":"simple ui.Button", "Type":"default"},
                           {"Text":"radio ui.Button", "Type":"radio"}]
                 }`)
    var m Layout
    if err := json.Unmarshal(b, &m); err != nil {
        fmt.Println(err)
        return
    }
    fmt.Printf("%#v\n", m)
}

Unmarshalled layout struct:
main.Layout{Buttons:[]main.Button{main.Button{Text:"simple ui.Button", Type:"default"}, main.Button{Text:"radio ui.Button", Type:"radio"}}}

from ui.

duckbrain avatar duckbrain commented on July 24, 2024

Unmarshalling JSON won't call the stuff in the ui.New* functions. You'll get the structs, but the components won't be created. Also, I'd imagine it'd be very useful to have a way to define ID's in the JSON and have them returned in a map[string]ui.Control.

from ui.

SaadHafiane avatar SaadHafiane commented on July 24, 2024

GUI description being declarative by nature recursive calls of the constructors should enough to create the elements.
As for the controls IDs, having an ID field in the structs themselves could allow such a behavior, and a jQuery like interface would be useful I could see such use cases:

  • batch updates of elements by ID
  • decoupling the variable name from the call-back binding by using an ID to call-back lookup table instead which can be updated on the fly at run time
  • provide css class like abilities

from ui.

andlabs avatar andlabs commented on July 24, 2024

Merged with #276.

from ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.