integer editor: add set_value & from_u64
This commit is contained in:
parent
dc1dc3fe24
commit
4cdedca62f
1 changed files with 29 additions and 5 deletions
|
@ -12,12 +12,12 @@ use {
|
||||||
},
|
},
|
||||||
crate::{
|
crate::{
|
||||||
type_system::{Context, TypeTerm, ReprTree},
|
type_system::{Context, TypeTerm, ReprTree},
|
||||||
editors::list::{ListEditor, PTYListController, PTYListStyle},
|
editors::list::{ListEditor, ListCmd, PTYListController, PTYListStyle},
|
||||||
terminal::{
|
terminal::{
|
||||||
TerminalAtom, TerminalEvent, TerminalStyle, make_label
|
TerminalAtom, TerminalEvent, TerminalStyle, make_label
|
||||||
},
|
},
|
||||||
diagnostics::{Message},
|
diagnostics::{Message},
|
||||||
tree::{NestedNode, TreeNavResult},
|
tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor},
|
||||||
commander::ObjCommander
|
commander::ObjCommander
|
||||||
},
|
},
|
||||||
std::sync::Arc,
|
std::sync::Arc,
|
||||||
|
@ -91,7 +91,6 @@ impl DigitEditor {
|
||||||
let r = ed.radix;
|
let r = ed.radix;
|
||||||
|
|
||||||
NestedNode::new(ed.ctx.clone(), data, depth)
|
NestedNode::new(ed.ctx.clone(), data, depth)
|
||||||
|
|
||||||
.set_cmd(editor.clone())
|
.set_cmd(editor.clone())
|
||||||
.set_view(
|
.set_view(
|
||||||
ed.data
|
ed.data
|
||||||
|
@ -134,9 +133,12 @@ impl DigitEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub struct PosIntEditor {
|
pub struct PosIntEditor {
|
||||||
radix: u32,
|
radix: u32,
|
||||||
digits: NestedNode
|
digits: NestedNode,
|
||||||
|
|
||||||
|
// todo: endianness
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PosIntEditor {
|
impl PosIntEditor {
|
||||||
|
@ -176,9 +178,31 @@ impl PosIntEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_u64(ctx: Arc<RwLock<Context>>, radix: u32, value: u64) -> Self {
|
||||||
|
let mut edit = PosIntEditor::new(ctx, radix);
|
||||||
|
edit.set_value_u64( value );
|
||||||
|
edit
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_value_u64(&mut self, mut value: u64) {
|
||||||
|
self.digits.send_cmd_obj(ListCmd::Clear.into_repr_tree(&self.digits.ctx));
|
||||||
|
|
||||||
|
while value > 0 {
|
||||||
|
let digit_val = (value % self.radix as u64) as u32;
|
||||||
|
value /= self.radix as u64;
|
||||||
|
|
||||||
|
// if BigEndian
|
||||||
|
self.digits.goto(TreeCursor::home());
|
||||||
|
|
||||||
|
self.digits.send_cmd_obj(ReprTree::from_char(&self.digits.ctx, char::from_digit(digit_val, self.radix).expect("invalid digit")));
|
||||||
|
}
|
||||||
|
self.digits.goto(TreeCursor::none());
|
||||||
|
}
|
||||||
|
|
||||||
pub fn into_node(self) -> NestedNode {
|
pub fn into_node(self) -> NestedNode {
|
||||||
self.digits
|
self.digits
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
pub fn get_data_port(&self) -> OuterViewPort<dyn SequenceView<Item = u32>> {
|
pub fn get_data_port(&self) -> OuterViewPort<dyn SequenceView<Item = u32>> {
|
||||||
let radix = self.radix;
|
let radix = self.radix;
|
||||||
|
|
Loading…
Reference in a new issue