()
| 117 | } |
| 118 | |
| 119 | func (m *Meter) Render() { |
| 120 | pc := &m.Scene.PaintContext |
| 121 | st := &m.Styles |
| 122 | |
| 123 | prop := (m.Value - m.Min) / (m.Max - m.Min) |
| 124 | |
| 125 | if m.Type == MeterLinear { |
| 126 | m.RenderStandardBox() |
| 127 | if m.ValueColor != nil { |
| 128 | dim := m.Styles.Direction.Dim() |
| 129 | size := m.Geom.Size.Actual.Content.MulDim(dim, prop) |
| 130 | pc.FillStyle.Color = m.ValueColor |
| 131 | m.RenderBoxGeom(m.Geom.Pos.Content, size, st.Border) |
| 132 | } |
| 133 | return |
| 134 | } |
| 135 | |
| 136 | pc.StrokeStyle.Width = m.Width |
| 137 | sw := pc.StrokeWidth() |
| 138 | pos := m.Geom.Pos.Content.AddScalar(sw / 2) |
| 139 | size := m.Geom.Size.Actual.Content.SubScalar(sw) |
| 140 | |
| 141 | var txt *paint.Text |
| 142 | var toff math32.Vector2 |
| 143 | if m.Text != "" { |
| 144 | txt = &paint.Text{} |
| 145 | txt.SetHTML(m.Text, st.FontRender(), &st.Text, &st.UnitContext, nil) |
| 146 | tsz := txt.Layout(&st.Text, st.FontRender(), &st.UnitContext, size) |
| 147 | toff = tsz.DivScalar(2) |
| 148 | } |
| 149 | |
| 150 | if m.Type == MeterCircle { |
| 151 | r := size.DivScalar(2) |
| 152 | c := pos.Add(r) |
| 153 | |
| 154 | pc.DrawEllipticalArc(c.X, c.Y, r.X, r.Y, 0, 2*math32.Pi) |
| 155 | pc.StrokeStyle.Color = st.Background |
| 156 | pc.Stroke() |
| 157 | |
| 158 | if m.ValueColor != nil { |
| 159 | pc.DrawEllipticalArc(c.X, c.Y, r.X, r.Y, -math32.Pi/2, prop*2*math32.Pi-math32.Pi/2) |
| 160 | pc.StrokeStyle.Color = m.ValueColor |
| 161 | pc.Stroke() |
| 162 | } |
| 163 | if txt != nil { |
| 164 | txt.Render(pc, c.Sub(toff)) |
| 165 | } |
| 166 | return |
| 167 | } |
| 168 | |
| 169 | r := size.Mul(math32.Vec2(0.5, 1)) |
| 170 | c := pos.Add(r) |
| 171 | |
| 172 | pc.DrawEllipticalArc(c.X, c.Y, r.X, r.Y, math32.Pi, 2*math32.Pi) |
| 173 | pc.StrokeStyle.Color = st.Background |
| 174 | pc.Stroke() |
| 175 | |
| 176 | if m.ValueColor != nil { |
nothing calls this directly
no test coverage detected