func (inst instanceNode) Create(theme gxui.Theme) gxui.Control { label := theme.CreateLabel() label.SetText(inst.Name()) if inst.tooltips != nil { inst.tooltips.AddToolTip(label, 0.25, func(point math.Point) gxui.Control { tip := theme.CreateLabel() tip.SetText("Class: " + inst.ClassName) return tip }) } if len(Data.Icons) == 0 { return label } texture, ok := Data.Icons[inst.ClassName] if !ok { texture = Data.Icons[""] } icon := theme.CreateImage() icon.SetMargin(math.Spacing{3, 0, 0, 0}) icon.SetTexture(texture) layout := theme.CreateLinearLayout() layout.SetDirection(gxui.LeftToRight) layout.SetHorizontalAlignment(gxui.AlignLeft) layout.SetVerticalAlignment(gxui.AlignMiddle) layout.AddChild(icon) layout.AddChild(label) return layout }
func (node addRootNode) Create(theme gxui.Theme) gxui.Control { layout := theme.CreateLinearLayout() layout.SetDirection(gxui.LeftToRight) layout.SetHorizontalAlignment(gxui.AlignLeft) layout.SetVerticalAlignment(gxui.AlignMiddle) ctx := node.ctx { button := CreateButton(theme, "Add Instance") button.OnClick(func(gxui.MouseEvent) { ctx.ctxc.EnterContext(&InstanceContext{ Finished: func(child *rbxfile.Instance, ok bool) { if !ok { return } if err := ctx.session.Action.Do(cmd.AddRootInstance(ctx.session.Root, child)); err != nil { ctx.ctxc.EnterContext(&AlertContext{ Title: "Error", Text: "Failed to add instance:\n" + err.Error(), Buttons: ButtonsOK, }) return } if ctx.tree.Select(child) { ctx.tree.Show(child) } }, }) }) layout.AddChild(button) } { button := CreateButton(theme, "Add Model") button.OnClick(func(gxui.MouseEvent) { loadModel(ctx.ctxc, func(children []*rbxfile.Instance) { ag := make(action.Group, len(children)) var first *rbxfile.Instance for i, child := range children { if first == nil { first = child } ag[i] = cmd.AddRootInstance(ctx.session.Root, child) } if err := ctx.session.Action.Do(ag); err != nil { ctx.ctxc.EnterContext(&AlertContext{ Title: "Error", Text: "Failed to add objects:\n" + err.Error(), Buttons: ButtonsOK, }) return } if first != nil && ctx.tree.Select(first) { ctx.tree.Show(first) } }) }) layout.AddChild(button) } return layout }
func CreateDialog(theme gxui.Theme) Dialog { c := new(dialog) c.actions = make(map[int]*dialogAction, 4) c.newButton = theme.CreateButton c.newLabel = theme.CreateLabel c.title = theme.CreateLabel() container := theme.CreateLinearLayout() container.SetDirection(gxui.TopToBottom) container.SetHorizontalAlignment(gxui.AlignLeft) container.SetVerticalAlignment(gxui.AlignTop) container.SetPadding(math.Spacing{L: 10, T: 10, R: 10, B: 10}) c.container = container actionContainer := theme.CreateLinearLayout() actionContainer.SetDirection(gxui.LeftToRight) actionContainer.SetVerticalAlignment(gxui.AlignMiddle) actionContainer.SetHorizontalAlignment(gxui.AlignCenter) c.actionContainer = actionContainer layout := theme.CreateLinearLayout() layout.SetBackgroundBrush(gxui.Brush{Color: gxui.Color{0.2, 0.2, 0.2, 1}}) layout.SetDirection(gxui.TopToBottom) layout.SetHorizontalAlignment(gxui.AlignCenter) layout.AddChild(c.title) layout.AddChild(container) layout.AddChild(actionContainer) c.control = layout return c }