Skip to content

Commit 5ca8256

Browse files
committed
Hide checkmark internals from tui API
1 parent 48fd7d5 commit 5ca8256

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/bin/edit/draw_menubar.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,7 @@ fn draw_menu_view(ctx: &mut Context, state: &mut State) {
113113
if ctx.menubar_menu_button(loc(LocId::FileGoto), 'G', kbmod::CTRL | vk::G) {
114114
state.wants_goto = true;
115115
}
116-
if ctx.menubar_menu_checkbox(
117-
loc(LocId::ViewWordWrap),
118-
'W',
119-
kbmod::ALT | vk::Z,
120-
word_wrap.into(),
121-
) {
116+
if ctx.menubar_menu_checkbox(loc(LocId::ViewWordWrap), 'W', kbmod::ALT | vk::Z, word_wrap) {
122117
tb.set_word_wrap(!word_wrap);
123118
ctx.needs_rerender();
124119
}

src/tui.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ pub enum Overflow {
261261

262262
/// If specified, a checkmark 🗹 / ☐ to be prepended to the button text
263263
#[derive(Default, Clone, Copy, PartialEq, Eq)]
264-
pub enum Checkmark {
264+
enum Checkmark {
265265
/// No checkmark (or space for it)
266266
#[default]
267267
Absent,
@@ -295,14 +295,16 @@ impl ButtonStyle {
295295
pub fn accelerator(self, char: char) -> Self {
296296
Self { accelerator: Some(char), ..self }
297297
}
298-
/// Draw a checkbox prefix: `[🗹 Example Button]`
299-
pub fn checkmark(self, checkmark: Checkmark) -> Self {
300-
Self { checkmark, ..self }
301-
}
302298
/// Draw with or without brackets: `[Example Button]` or `Example Button`
303299
pub fn bracketed(self, bracketed: bool) -> Self {
304300
Self { bracketed, ..self }
305301
}
302+
/// Draw a checkbox prefix: `[🗹 Example Button]`
303+
///
304+
/// Note: use `checkbox` or `menubar_menu_checkbox`
305+
fn checkmark(self, checkmark: Checkmark) -> Self {
306+
Self { checkmark, ..self }
307+
}
306308
}
307309

308310
impl Default for ButtonStyle {
@@ -3155,12 +3157,23 @@ impl<'a> Context<'a, '_> {
31553157
accelerator: char,
31563158
shortcut: InputKey,
31573159
) -> bool {
3158-
self.menubar_menu_checkbox(text, accelerator, shortcut, Checkmark::AlignOnly)
3160+
self.menubar_menu_item(text, accelerator, shortcut, Checkmark::AlignOnly)
31593161
}
31603162

31613163
/// Appends a checkbox to the current menu.
31623164
/// Returns true if the checkbox was activated.
31633165
pub fn menubar_menu_checkbox(
3166+
&mut self,
3167+
text: &str,
3168+
accelerator: char,
3169+
shortcut: InputKey,
3170+
checked: bool,
3171+
) -> bool {
3172+
self.menubar_menu_item(text, accelerator, shortcut, checked.into())
3173+
}
3174+
3175+
/// Appends a button or checkbox to the current menu,
3176+
fn menubar_menu_item(
31643177
&mut self,
31653178
text: &str,
31663179
accelerator: char,

0 commit comments

Comments
 (0)