<commit_before>local Window = require 'ui.Window'
local Box = Window:subclass {
  -- how far down are we scrolled?
  scroll = 0;
  -- how far down *can* we scroll?
  max_scroll = 0;
  -- do we display a scrollbar and let the user scroll us?
  -- note that even if this is false, the :scrollTo API is still available --
  -- we just won't render the scrollbar.
  -- It's also automatically hidden if max_scroll <= 0.
  display_scrollbar = true;
  size = { 0, 0 };
  position = { 0.5, 0.5 };
}

function Box:__init(...)
  ui.Window.__init(self, ...)
  assertf(self.content, 'Box %s created without content', self.name)
  self:attach(self.content)
end

function Box:__tostring()
  return 'Box[%s]' % self.title
end

function Box:getMargins()
  return 1,1,1,1
end

function Box:layout(w, h)
  ui.Window.layout(self, w, h)
  self.max_scroll = self.content.h - (self.h - 2)
  self.content_y = self.content.y
  self:scroll_by(0)
end

function Box:getChildSize(w, h)
  local ch_w,ch_h = ui.Window.getChildSize(self, w, h)
  -- We lie about our child size because if it's larger than we are, we only
  -- display a slice of it and enable scrolling.
  return ch_w,ch_h:min(h)
end

function Box:render()
  ui.box(nil, self.title or self.name, self.faces)
  -- render scrollbar, if applicable<commit_msg>Make Box take its title into account when calculating width<commit_after>local Window = require 'ui.Window'
local Box = Window:subclass {
  -- how far down are we scrolled?
  scroll = 0;
  -- how far down *can* we scroll?
  max_scroll = 0;
  -- do we display a scrollbar and let the user scroll us?
  -- note that even if this is false, the :scrollTo API is still available --
  -- we just won't render the scrollbar.
  -- It's also automatically hidden if max_scroll <= 0.
  display_scrollbar = true;
  size = { 0, 0 };
  position = { 0.5, 0.5 };
}

function Box:__init(...)
  ui.Window.__init(self, ...)
  assertf(self.content, 'Box %s created without content', self.name)
  self:attach(self.content)
end

function Box:__tostring()
  return 'Box[%s]' % self.title
end

function Box:getMargins()
  return 1,1,1,1
end

function Box:layout(w, h)
  ui.Window.layout(self, w, h)
  self.max_scroll = self.content.h - (self.h - 2)
  self.content_y = self.content.y
  self:scroll_by(0)
end

function Box:getChildSize(w, h)
  local ch_w,ch_h = ui.Window.getChildSize(self, w, h)
  -- We lie about our child size because if it's larger than we are, we only
  -- display a slice of it and enable scrolling.
  return ch_w:max(self.title and #self.title or 0),ch_h:min(h)
end

function Box:render()
  ui.box(nil, self.title, self.faces)
  -- render scrollbar, if applicable
{'fraction_non_alphanumeric': 0.1239638281838734, 'fraction_numerical': 0.011680482290881688, 'mean_word_length': 3.4323873121869783, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '556164', 'n_tokens_mistral': 957, 'n_tokens_neox': 922, 'n_words': 310}