Add cluster num option

This commit is contained in:
2020-02-02 00:07:42 +01:00
parent a03deb3737
commit be90c9dc89
5 changed files with 30 additions and 15 deletions

View File

@@ -5,27 +5,30 @@ import message
from math import log10
def num2str(x):
return str(int(log10(x)) + 1)
def show_toggle_cluster_buttons(sense, example):
cls = example.get_cluster()
if cls is None:
return []
base_tag = "input.cluster-list-button"
result = []
for opt in sense.example_clusters():
tag = "input.cluster-list-button"
tag = base_tag
if opt == cls:
tag += ".cluster-button-checked"
attrs = {"value": str(opt + 1), "type": "button"}
style = {"width": num2str(opt + 1) + "em"}
style = {"width": str(int(log10(opt + 1)) + 1) + "em"}
result.append(h(tag,
{"attrs": attrs, "style": style,
"on": {"click": message.msg(message.ExampleClusterEdit(example, opt))}}, []))
result.append(h(base_tag,
{"attrs": {"value": "+", "type": "button"},
"style": {"width": "1em"},
"on": {"click": message.msg(message.ExampleClusterAdd(example))}},
[]))
return result

View File

@@ -121,7 +121,7 @@ class View:
example_content = []
if cluster is not None:
example_content.append(h("span.example-cluster", {}, num2str(cluster)))
example_content.append(h("span.example-cluster", {}, str(cluster + 1)))
example_text_inner_tag = "span.example-text-{}".format(example.get_view_type())
example_content.append(h(example_text_inner_tag, {}, example.text()))