Example #1
0
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
}
Example #2
0
func (root rootAdapter) Create(theme gxui.Theme, index int) gxui.Control {
	if root.Root == nil {
		return nil
	}
	l := theme.CreateLabel()
	l.SetText(root.Instances[index].Name())
	return l
}
Example #3
0
func (a FormatAdapter) Create(theme gxui.Theme, index int) gxui.Control {
	l := theme.CreateLabel()
	text := Format(index).String()
	if text == "" {
		text = "None"
	}
	l.SetText(text)
	return l
}
Example #4
0
func (l *classList) computeSize(theme gxui.Theme) {
	s := math.Size{}
	font := theme.DefaultFont()
	for _, class := range l.list {
		s = s.Max(font.Measure(&gxui.TextBlock{
			Runes: []rune(class.Name),
		}))
	}
	s.H = 22
	l.size = s
}
Example #5
0
func (p propsAdapter) Create(theme gxui.Theme, index int) gxui.Control {
	pr := p.props[index]
	l := theme.CreateLabel()
	prop := pr.inst.Properties[pr.name]
	v := prop.String()
	if len(v) < 128 {
		l.SetText(pr.name + " (" + prop.Type().String() + ") = " + prop.String())
	} else {
		l.SetText(pr.name + " (" + prop.Type().String() + ") = <long value>")
	}

	return l
}
Example #6
0
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
}
Example #7
0
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
}
Example #8
0
func CreatePanel(theme gxui.Theme) Panel {
	table := theme.CreateTableLayout()
	table.SetSizeClamped(true, false)
	scroll := theme.CreateScrollLayout()
	scroll.SetScrollAxis(false, true)
	scroll.SetChild(table)
	panel := &panel{
		control:    scroll,
		table:      table,
		theme:      theme,
		divider:    0.5,
		itemHeight: 26,
	}
	scroll.SetScrollLength(panel.itemHeight)
	panel.relayout()
	return panel
}
Example #9
0
// Create returns a Control visualizing the item at the specified index.
func (l *classList) Create(theme gxui.Theme, index int) gxui.Control {
	class := l.list[index]
	label := theme.CreateLabel()
	label.SetText(class.Name)
	return label
}